I’m trying to get the NuttX CAN drivers built for my Pixhawk4 (px4_fmu-v5_default) and I can’t seem to get them to build. I verified that uavcan is disabled and that the NuttX CAN interfaces and STM32 CAN1 and CAN2 peripherals are enabled via boardconfig and menuconfig. However, it looks like the CAN drivers aren’t building and there’s no sign of /dev/can0 or /dev/can1 once I build it. What configuration options should I check?
ETA: CAN drivers are building but I can’t link my application in such a way that I can link the can_devinit() function nor do I see /dev/can0 or /dev/can1 on the Pixhawk once I load the code.
So… I got past this hurdle by modifying boards/px4/fmu-v5/src/init.c.
I added a local declaration for can_devinit():
extern int can_devinit(void);
And I added a call to it down at the bottom of board_app_initialize(). So now /dev/can0 exists and my code starts and appears to be able to open. However, I see no evidence of incoming packets, despite there being a talkative NMEA2000 device on the CAN bus.
I’m trying to do the same. I made a new driver taking some inspiration from src/drivers/cyphal/CanardNuttXCDev.cpp. I can read and write to /dev/can0 without error, but nothing is written to the bus (connected to CAN1), nor are incoming messages read - so seems like the same result. I verified with a CAN adapter connected to my computer.
I have not, but mostly b/c I’ve had a bunch of higher priority stuff on my plate and I may have found a way to remove the PX4 software from the path for my CAN devices making the answer less relevant to me.
f (!_initialized) {
struct can_dev_s *can = stm32_caninitialize(1); // the 1 is for CAN1
if (can == nullptr) {
PX4_ERR("Failed to get CAN interface");
return;
}
/* Register the CAN driver at "/dev/can0" */
int ret = can_register("/dev/can0", can);
if (ret < 0) {
PX4_ERR("can_register failed: %d", ret);
return;
}
// open /dev/can0
_fd = ::open("/dev/can0", O_RDWR /*| O_NONBLOCK*/);
if (_fd < 0) {
PX4_ERR("FAILED TO OPEN /dev/can0");
return;
} else {
PX4_INFO("CAN opened successfully on /dev/can0");
}
_initialized = true;
}