STM32 Boards
Arduino IDE Setup
madflight for STM32 requires:
-
STM32duino Arduino Core for STM32 v2.x.x Start the Arduino IDE and select menu Tools->Board Manager to install this software.
-
STM32duino FreeRTOS Select menu Tools->Manage Libraries, then search for "STM32duino FreeRTOS".
Install the madflight library: use menu Tools->Manage Libraries, then search for madflight
Open a madflight example: use menu File->Examples->Examples for custom libraries->madflight->00.HelloWorld.ino
PlatformIO Setup
-
Clone or download a madflight release to your harddisk
-
Start PlatformIO and open the madflight root folder
-
Open file platformio.ini and adapt the settings
-
Compile env:STM32F411
Pinout STM32 Commercial Flight Controllers
In the src/brd directory you'll find 400+ Betaflight configuration files for commercial flight controllers. Use the brd/betaflight/XXX.h header file of your board, and in your program override settings as needed to match your board.
The Betaflight configuration files are manually generated by a Python script in the 'extras' folder. If your favorite board is missing, run the script to add it.
Pinout STM32F411 Black Pill
This is the default pinout for STM32. It is optimized for the WeAct STM32F411 Black Pill (40 pin) board. This pinout is defined in brd/default_STM32.h, but can be modified with madflight_config configuration settings in your program.
| Function | GPIO | Board | GPIO | Function |
|---|---|---|---|---|
| not connected | VB | SWD pins | 3V3 | 3V3 out |
| pin_led | C13 | G | GND | |
| free for future use | C14 | 5V | 5V input (*) | |
| free for future use | C15 | B9 | pin_i2c1_sda (connect to I2C gyro sda) | |
| not connected | R | B8 | free for future use | |
| free for future use | A0 | B7 | pin_i2c0_scl (connect to scl pins of barometer, magnetometer, etc. sensors) | |
| free for future use | A1 | B6 | pin_i2c0_sda (connect to sda pins of barometer, magnetometer, etc. sensors) | |
| pin_ser1_tx (connect to gps rx) | A2 | B5 | free for future use | |
| pin_ser1_rx (connect to gps tx) | A3 | B4 | free for future use | |
| pin_imu_cs (connect to SPI gyro cs) | A4 | B3 | pin_ser0_rx (connect to radio tx) | |
| pin_spi0_sclk (connect to SPI gyro sclk) | A5 | A15 | pin_ser0_tx (connect to radio rx) | |
| pin_spi0_miso (connect to SPI gyro miso) | A6 | A12 | USB D+ | |
| pin_spi0_mosi (connect to SPI gyro mosi) | A7 | A11 | USB D- | |
| pin_bat_i (connect to battery current sensor) | B0 | A10 | pin_out5 (connect to motor/servo6) | |
| pin_bat_v (connect to battery voltage divider) | B1 | A9 | pin_out4 (connect to motor/servo5) | |
| pin_imu_int (connect to SPI/I2C gyro interrupt out) | B2 | A8 | pin_out3 (connect to motor/servo4) | |
| pin_i2c1_scl (connect to I2C gyro scl) | B10 | B15 | pin_out2 (connect to motor/servo3) | |
| 3V3 out | 3V3 | B14 | pin_out1 (connect to motor/servo2) | |
| GND | G | B13 | pin_out0 (connect to motor/servo1) | |
| 5V input (*) | 5V | USB connector | B12 | free for future use |
Internally connected: C13 - pin_led, A0 - key button
(*) 5V input via diode from BEC. Without a diode take care not connect USB and the battery at the same time!
STM32 Hardware
The STM32 MCU family is a huge collection of chips. madflight will run on most stm32duino supported F4, F7, H7 and similar chips, preferred are STM32H743 and STM32F405.
Most (if not all) supported STM32 targets have a single core MCU with FPU.
FreeRTOS is required for madflight v1.3 and later.
madflight for STM32 runs the IMU loop by default in interrupt context.
madflight Limitiations
- OUT: STM32duino PWM drivers have 1 us resolution, too coarse for OneShot
- OUT: PWM pins with shared timer have same frequency
- BBX: SDCARD is not implemented yet
- When using Arduino IDE: the standard 64 byte buffer for the serial ports is too small for GPS/MAVLink -> You need to set
#define SERIAL_RX_BUFFER_SIZE 256and#define SERIAL_TX_BUFFER_SIZE 256in HardwareSerial.h (in PlatformIO this is done in platfromio.ini)
