pru c++ shared mem

The PRU has direct access to all of physical memory. If you are sending data to Linux then you just need to use an unused block, or to be safe allocate a DMA block in the device tree. Just mmap the address and read directly from Linux. RPmsg is great for communicating back and forth to Linux but not really good for moving data/memory.

device tree entry;
// allocate 8mb shred mem for PRU
my_shared_memory_region: pru-shared-memory@90000000 {
compatible = “shared-dma-pool”;
reg = <0x0 0x90000000 0x0 0x800000>;
reusable;
status = “okay”;
};

on Linux user space app just use mmap to map the physical address into user space.
PRU code just needs to keep track of where it is writing and wrap around when you get to the end.
for quick and easy wrap If mem size is power of two, just “And” your byte counter with memsize -1.

e.g.
const uint32_t MEM_SIZE = 0x800000U;
const uint32_t MEM_WRAP = MEM_SIZE -1;

byte_ctr &= MEM_WRAP;

1 Like