ardupilot/Tools/AP_Periph
Peter Barker 1d4b13af08 AP_Periph: correct compilation when both periph-adsb and GCS enabled
Get lots of these otherwise:

/home/pbarker/gcc/gcc-arm-none-eabi-10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: lib/libAP_Periph_libs.a(GCS_MAVLink.cpp.0.o): in function `mavlink_parse_char':
GCS_MAVLink.cpp:(.text.mavlink_parse_char+0x0): multiple definition of `mavlink_parse_char'; Tools/AP_Periph/adsb.cpp.41.o:adsb.cpp:(.text.mavlink_parse_char+0x0): first defined here
/home/pbarker/gcc/gcc-arm-none-eabi-10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: lib/libAP_Periph_libs.a(GCS_MAVLink.cpp.0.o): in function `put_bitfield_n_by_index':
GCS_MAVLink.cpp:(.text.put_bitfield_n_by_index+0x0): multiple definition of `put_bitfield_n_by_index'; Tools/AP_Periph/adsb.cpp.41.o:adsb.cpp:(.text.put_bitfield_n_by_index+0x0): first defined here
2021-12-14 10:35:06 +11:00
..
AP_Periph.cpp Tools: move from ENABLE_SCRIPTING to AP_SCRIPTING_ENABLED 2021-11-15 20:27:40 +11:00
AP_Periph.h AP_Periph: enable use of AP_ESC_Telem in peripheral nodes 2021-12-10 08:11:24 -08:00
GCS_MAVLink.cpp Tools: move from HAL_NO_GCS to HAL_GCS_ENABLED 2021-09-22 21:37:00 +10:00
GCS_MAVLink.h Tools: move from HAL_NO_GCS to HAL_GCS_ENABLED 2021-09-22 21:37:00 +10:00
Parameters.cpp AP_Periph: cope with GCS enabled for ESC telem 2021-12-10 08:11:24 -08:00
Parameters.h AP_Periph: cope with GCS enabled for ESC telem 2021-12-10 08:11:24 -08:00
README.md AP_Periph: fix command to build bootloader 2021-01-11 12:27:44 -08:00
adsb.cpp AP_Periph: correct compilation when both periph-adsb and GCS enabled 2021-12-14 10:35:06 +11:00
can.cpp AP_Periph: enable use of AP_ESC_Telem in peripheral nodes 2021-12-10 08:11:24 -08:00
hwing_esc.cpp AP_Periph: use native_millis for use in SITL 2020-11-04 19:59:40 +11:00
hwing_esc.h AP_Periph: fixed HWESC temperature decoding 2020-04-02 11:43:37 +11:00
i2c.h AP_Periph: added peripheral firmware 2019-08-27 10:29:56 +10:00
msp.cpp AP_Periph: fixed msp gps yaw 2021-07-25 21:00:09 +10:00
rc_out.cpp AP_Periph: cope with GCS enabled for ESC telem 2021-12-10 08:11:24 -08:00
release-notes.txt AP_Periph: updated release notes for 1.2.0 2021-01-06 07:59:33 +11:00
version.cpp AP_Periph: Use new AP_FWVersionDefine header 2020-09-23 20:58:35 +10:00
version.h AP_Periph: mark version as 1.3dev 2020-12-13 10:32:30 +11:00
wscript AP_Periph: allow build with ESC telemetry and BLHeli support 2021-12-10 08:11:24 -08:00

README.md

AP_Periph UAVCAN Peripheral Firmware

This is an ArduPilot based UAVCAN peripheral firmware. This firmware takes advantage of the wide range of sensor drivers in ArduPilot to make building a UAVCAN peripheral firmware easy.

The AP_Periph firmware is based on the same ChibiOS hwdef.dat system that is used to define pinouts for STM32 based flight controllers supported by ArduPilot. That means you can add support for a new UAVCAN peripheral based on the STM32 by just writing a simple hwdef.dat that defines the pinout of your device.

Currently we have four targets building for AP_Periph firmwares:

  • A STM32F103 128k flash part made by mRobotics (target f103-GPS)
  • A STM32F412 512k flash part made by CUAV (target CUAV_GPS)
  • A STM32F105 256k flash part (used in ZubaxGNSSv2)
  • A STM32F303 256k flash part made by mRobotics (target f303-GPS)

More can be added using the hwdef.dat system

Features

The AP_Periph firmware can be configured to enable a wide range of UAVCAN sensor types. Support is included for:

  • GPS modules (including RTK GPS)
  • Magnetometers (SPI or I2C)
  • Barometers (SPI or I2C)
  • Airspeed sensors (I2C)
  • Rangefinders (UART or I2C)
  • ADSB (Ping ADSB receiver on UART)
  • Battery Monitor (Analog, I2C/SMBus, UART)
  • LEDs (GPIO, I2C or WS2812 serial)
  • Safety LED and Safety Switch
  • Buzzer (tonealarm or simple GPIO)
  • RC Output (All standard RCOutput protocols)

An AP_Periph UAVCAN firmware supports these UAVCAN features:

  • dynamic or static CAN node allocation
  • firmware upload
  • automatically generated bootloader
  • parameter storage in flash
  • easy bootloader update
  • high resiliance features using watchdog, CRC and board checks
  • firmware update via MissionPlanner or uavcan-gui-tool

Building

Using f103-GPS as an example, build the main firmware like this:

  • ./waf configure --board f103-GPS
  • ./waf AP_Periph

that will build a file build/f103-GPS/bin/AP_Periph.bin. You can now load that using the CAN bootloader and either uavcan_gui_tool or MissionPlanner SLCAN support.

Flashing

To load directly with a stlink-v2, do this:

  • st-flash write build/f103-GPS/bin/AP_Periph.bin 0x8006400

for the CUAV_GPS which loads at offset 0x10000 use this:

  • st-flash write build/CUAV_GPS/bin/AP_Periph.bin 0x8010000

Flashing bootloader

To flash the bootloader use this:

  • st-flash write Tools/bootloaders/f103-GPS_bl.bin 0x8000000

Building bootloader

To build the bootloader use this:

  • Tools/scripts/build_bootloaders.py f103-GPS

the resulting bootloader will be in Tools/bootloaders

Firmware Builds

Firmware targets are automatically built and distributed on the ArduPilot firmware server on firmware.ardupilot.org. These firmwares can be loaded using Mission Planner or the UAVCAN GUI Tool. Parameters for peripherals can be changed using the Mission Planner SLCAN support or using UAVCAN GUI Tools.

User Bootloader Update

The bootloader is automatically stored in ROMFS in the main firmware. End users can update the bootloader by setting the UAVCAN parameter "FLASH_BOOTLOADER" to 1. After setting it to 1 the node will respond with a debug text message which can be seen in the UAVCAN GUI tool to show the result of the flash.

SITL Testing

Currently GPS peripheral build is supported under linux environment, we simulate a UAVCAN GPS Peripheral on SocketCAN.

Setup can be done as follows, this is on top of usual setup required to build ardupilot:

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib
sudo apt-get update
sudo apt-get -y install can-utils iproute2 linux-modules-extra-$(uname -r)
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0

Build Commands:

./waf configure --board sitl_periph_gps
./waf AP_Periph

Autotest Command:

Tools/autotest/autotest.py -v Copter build.SITLPeriphGPS test.CAN

Note

To run valgrind on AP_Periph binary you might need to get 32 bit version of libc6-dbg which can be simply get using following command for Ubuntu machines: sudo apt-get install libc6-dbg:i386


https://github.com/linux-can/can-utils contains a nice set of utility to do CAN related testings on Linux system. I used Ubuntu for this development, for Ubuntu systems you can simply download this tool using sudo apt-get install can-utils

Following are the common commands that can be used while testing or developing:

  • Create Virtual CAN Interface:
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
sudo ip link add dev vcan1 type vcan
sudo ip link set up vcan1
  • Route one CANSocket to another
sudo modprobe can-gw
sudo cangw -A -s vcan0 -d vcan1 -e
sudo cangw -A -s vcan1 -d vcan0 -e
  • Delete routes
sudo cangw -D -s vcan0 -d vcan1 -e
sudo cangw -D -s vcan1 -d vcan0 -e
  • Route SLCAN to VCAN, this allows connecting CAN devices to SITL run via CAN Adapter like the one running in Ardupilot itself.
sudo modprobe slcan
sudo modprobe can-gw
sudo slcan_attach -f -s8 -o /dev/ttyACM0
sudo slcand ttyACM0 slcan0
sudo ifconfig slcan0 up
sudo cangw -A -s vcan0 -d slcan0 -e
sudo cangw -A -s slcan0 -d vcan0 -e
  • Dump can messages:
sudo candump vcan0

Discussion and Feedback

Please join the discussions at these locations: