ardupilot/libraries/AP_CANManager
Andrew Tridgell b59b2138b8 AP_CANManager: fixed critical race in log_text()
the AP_CANManager::log_text() gets called from debug logging in
AP_DroneCAN. It is a method on a common AP_CANManager object which is
shared by multiple AP_DroneCAN threads.

if two threads call the debug log messages at the same time then we
can end up with _log_pos greater than LOG_BUFFER_SIZE (1024) and
overwrite past the end of the buffer

in the crash_dump we have for this case the next piece of memory was
hal.can[0], and the overwrite of the buffer had corrupted the
MessageRam_ structurre in the ChibiOS CAN interface code. That led to
a hardfault on receive of a CAN message

Note that this issue only happens if CAN_LOGLEVEL is set to greater
than zero, and the default is zero. So users can avoid the bug by
checking they have not changed CAN_LOGLEVEL.

Also, this is likely an issue that only happens on startup, as once
the two AP_DroneCAN threads are fully running they have the same
thread priority so can't pre-empt each other. During startup some
messages are sent from the main thread which has a different priority
to the AP_DroneCAN threads, and can thus trigger this issue
2025-01-27 08:49:31 +09:00
..
AP_CAN.h AP_CANManager: Add multiCAN interface 2024-02-27 10:59:41 +11:00
AP_CANDriver.h AP_CANManager: support CAN_Dn_PROTOCOL2 for an aux 11 bit protocol 2023-11-28 11:38:16 +11:00
AP_CANIfaceParams.cpp AP_CANManager: support CAN frame logging 2024-12-12 15:13:40 +11:00
AP_CANManager_CANDriver_Params.cpp AP_CANManager: correct includes 2024-03-20 18:45:52 +11:00
AP_CANManager_config.h AP_CANManager: support CAN frame logging 2024-12-12 15:13:40 +11:00
AP_CANManager.cpp AP_CANManager: fixed critical race in log_text() 2025-01-27 08:49:31 +09:00
AP_CANManager.h AP_CANManager: support CAN frame logging 2024-12-12 15:13:40 +11:00
AP_CANSensor.cpp AP_CANManager: use NEW_NOTHROW for new(std::nothrow) 2024-06-04 09:20:21 +10:00
AP_CANSensor.h AP_CANManager: CANSensor: add getter for initialized 2024-05-07 09:48:10 +10:00
AP_SLCANIface.cpp AP_CANManager: Integrate methods for converting hexadecimal characters to numbers 2024-09-25 08:48:44 +10:00
AP_SLCANIface.h AP_CANManager: reimplement with BinarySemaphore 2024-01-03 07:37:05 +11:00
LogStructure.h AP_CANManager: support CAN frame logging 2024-12-12 15:13:40 +11:00
README.md AP_CANManager: update docs 2023-09-01 13:04:59 +10:00

Testing And Debugging

Testing under SITL

A wide range of DroneCAN peripherals are supported in the SITL simulation system. The simplest way of starting a DroneCAN enabled simulated vehicle is to use sim_vehicle.py.

For a quadplane use: sim_vehicle.py with the option -f quadplane-can

For a quadcopter use: sim_vehicle.py with the option -f quad-can