Skip to content

Instantly share code, notes, and snippets.

@tstellanova
Last active August 5, 2020 15:43
Show Gist options
  • Save tstellanova/81c963f556522447dd007a0c3a84ebc3 to your computer and use it in GitHub Desktop.
Save tstellanova/81c963f556522447dd007a0c3a84ebc3 to your computer and use it in GitHub Desktop.
Current State of Embedded Rust for Flight Controllers

Introduction

A wide variety of widely-available flight controllers and associated robotics boards have been released in the past five years. These boards incorporate a careful selection of sensors and actuator outputs useful for robotics-- not just for flying vehicles, but also rovers and underwater vehicles. This living document analyzes briefly the compatibility of embedded Rust with these inexpensive and powerful boards.

Overall Utility Issues

General issues that impact the usefulness of embedded Rust with these kinds of boards:

  • No (or fragmented) DMA support. Some embedded HAL crates have DMA support already, but many do not. Almost none of the DMA APIs resemble each other. There is at least one effort underway to unify the DMA APIs
  • Interrupt handling is possible but requires glue code at the application level. It is not straightforward to create an encapsulated device driver that owns an interrupt (such as waiting on a DRDY line). Both bare metal and frameworks such as RTFM seem to encourage monolithic applications rather than separated driver concerns.
  • The procedure for common tasks such as configuring the MCU clock speeds or obtaining I2C1 differs wildly between HAL crates: this requires manual customization at the BSP level.

Flight Controllers

  • Note that many of the PX4-compatible flight controllers contain a separate IO coprocessor (typically stm32f103) that drives a few key functions such as PWM output. Communications with this coprocessor is via a 1.5 Mbps serial UART and typically requires DMA to function properly.

Holybro Durandal (stm32h743 480 MHz)

  • Is in essence a PX4 FMUv6. Has px4io coprocessor.
  • Blocking I2C and SPI largely work with stm32h7xx-hal
  • stm32h7xx-hal DMA is a project in progress (and it's huge)
  • Work in progress toward a Durandal BSP

Holybro Pixhawk 4 (stm32f765 216 MHz)

  • Is PX4 FMUv5. Has px4io coprocessor
  • Could use stm32f7xx-hal
  • stm32f7xx-hal supports DMA and SPI on this processor
  • stm32f7xx-hal does not support I2C at all -- It now does in the repo master
  • Work in progress toward a Pixhawk 4 BSP crate

iFlight F7 Twing (stm32f722 216 MHz)

  • This and similar are popular boards with the betaflight/cleanflight crowd
  • Dual 6DOFs, some boards lack magnetometer
  • stm32f7xx-hal lacks support for DMA, SPI, and I2C for this processor

Cube Black (Pixhawk 2) (stm32f427 168 MHz)

  • Essentially PX4 FMUv3, separate px4io coprocessor.
  • Cube contains vibration isolated sensors
  • stm32f4xx-hal stable, lacks DMA support

Pixracer (stm32f427 168 MHz)

  • Is PX4 FMUV4
  • Later R15 version: STM32F427VIT6 rev.3 180 MHz ?
  • Fairly well-understood sensors
  • stm32f4xx-hal stable, lacks DMA support
  • The Pixracer lacks an io coprocessor (px4io) and so DMA for 1.5 Mbps UART might not be needed
    • PWM can be driven directly (at least channels 1-4; 5-6 with more work)
  • Experimental cPPM support implemented
  • S.Bus can also be used with RCIN (read with UART)
  • Work in progress toward a Pixracer BSP

Other Boards

PX4FLOW (stm32f407VGT6 168 MHz)

  • This optical flow sensor board includes the stm32f407 and MT9V034 global shutter image sensor in a compact, lightweight board along with L3GD20 (or similar) gyroscope.
  • Multiple variants of this board have been built, with various processors and gyros, though the image sensor remains consistent.
  • Provides multiple i/o port including i2c1, usart2, usart3, usb, as well as SWD, and standard pin header originally designed to communicate with eg a MAXBOTIX sonar distance sensor (used for detecting ground range)
  • Works with stm32f4xx-hal
  • CUAV PX4FLOW 2.3 is the latest available version
  • Work in a progress toward a PX4Flow BSP
  • Really requires DMA to operate at high frame rates, and DMA has not yet landed on stm32f4xx-hal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment