Question about share DDR Data in PRU_memAccess_DDR_PRUsharedRAM included in am335x_pru_package

I’m reading about PRUs, I’ve activated it and successfully working on, but I wonder why in the PRU_memAccess_DDR_PRUsharedRAM example in function LOCAL_exampleInit was mapped so much memory?

Here is the code from the example


static int LOCAL_exampleInit ( )
void *DDR_regaddr1, *DDR_regaddr2, DDR_regaddr3;
open the device /
mem_fd = open("/dev/mem", O_RDWR);
if (mem_fd < 0) {
printf(“Failed to open /dev/mem (%s)\n”, strerror(errno));
return -1;
map the DDR memory */


ddrMem is the pointer to the mapped memory at DDR_BASEADDR = 0x80000000

If I understand the mmap 2dn argument is size_t length so 0x0FFF FFFF = 268435455 bytes, so ((268435455÷1024)÷1024) = 255.99 MB !!!

I just wonder why so much?


I don’t think the provided DDR example does the right thing. Thanks to Elias’ hipstercircuits blog post about this I tried to make a better example:

My general conclusion is that it’s a bad idea to write to DDR memory under Linux which is a virtual memory system. You need to allocate this memory in the Linux Kernel driver which prevents it from being used by any other program.

Better to just write ping pong buffer into PRU Dataram.

That example uses a block if DDR that is allocated by the uio_priss kernel driver and passes its address to the PRU via PRU memory. We had to use DDR because the 12k or PRU memory was not a big enough buffer for our data rates.