Skip to content

Commit

Permalink
Add RP2350 support
Browse files Browse the repository at this point in the history
  • Loading branch information
qqqlab committed Aug 26, 2024
1 parent f36d430 commit 8f6e2ad
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
26 changes: 15 additions & 11 deletions examples/04.Plane/04.Plane.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*#########################################################################################################################
WARNING: This program is highly experimental - not flight tested at all - it was only dry run tested!
WARNING: This program is experimental - it was only flight-tested in a couple of flights
This is just a quick first attempt to make a plane controller, it has 3 flight modes: MANUAL, ROLL and FBWA.
This program is an airplane controller, it has 3 flight modes: MANUAL, ROLL and FBWA.
## MANUAL Mode
Expand Down Expand Up @@ -43,7 +43,7 @@ Then set to FBWA flight mode, keep the radio sticks centered, and move the plane
surfaces work to oppose the move, that is: pitching the plane down should move elevator up, banking right should deflect
the right aileron down, left aileron up.
Another thing that needs to be set are the PID parameters. Set to FBWA mode and adjust the PID parameters so that the
Another thing that needs to be set are the PID parameters. Set to ROLL or FBWA mode and adjust the PID parameters so that the
control surfaces react quickly, but don't oscillate, on changes in attitude.
###########################################################################################################################
Expand Down Expand Up @@ -117,13 +117,6 @@ Copyright (c) 2024 https://github.com/qqqlab/madflight
#define HW_PIN_BB_CS -1
//*/

//RP2040 specific options
//#define HW_RP2040_SYS_CLK_KHZ 200000 //overclocking
//#define HW_RP2040_USE_FREERTOS //enable use of FreeRTOS - experimental

//ESP32 specific options
//#define USE_ESP32_SOFTWIRE //use bitbang I2C (not hardware I2C) See https://github.com/espressif/esp-idf/issues/4999

//========================================================================================================================//
// BOARD //
//========================================================================================================================//
Expand Down Expand Up @@ -301,7 +294,7 @@ void setup() {
led.on();

hw_setup(); //hardware specific setup for spi and Wire (see hw_xxx.h)
cfg.begin(); //read config from EEPROM
cfg.begin(); //read config from EEPROM
cli.print_boardInfo(); //print board info and pinout
cli.print_i2cScan(); //print i2c scan
rcin.setup(); //Initialize radio communication. Set correct USE_RCIN_xxx user specified defines above. Note: rcin_Setup() function is defined in rcin.h, but normally no changes needed there.
Expand Down Expand Up @@ -344,6 +337,17 @@ void setup() {
ahrs.setup(LP_gyr, LP_acc, LP_mag); //setup low pass filters for Mahony/Madgwick filters
ahrs.setInitalOrientation(); //do this before IMU update handler is started

//pinMode(9,INPUT);
/*
int v1 = 0;
while(1) {
int v2=digitalRead(9);
if(v1!=v2) {
Serial.printf("v=%d\n",v1);
v1=v2;
}
}
*/
//start IMU update handler
imu.onUpdate = imu_loop;
if(!imu.waitNewSample()) die("IMU interrupt not firing.");
Expand Down
20 changes: 13 additions & 7 deletions extras/TestFLOPS/TestFLOPS.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
//STM32G431 1:dt= 2358 e=2.721910715 2:dt= 1306 e=2.721910715 -> 85.55 MLOOPS, 84.03 MFLOPS
//STM32F405 1:dt= 2382 e=2.721910715 2:dt= 1328 e=2.721910715 -> 85.39 MLOOPS, 82.57 MFLOPS
//ESP32 1:dt= 2515 e=2.721910715 2:dt= 1682 e=2.721910715 -> 108.05 MLOOPS, 62.89 MFLOPS
//ESP32S3 1:dt= 2100 e=2.721910715 2:dt= 1675 e=2.721910715 -> 211.77 MLOOPS, 61.43 MFLOPS
//STM32F411 1:dt= 4170 e=2.721910715 2:dt= 2301 e=2.721910715 -> 48.15 MLOOPS, 47.75 MFLOPS
//RP2040 1:dt= 54372 e=2.721910715 2:dt=50233 e=2.721910715 -> 21.74 MLOOPS, 2.00 MFLOPS
//STM32F103 1:dt=100353 e=2.721910715 2:dt=91298 e=2.721910715 -> 9.93 MLOOPS, 1.10 MFLOPS

//ESP32 240MHz 1:dt= 2515 e=2.721910715 2:dt= 1682 e=2.721910715 -> 108.05 MLOOPS, 62.89 MFLOPS
//ESP32S3 240MHz 1:dt= 2100 e=2.721910715 2:dt= 1675 e=2.721910715 -> 211.77 MLOOPS, 61.43 MFLOPS

//RP2040 133MHz 1:dt= 54372 e=2.721910715 2:dt=50233 e=2.721910715 -> 21.74 MLOOPS, 2.00 MFLOPS
//RP2350 150MHz 1:dt= 2677 e=2.721910715 2:dt= 1421 e=2.721910715 -> 71.66 MLOOPS, 78.00 MFLOPS
//RP2350 300MHz 1:dt= 1336 e=2.721910715 2:dt= 709 e=2.721910715 -> 143.55 MLOOPS, 156.25 MFLOPS

//STM32F103 72MHz 1:dt=100353 e=2.721910715 2:dt=91298 e=2.721910715 -> 9.93 MLOOPS, 1.10 MFLOPS
//STM32F405 168MHz 1:dt= 2382 e=2.721910715 2:dt= 1328 e=2.721910715 -> 85.39 MLOOPS, 82.57 MFLOPS
//STM32F411 100MHz 1:dt= 4170 e=2.721910715 2:dt= 2301 e=2.721910715 -> 48.15 MLOOPS, 47.75 MFLOPS
//STM32G431 170MHz 1:dt= 2358 e=2.721910715 2:dt= 1306 e=2.721910715 -> 85.55 MLOOPS, 84.03 MFLOPS

void setup() {
Serial.begin(115200);
while(!Serial);
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=madflight
version=1.1.4
version=1.2.0
author=qqqlab
maintainer=qqqlab <[email protected]>
license=GNU
sentence=Flight Controller for ESP32 / RP2040 / STM32
sentence=Flight Controller for ESP32 / RP2350 / RP2040 / STM32
paragraph=Flight tested with readily available development boards and sensor breakout boards. Build a quadcopter, helicoper, airplane or VTOL craft. Includes modules for PID control, CRSF/ELRS/DSMX/SBUS receiver and telemetry, AHRS, GPS, barometer, magnetometer, calibration, command line interface, black box data logging.
category=Other
url=https://madflight.com/arduino
Expand Down
2 changes: 1 addition & 1 deletion src/madflight.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define MADFLIGHT_VERSION "madflight v1.2.0-DEV"
#define MADFLIGHT_VERSION "madflight v1.2.0"

/*==========================================================================================
madflight - Flight Controller for ESP32 / RP2040 / STM32
Expand Down
13 changes: 10 additions & 3 deletions src/madflight/hw_RP2040/hw_RP2040.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ void hw_eeprom_commit() {
//======================================================================================================================//
// IMU
//======================================================================================================================//
#define IMU_EXEC IMU_EXEC_FREERTOS_OTHERCORE //use FreeRTOS on second core (Note: RP2040 IMU_EXEC_IRQ blocks the system)
#define IMU_FREERTOS_TASK_PRIORITY 7 //IMU Interrupt task priority, higher number is higher priority. Max priority on RP2040 is 7
#define HW_RP2040_USE_FREERTOS //enable FreeRTOS
#ifdef PICO_RP2350
#define IMU_EXEC IMU_EXEC_IRQ
#else
#define IMU_EXEC IMU_EXEC_FREERTOS_OTHERCORE //use FreeRTOS on second core (Note: RP2040 IMU_EXEC_IRQ blocks the system)
#define IMU_FREERTOS_TASK_PRIORITY 7 //IMU Interrupt task priority, higher number is higher priority. Max priority on RP2040 is 7
#define HW_RP2040_USE_FREERTOS //enable FreeRTOS
#endif

//======================================================================================================================//
// hw_setup()
Expand Down Expand Up @@ -88,6 +92,9 @@ void hw_setup()
bb_spi->begin();

hw_eeprom_begin();

//IMU
pinMode(HW_PIN_IMU_EXTI, INPUT); //needed for RP2350, should not hurt for RP2040
}

void hw_reboot() {
Expand Down
6 changes: 3 additions & 3 deletions src/madflight/imu/imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ configures gyro and accel with 1000 Hz sample rate (with on sensor 200 Hz low pa
#define IMU_ALIGN_CW270FLIP 8

//Available excecution methods (not all platforms support all methods)
#define IMU_EXEC_IRQ 1 //execute in IRQ context on first core (only works on STM32)
#define IMU_EXEC_FREERTOS 2 //execute as IRQ triggered high priority FreeRTOS task on same core as setup() (only works on ESP32, RP2040)
#define IMU_EXEC_FREERTOS_OTHERCORE 3 //execute as IRQ triggered high priority FreeRTOS task on second core (only works on RP2040)
#define IMU_EXEC_IRQ 1 //execute in IRQ context on first core (works on STM32, RP2350. Does NOT work on ESP32)
#define IMU_EXEC_FREERTOS 2 //execute as IRQ triggered high priority FreeRTOS task on same core as setup() (works on ESP32, RP2040)
#define IMU_EXEC_FREERTOS_OTHERCORE 3 //execute as IRQ triggered high priority FreeRTOS task on second core (works on RP2040)

//default settings
#ifndef IMU_GYRO_DPS
Expand Down

0 comments on commit 8f6e2ad

Please sign in to comment.