PB2 PRU weird issues + shouldnt the DT set the PRU IRAM to 16KB not 12KB?

If i uncomment either of the 2 lines below, the code complies and i can start the PRU just fine. HOwever if i uncomment both at the same time, the code compiles but i cant start the PRU. I get a

tee: /sys/class/remoteproc/remoteproc2/state: Invalid argument

and a

[20207.065889] remoteproc remoteproc2: PRU memory copy failed for da 0x105 memsz 0x4
[20207.065896] remoteproc remoteproc2: Failed to load program segments: -22
[20207.065967] remoteproc remoteproc2: Boot failed: -22

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <pru_cfg.h>
#include <pru_intc.h>
#include "intc_map_0.h"
#include <rsc_types.h>

volatile unsigned int *pru0_dram = (unsigned int *)(0x00000 + 0x200);

typedef struct {
   uint8_t start_seq[3];
   uint8_t command;
   uint8_t number_of_bytes_to_follow;
} COMMAND_PACKET;

COMMAND_PACKET request;

void main(void) {
//      request.start_seq[0]='S';
        while(1){
//              pru0_dram[0] = 4;
        }
}

Also, the DT for the PB2 sets the PRU IRAM at 12KB. But i found the following that state its 16KB, not 12KB.
https://git.ti.com/cgit/pru-software-support-package/pru-software-support-package/commit/
https://lkml.org/lkml/2026/3/3/2283

Robert is always happy to take a PR, should you be inclined to post one…

I fixed it by simply adding a extra data to the struct??? No clue why this is happening or what it means

uint8_t pack[1]; //doesnt work
uint8_t pack[2]; //doesnt work
uint8_t pack[3]; //works
uint8_t pack[4]; //doesnt work
uint8_t pack[5]; //doesnt work
uint8_t pack[6]; //doesnt work
uint8_t pack[7]; //works
uint8_t pack[8]; //doesnt work
uint8_t pack[9]; //doesnt work
uint8_t pack[10]; //doesnt work
uint8_t pack[11]; //works

The dmesg line names the cause. On K3 devices - and the PocketBeagle 2’s AM6254 is one, the device tree describes its PRUs with compatible “ti,am625-pru” - the PRU firmware is not loaded with a plain memcpy. The TI PRU remoteproc driver in the Linux kernel (drivers/remoteproc/pru_rproc.c) routes the copy through a helper, pru_rproc_memcpy, which returns EINVAL when the destination address or the copy length is not a multiple of 4 bytes. That matches your log exactly: the failing copy targets da 0x105, which is not divisible by 4, so the loader prints “PRU memory copy failed for da 0x105 memsz 0x4” and the boot aborts with -22.

The comment above that function in the driver explains why the restriction exists: on the ICSSG PRU/RTU/TX_PRU cores the IRAM ports only reflect data correctly for integer 4-byte copies; an unaligned copy zeroes the other bytes within the same 4-byte word, and 8-byte copies (which an ARM64 memcpy would emit) raise an exception. For the older AM335x generation the same driver uses a plain memcpy instead, which is why this failure mode does not show up on the classic boards.

Your padding experiment matches this pattern. Adding bytes to the struct shifts whatever the linker places behind it. The sizes that boot (3, 7, 11) are exactly the values of N congruent 3 modulo 4, i.e. consistent with the struct ending on a 4-byte boundary, while 1, 2, 4, 5, 6, 8, 9, 10 all leave it misaligned. Which particular symbol lands at 0x105 I cannot tell from here - that depends on the link map - but the pattern in your numbers is the 4-byte alignment requirement, not a size or timing problem.

A more robust fix than trial-and-error padding: force the alignment explicitly. The GCC manual (Common Variable Attributes) documents that the aligned attribute “specifies a minimum alignment for the variable or structure field, measured in bytes”. Declaring the array (or the whole struct) with attribute((aligned(4))) keeps the layout correct even when you add or remove fields later, so the firmware does not break again the next time the struct size changes.

your first post on the forum and you drop this much knowledge?? Wow thank you so much. I see exactly what you’re talking about


I’m sure others are going to run into this issue when porting their code over from AM335x to AM62x so this thread will be of big help.

Thank you!!

Hi,

to bypass this one I saw somewhere and I use the approach to load in blocks: