Hi all,
I'm trying to use a piece of open-source software called rpipdi to program an Atmel ATxmega 128A3U coprocessor from a CM4.
This builds OK and runs, but gives the following error:I could use some assistance if possible, please.
I'm trying to work out whether it is my setup causing problems before I open a discussion or issue on the repo.
rpi_init() under rpi.c seems to be failing to map memory.
A buffer is used to read 16 characters from "/proc/device-tree/soc/ranges", which is used to determine base address and size, however when I cat this file it gives only 9 characters and is not human-readable ("~��|�@���"), is this to be expected?
I'm running kernel 6.12.22-v8, could an mmap API change in the 4 years since the software release be causing problems?
The system timers and GPIO base address also seem to reference the BCM2835 rather than BCM2711, so _gpio and _st might need to be modified to work correctly with the CM4.
The function in question is below:Many thanks,
Adam
I'm trying to use a piece of open-source software called rpipdi to program an Atmel ATxmega 128A3U coprocessor from a CM4.
This builds OK and runs, but gives the following error:
Code:
Failed to map memory: Invalid argumentERROR: Failed to init PDII'm trying to work out whether it is my setup causing problems before I open a discussion or issue on the repo.
rpi_init() under rpi.c seems to be failing to map memory.
A buffer is used to read 16 characters from "/proc/device-tree/soc/ranges", which is used to determine base address and size, however when I cat this file it gives only 9 characters and is not human-readable ("~��|�@���"), is this to be expected?
I'm running kernel 6.12.22-v8, could an mmap API change in the 4 years since the software release be causing problems?
The system timers and GPIO base address also seem to reference the BCM2835 rather than BCM2711, so _gpio and _st might need to be modified to work correctly with the CM4.
The function in question is below:
Code:
bool rpi_init() { if (_gpio) return true; // Try to read device tree FILE *fp = fopen("/proc/device-tree/soc/ranges", "rb"); if (!fp) return error("Unable to open device tree"); unsigned char buf[16]; int ret = fread(buf, 1, sizeof(buf), fp); fclose(fp); off_t base; size_t size; if (8 <= ret) { base = buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7]; size = buf[8] << 24 | buf[9] << 16 | buf[10] << 8 | buf[11]; if (!base) { // RPI 4 base = buf[8] << 24 | buf[9] << 16 | buf[10] << 8 | buf[11]; size = buf[12] << 24 | buf[13] << 16 | buf[14] << 8 | buf[15]; } } else return error("Unable to read device tree"); // Open /dev/mem int fd = -1; if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) return error("Unable to open /dev/mem"); // Map memory uint32_t *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, base); if (mem == MAP_FAILED) return error("Failed to map memory"); // Save base addresses. Divided by 4 for (uint32_t *) access. _gpio = mem + BCM2835_GPIO_BASE / 4; _st = mem + BCM2835_ST_BASE / 4; return true;}Adam
Statistics: Posted by AdamWTracerco — Wed Apr 30, 2025 2:34 pm — Replies 1 — Views 89