From 8f6e2ad1be99127e1732eaf6f1738fc9587df77e Mon Sep 17 00:00:00 2001 From: qqqlab <46283638+qqqlab@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:15:23 +0200 Subject: [PATCH] Add RP2350 support --- examples/04.Plane/04.Plane.ino | 26 +++++++++++++++----------- extras/TestFLOPS/TestFLOPS.ino | 20 +++++++++++++------- library.properties | 4 ++-- src/madflight.h | 2 +- src/madflight/hw_RP2040/hw_RP2040.h | 13 ++++++++++--- src/madflight/imu/imu.h | 6 +++--- 6 files changed, 44 insertions(+), 27 deletions(-) diff --git a/examples/04.Plane/04.Plane.ino b/examples/04.Plane/04.Plane.ino index f4e8abd..7e8893a 100644 --- a/examples/04.Plane/04.Plane.ino +++ b/examples/04.Plane/04.Plane.ino @@ -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 @@ -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. ########################################################################################################################### @@ -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 // //========================================================================================================================// @@ -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. @@ -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."); diff --git a/extras/TestFLOPS/TestFLOPS.ino b/extras/TestFLOPS/TestFLOPS.ino index 62a875d..d8895e0 100644 --- a/extras/TestFLOPS/TestFLOPS.ino +++ b/extras/TestFLOPS/TestFLOPS.ino @@ -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); diff --git a/library.properties b/library.properties index 77ab931..f813b92 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=madflight -version=1.1.4 +version=1.2.0 author=qqqlab maintainer=qqqlab 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 diff --git a/src/madflight.h b/src/madflight.h index c2d63a7..902d42d 100644 --- a/src/madflight.h +++ b/src/madflight.h @@ -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 diff --git a/src/madflight/hw_RP2040/hw_RP2040.h b/src/madflight/hw_RP2040/hw_RP2040.h index 03c39d0..f85ff4c 100644 --- a/src/madflight/hw_RP2040/hw_RP2040.h +++ b/src/madflight/hw_RP2040/hw_RP2040.h @@ -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() @@ -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() { diff --git a/src/madflight/imu/imu.h b/src/madflight/imu/imu.h index eb601af..05648d6 100644 --- a/src/madflight/imu/imu.h +++ b/src/madflight/imu/imu.h @@ -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