RP2040 / RP2350 Boards

Arduino IDE Setup

madflight for RP2040/RP2350 requires arduino-pico v4.x.x

Start the Arduino IDE and select menu Tools->Board Manager to install this software.

PlatformIO Setup

Clone or download the madflight repository from GitHub.

Start PlatformIO, press the "Import Arduino Project" button, and import a madflight example.

Adapt the platformio.ini file as follows:

; PlatformIO Project Configuration File for madflight

[env]
; Set this to the folder where madflight.h is located
; Default locations when installed via the Arduino IDE:
;    Windows: C:\Users\{username}\Documents\Arduino\libraries\madflight
;    macOS:   /Users/{username}/Documents/Arduino/libraries/madflight
;    Linux:   /home/{username}/Arduino/libraries/madflight

lib_extra_dirs = /ENTER/MADFLIGHT/FOLDER/HERE

; RP2040/RP2350 is not merged into mainline PlatformIO, see 
; https://arduino-pico.readthedocs.io/en/latest/platformio.html
; on Windows you need to enable long path names, see above link for instructions

[env:madflight_pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower

[env:madflight_pico2]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rpipico2
framework = arduino
board_build.core = earlephilhower

Pinout Raspberry Pi Pico / Pico2

This is the default pinout for RP2040 and RP2350. It is optimized for Raspberry Pi Pico / Pico2 (40 pin) boards. This pinout is defined in madflight_board__RP2040.h, but can be modified with madflight pin_xxx configuration settings.

Module <-> HW_PIN_xxx GPIO Board GPIO HW_PIN_xxx <-> Module
pin_ser0_tx (connect to radio rx) 0 USB connector VBUS not connected
pin_ser0_rx (connect to radio tx) 1 VSYS 5V input via diode (*)
GND GND GND GND
pin_out0 (connect to motor/servo1) 2 EN not connected
pin_out1 (connect to motor/servo2) 3 3.3V out 3V3
pin_out2 (connect to motor/servo3) 4 VREF not connected
pin_out3 (connect to motor/servo4) 5 (A2) 28 pin_bat_v (connect to battery voltage divider)
GND GND GND GND
pin_out4 (connect to motor/servo5) 6 (A1) 27 pin_bat_i (connect to battery current sensor)
pin_out5 (connect to motor/servo6) 7 (A0) 26 free for future use
pin_ser1_tx (connect to gps rx) 8 RUN reset button to GND
pin_ser1_rx (connect to gps tx) 9 22 pin_imu_int (connect to SPI/I2C gyro interrupt out)
GND GND GND GND
pin_i2c1_sda (connect to I2C gyro sda) 10 21 pin_i2c0_scl (connect to scl pins of barometer, magnetometer, etc.)
pin_i2c1_scl (connect to I2C gyro scl) 11 20 pin_i2c0_sda (connect to sda pins of barometer, magnetometer, etc.)
pin_spi1_miso (connect to sdcard miso) 12 19 pin_spi0_mosi (connect to SPI gyro mosi)
_pin_bbx_cs _ (connect to sdcard cs) 13 18 pin_spi0_sclk (connect to SPI gyro sclk)
GND GND GND GND
pin_spi1_sclk (connect to sdcard sclk) 14 17 pin_imu_cs (connect to SPI gyro cs)
pin_spi1_mosi (connect to sdcard mosi) 15 JTAG pins 16 pin_spi0_miso (connect to SPI gyro miso)

Internally connected: pin_led GPIO25

(*) 5V input via diode from BEC or DC-DC converter. Without a diode take care not connect USB and the battery at the same time!

RP2040/RP2350 Hardware

RP2350 (Raspberry Pi Pico2) is newer and a lot more powerful than RP2040 (Raspberry Pi Pico).

RP2350 has dual core processor, plus dual single precision FPUs.

RP2040 has dual core processor, but no FPUs.

madflight uses float and is much happier with RP2350 than with RP2040 !

madflight uses a custom Serial library, because the default Arduino Serial transmitter blocks after sending a couple bytes. Something we don't want.

madflight uses FreeRTOS and executes the 1000Hz IMU loop on the second core. The first core is used for the other sensors.

madflight Limitiations

  • BBX: SDCARD only with SPI interface (not with MMC interface)
  • OUT: Consecutive even/odd PWM pins (e.g. pins 2,3 or 10,11) share the same timer and have the same frequency.