Yet another wrinkle in the process of porting our stuff from CM4 to CM5, and a weird one at that...
We have a systemd service that starts on boot, this is a piece of C code that acts as a comms bridge, communicating via the UART with a microcontroller on the board using simple messages, and also starting a socket server for other processes to connect to it and send/receive messages. Some of the messages from the micro are translated into udev events (key presses). It also stores & maintains a basic config. It's a basically a programmatical lump of glue to join various things together.
This was originally written in C under Raspbian 10/11 and built & used on 12/Bookworm on a CM4 no problem at all for quite some time now.
However, loading a CM5 with the same default Raspbian 64-bit OS and building & installing the service it runs but doesn't work - I'll give as much info as I can about what that means;
First off, in the CM5 the serial port has moved - no biggie, I knocked up some code to detect that based on the raspi-config method of detecting hardware (code pasted below). That appears to work fine.
So - at this point I can build & run the code no problem and it works as it should - serial messages go back & forth, ports are listened on, uDev is opened and events happen when triggered.
However, when I run it from boot as a service using the same systemd setup process as before, it gives out a couple of serial messages and then just stops - but the service is shown as running and there's no errors or anything in the logs. The serial activity just stops - I've checked with a scope and it's not mangled or anything, there's no activity at all on the UART.
systemd service:
The status always shows as active/running with no errors:
If I stop & restart the service from the command line it will then start & run fine, again with no errors.
There's nothing in the logs even though my executable does spit out messages to stdout and stderr quite verbosely.
I'm scratching my head now as to what's different between CM4 and CM5 running identical OS images with identical software installed
Here's the C code to detect if we're running on a CM4 or CM5, don't judge me:
We have a systemd service that starts on boot, this is a piece of C code that acts as a comms bridge, communicating via the UART with a microcontroller on the board using simple messages, and also starting a socket server for other processes to connect to it and send/receive messages. Some of the messages from the micro are translated into udev events (key presses). It also stores & maintains a basic config. It's a basically a programmatical lump of glue to join various things together.
This was originally written in C under Raspbian 10/11 and built & used on 12/Bookworm on a CM4 no problem at all for quite some time now.
However, loading a CM5 with the same default Raspbian 64-bit OS and building & installing the service it runs but doesn't work - I'll give as much info as I can about what that means;
First off, in the CM5 the serial port has moved - no biggie, I knocked up some code to detect that based on the raspi-config method of detecting hardware (code pasted below). That appears to work fine.
So - at this point I can build & run the code no problem and it works as it should - serial messages go back & forth, ports are listened on, uDev is opened and events happen when triggered.
However, when I run it from boot as a service using the same systemd setup process as before, it gives out a couple of serial messages and then just stops - but the service is shown as running and there's no errors or anything in the logs. The serial activity just stops - I've checked with a scope and it's not mangled or anything, there's no activity at all on the UART.
systemd service:
Code:
$ cat /etc/systemd/system/panel.service[Unit]Description=Panel serviceAfter=multi-user.target[Service]ExecStart=/home/pi/panelsrvType=simple# Do not kill (our code does not use sd_notify to send "READY" etc.)TimeoutSec=infinity[Install]WantedBy=multi-user.target
Code:
$ sudo systemctl status panel.service● panel.service -panel service Loaded: loaded (/etc/systemd/system/panel.service; enabled; preset: enabled) Active: active (running) since Mon 2024-12-09 12:40:08 GMT; 5s ago Main PID: 1997 (panelsrv) Tasks: 5 (limit: 4758) CPU: 170ms CGroup: /system.slice/panel.service └─1997 /home/pi/panelsrvDec 09 12:40:08 raspi5 systemd[1]: Started panel.service - panel service.
There's nothing in the logs even though my executable does spit out messages to stdout and stderr quite verbosely.
I'm scratching my head now as to what's different between CM4 and CM5 running identical OS images with identical software installed

Here's the C code to detect if we're running on a CM4 or CM5, don't judge me:
Code:
/* * Quick and dirty code to detect CM4 or CM5 and choose the correct serial port */static char sport[PATH_MAX] = "";static void get_serial_port(void){ /* * From command line: * cat /proc/device-tree/compatible * raspberrypi,5-compute-modulebrcm,bcm2712 * Note this string includes NULL characters */ FILE* fp; #define MAX_BYTES 100 char buffer[MAX_BYTES]; fp = fopen("/proc/device-tree/compatible", "r"); if (fp == NULL) { perror("Failed: "); return; } fread(buffer, 1, MAX_BYTES, fp); fclose(fp); char *pch = strstr(buffer,"raspberrypi,5-compute-module"); if(pch != NULL) { strcpy(sport, "/dev/ttyAMA0"); printf("Pi CM5 - Serial port is '%s'\n", sport); } else { strcpy(sport, "/dev/ttyS0"); printf("Pi CM4 - Serial port is '%s'\n", sport); }}
Statistics: Posted by John_U — Mon Dec 09, 2024 12:48 pm