@Kurt: Yes, set it to MEM_NOCACHE if you want to read. This disables the cache for that region. Or use the functions..
Thanks Frank,
But I am thinking more about the end user and what do they need to do and/or if the libraries need to reflect on this and handle it.
Right now I am thinking of doing some form of hack inside of SPI, that maybe does something like:
if (tx_buffer >= 0x20200000U) arm_dcache_flush(tx_buffer, count);
if (rx_buffer >= 0x20200000U) arm_dcache_delete(rx_buffer, count);
But not sure if the rx_buffer delete could be done at the start of the DMA or do I need to wait until the end of the DMA... Will try start and see what happens.
But again wondering about how the memory works.
My assumption is, there is lower memory, where variables and stack go: If I read the stuff correctly, we have: 128k of DTCM memory.
We then have 256KB of OCRAM where currently DMAMEM and heap go...
I did some quick and dirty prints in test app:
Code:
buffer = (uint8_t *)malloc(BUFFER_SIZE);
//rxBuffer = (uint8_t *)malloc(BUFFER_SIZE);
DBGSerial.print("Buffer: ");
DBGSerial.print((uint32_t)buffer, HEX);
DBGSerial.print(" RX Buffer: ");
DBGSerial.print((uint32_t)rxBuffer, HEX);
DBGSerial.print(" ");
DBGSerial.println(BUFFER_SIZE, DEC);
DBGSerial.printf("Static buffer: %x, Stack Buffer: %x\n", (uint32_t)static_buffer, (uint32_t)stack_buffer);
DBGSerial.printf("Heap Start: %x, Heap End: %x\n", (uint32_t)&_heap_start, (uint32_t)&_heap_end);
event.attachImmediate(&asyncEventResponder);
Output shows:
Code:
SPI Test program
Buffer: 20209C48 RX Buffer: 20200000 40000
Static buffer: 20001790, Stack Buffer: 2001ffc4
Heap Start: 20209c40, Heap End: 20240000
So the current definition of DMAMEM - imiplies it does not work with DMA? Unless you force the cache to work for you?
Also wondering about the lower memory. That is wondering if we should allow the unused parts to be used for heap as well?
That is if you subtract my buffer I put on stack, from my static buffer, they differ by about 120K in memory location. Note: I did not look to see where the actual last variable was actually allocated, probably including buffers for things like Serial objects and the like.
But if we don't allow something like malloc and new to get to this space, than maybe we should be default enlarge system buffers to make more use of this space?
Edit: Should mention that I understand that there is not enough memory available for two full ILI9341 buffers on these chips.
That is each one takes 153600 bytes, so 2 times that would take over 300K. But could potentially do it using multiple memory locations...
That is if one allocated lets says: the full 153600 for one buffer, and for the other buffer do it with two allocations like 100K from high memory and the other 53K from lower memory... Note: At one point was playing with I believe the ESP32, where I wanted a backing buffer for ILI9341 and did something similar as you could not allocate that much memory in one allocation...