T4.1 PSRAM static allocation and copy content

liudr

Well-known member
Just want to check whether I'm doing it right:

I have an 8MB PSRAM from prjc that I soldered to my T4.1 smaller footprint. I plan to use the PSRAM as a large buffer so I don't need ext_malloc().

Code:
#define PSRAM_SIZE				(8*1024UL*1024UL)
EXTMEM uint8_t PSRAM_buffer[PSRAM_SIZE];	// May use extmem_malloc() to allocate.

Later...

memcpy((void*)(PSRAM_buffer+PSRAM_ptr),OUTbuf,len);

So is there any special memcpy() etc. that only does copy and compare with PSRAM? My OUTbuf is in RAM2 (could place in 1 as well). Do I need to write cache to RAM2 before copying, in case this copy is done with DMA?

Thanks.
 
Yes, that looks fine.

Ordinary memcpy() is used, because the PSRAM appears as ordinary memory. It's much slower for cache misses, but other than the performance impact, from a software point of view it's the same as any other memory.

DMA can also be used, but with DMA you do need to use the cache maintenance functions. DMA is a lot more complicated and offers almost no benefit if your code will just sit and wait for it to complete. Unless you really want to dive into the learning experience just for the sake of education, I'd recommend avoiding DMA unless you truly need to run other code while the DMA engine copies the data.
 
Thanks Paul! I'll avoid using DMA to access PSRAM. What I want to do is to write some content into OUTbuf, then have the content sent to a USB device using a USBHost_t36 library driver I wrote, and "at the same time" save a copy of the content to PSRAM. I wrote my driver so that it copies the OUTbuf content into an internal buffer before sending the data, with the internal buffer, to avoid having to write cache to memory. So once I submit the transfer with the copied data, I can take the original data and copy it to PSRAM.

I wonder what happens if I just have one copy of the data in RAM1 and try to send it with USB controller AND copy it to PSRAM. My guess is the copying to PSRAM will proceed (slowly) as usual until the USB controller needs the data for transfer. Then I don't know if the CPU is halted while the USB controller reads the data or not. I read about burst DMA halts CPU while the transfer is ongoing. Anyway, more to read about :D
 
Back
Top