Post · 3 min read· pp. 59–62

RP2040 / RP2350 Boards

Arduino IDE Setup

madflight for RP2350/RP2040 requires arduino-pico v4.x.x or later (Note: for fast SDIO SDCARD arduino-pico v5.x.x is required.)

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

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

To compile an example use the following settings:

  • Set menu Tools->Operating System to "FreeRTOS SMP"
  • Set menu Tools->USB Stack to "Pico SDK"

PlatformIO Setup

  1. Clone or download a madflight release to your harddisk
  2. Start PlatformIO and open the madflight root folder
  3. Open file platformio.ini and adapt the settings
  4. Compile env:RP2040, env:RP2350A, or env:RP2350B

Note: RP2040/RP2350 is not merged into mainline PlatformIO, see here. On Windows you need to enable long path names, see previous link for instructions.

To enable uploading on Windows you need to use Zadig - Connect a RP2 device whilst holding the boot button, then in Zadig select "RP2 Boot (Interface 1) and install the WinUSB driver. See here

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 definedbrd/default_RP2040.h, but can be modified with madflight_config configuration settings in your program.

Module <-> HW_PIN_xxxGPIOBoardGPIOHW_PIN_xxx <-> Module
pin_ser0_tx (connect to radio rx)0USB connectorVBUSnot connected
pin_ser0_rx (connect to radio tx)1VSYS5V input via diode (*)
GNDGNDGNDGND
pin_out0 (connect to motor/servo1)2ENnot connected
pin_out1 (connect to motor/servo2)33.3V out3V3
pin_out2 (connect to motor/servo3)4VREFnot connected
pin_out3 (connect to motor/servo4)5(A2) 28pin_bat_v (connect to battery voltage divider)
GNDGNDGNDGND
pin_out4 (connect to motor/servo5)6(A1) 27pin_bat_i (connect to battery current sensor)
pin_out5 (connect to motor/servo6)7(A0) 26free for future use
pin_ser1_tx (connect to gps rx)8RUNreset button to GND
pin_ser1_rx (connect to gps tx)922pin_imu_int (connect to SPI/I2C gyro interrupt out)
GNDGNDGNDGND
pin_i2c1_sda (connect to I2C gyro sda)1021pin_i2c0_scl (connect to scl pins of barometer, magnetometer, etc.)
pin_i2c1_scl (connect to I2C gyro scl)1120pin_i2c0_sda (connect to sda pins of barometer, magnetometer, etc.)
pin_spi1_miso (connect to sdcard miso)1219pin_spi0_mosi (connect to SPI gyro mosi)
_pin_bbx_cs _ (connect to sdcard cs)1318pin_spi0_sclk (connect to SPI gyro sclk)
GNDGNDGNDGND
pin_spi1_sclk (connect to sdcard sclk)1417pin_imu_cs (connect to SPI gyro cs)
pin_spi1_mosi (connect to sdcard mosi)15JTAG pins16pin_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

  • OUT: Consecutive even/odd PWM pins (e.g. pins 2,3 or 10,11) share the same timer and have the same frequency.