Using libcanard for DroneCAN

Libcanard is a minimal implementation of the DroneCAN protocol stack in C for resource-constrained applications.

Setting up libcanard

Generate DSDL Code:

DroneCAN requires us to build the header and source files for managing, encoding, and decoding messages. To do this, we will be following the instructions in GitHub - dronecan/dronecan_dsdlc

  1. Install pip by installing python

  2. Install the necessary dependencies pip install empy==3.3.4 and pip install expect

  3. Clone GitHub - dronecan/dronecan_dsdlc , GitHub - dronecan/pydronecan: python DroneCAN code generation, interface and utilities , GitHub - dronecan/DSDL: DSDL Protocol Description files for DroneCAN , and GitHub - dronecan/libcanard next to each other

  4. Run python dronecan_dsdlc/dronecan_dsdlc.py -O <output directory> <list of namespace dirs>. In our case, to build everything, run python dronecan_dsdlc/dronecan_dsdlc.py -O dsdlc_generated DSDL/uavcan DSDL/ardupilot DSDL/com DSDL/cuav/equipment/power DSDL/dronecan DSDL/mppt DSDL/tests

  5. The DSDL headers and source files are now generated. Copy these files into your repository and include <dronecan_msgs.h> which will be generated to include all of the other header files

Including the library and relevant drivers:

To use the libcanard library you only need to add the canard.c, canard.h, and canard_internals.h files from GitHub - dronecan/libcanard into your repository. However, it is beneficial to also use a driver. The drivers provided in their repository are a good example, but the STM32 library they provide unfortunately uses specific register addresses instead of the HAL library which makes it possibly not compatible with all STM32 boards. We rewrote their STM32 driver with HAL which can be found in efs-kitchen-sinks/CAN-ESC at Canard_Base ยท UWARG/efs-kitchen-sinks . The canard_stm32_driver.c and canard_stm32_driver.h files are the only ones you would need to copy to your repository, with the rest of the code acting as an example for how to use the driver.

Using libcanard

WIP