Skip to content

Commit 1963a8a

Browse files
committed
Fix ESP32 IMU
1 parent 82e8f4c commit 1963a8a

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

examples/01.Quadcopter/madflight_config.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ imu_align CW90 // options: CW0, CW90, CW180, CW270, CW0FLIP, CW90FLIP,
4040
imu_i2c_adr 0 // use 0 for default i2c address
4141

4242
// RCL - Remote Controller Link
43-
rcl_gizmo SBUS // options: NONE, MAVLINK, CRSF, SBUS, DSM, PPM, PWM
43+
rcl_gizmo CRSF // options: NONE, MAVLINK, CRSF, SBUS, DSM, PPM, PWM
4444
rcl_num_ch 8 // number of channels
4545
rcl_deadband 0 // center stick deadband
4646

4747
// BAR - Barometer
48-
bar_gizmo BMP280 // options: NONE, BMP390, BMP388, BMP280, MS5611
48+
bar_gizmo NONE // options: NONE, BMP390, BMP388, BMP280, MS5611
4949
bar_i2c_adr 0
5050

5151
// MAG - Magnetometer
52-
mag_gizmo QMC5883 // options: NONE, QMC5883, MS5611
52+
mag_gizmo NONE // options: NONE, QMC5883, MS5611
5353
mag_i2c_adr 0
5454

5555
// BAT - Battery Monitor
56-
bat_gizmo INA226 // options: NONE, ADC, INA226, INA228
56+
bat_gizmo NONE // options: NONE, ADC, INA226, INA228
5757
bat_i2c_adr 0
5858

59-
// GPS
60-
gps_gizmo UBLOX // options: NONE, UBLOX
59+
// GPS -- TODO (crashes)
60+
gps_gizmo NONE // options: NONE, UBLOX
6161
gps_baud 0 // use 0 for auto baud
6262

63-
// BBX - Black Box Data Logger
63+
// BBX - Black Box Data Logger -- TODO
6464
bbx_gizmo NONE // options: NONE, SDSPI, SDMMC
6565

6666
)"" // End of MADFLIGHT_CONFIG

examples/02.QuadcopterAdvanced/madflight_config.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
//
2626
//========================================================================================================================//
2727

28+
29+
2830
#define MADFLIGHT_CONFIG R""(
2931

3032
// IMU - Inertial Measurement Unit (acc/gyro)
@@ -40,27 +42,27 @@ imu_align CW90 // options: CW0, CW90, CW180, CW270, CW0FLIP, CW90FLIP,
4042
imu_i2c_adr 0 // use 0 for default i2c address
4143

4244
// RCL - Remote Controller Link
43-
rcl_gizmo SBUS // options: NONE, MAVLINK, CRSF, SBUS, DSM, PPM, PWM
45+
rcl_gizmo CRSF // options: NONE, MAVLINK, CRSF, SBUS, DSM, PPM, PWM
4446
rcl_num_ch 8 // number of channels
4547
rcl_deadband 0 // center stick deadband
4648

4749
// BAR - Barometer
48-
bar_gizmo BMP280 // options: NONE, BMP390, BMP388, BMP280, MS5611
50+
bar_gizmo NONE // options: NONE, BMP390, BMP388, BMP280, MS5611
4951
bar_i2c_adr 0
5052

5153
// MAG - Magnetometer
52-
mag_gizmo QMC5883 // options: NONE, QMC5883, MS5611
54+
mag_gizmo NONE // options: NONE, QMC5883, MS5611
5355
mag_i2c_adr 0
5456

5557
// BAT - Battery Monitor
56-
bat_gizmo INA226 // options: NONE, ADC, INA226, INA228
58+
bat_gizmo NONE // options: NONE, ADC, INA226, INA228
5759
bat_i2c_adr 0
5860

59-
// GPS
60-
gps_gizmo UBLOX // options: NONE, UBLOX
61+
// GPS -- TODO (crashes)
62+
gps_gizmo NONE // options: NONE, UBLOX
6163
gps_baud 0 // use 0 for auto baud
6264

63-
// BBX - Black Box Data Logger
65+
// BBX - Black Box Data Logger -- TODO
6466
bbx_gizmo NONE // options: NONE, SDSPI, SDMMC
6567

6668
)"" // End of MADFLIGHT_CONFIG

src/madflight/cfg/cfg_cpp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ void CfgClass::printValue(uint16_t i) {
240240
if(getOptionString(i, param_int32_t[i], option)) {
241241
Serial.print(option);
242242
}else{
243-
Serial.printf("%d", param_int32_t[i]); //option lookup failed, print numeric value
243+
Serial.printf("%d", (int)param_int32_t[i]); //option lookup failed, print numeric value
244244
}
245245
break;
246246
}
247247
case 'f': //float
248248
Serial.printf("%f", param_float[i]);
249249
break;
250250
case 'i': //integer
251-
Serial.printf("%d", param_int32_t[i]);
251+
Serial.printf("%d", (int)param_int32_t[i]);
252252
break;
253253
case 'p': //pinnumber/pinname
254254
hal_print_pin_name(param_int32_t[i]);
@@ -316,7 +316,7 @@ bool CfgClass::setParam(String namestr, String val) {
316316
param_int32_t[i] = enum_idx;
317317
return true;
318318
}else{
319-
Serial.printf("CFG: WARNING - Param '%s' has no '%s' option. Available options: \n", namestr.c_str(), val.c_str(), Cfg::param_list[i].options);
319+
Serial.printf("CFG: WARNING - Param '%s' has no '%s' option. Available options: %s\n", namestr.c_str(), val.c_str(), Cfg::param_list[i].options);
320320
return false;
321321
}
322322
break;

src/madflight/hal/ESP32/hal_ESP32_cpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// IMU
1818
//======================================================================================================================//
1919
#define IMU_EXEC IMU_EXEC_FREERTOS //ESP32 always uses FreeRTOS on core0 (can't used float on core1)
20-
#define IMU_FREERTOS_TASK_PRIORITY 31 //IMU Interrupt task priority, higher number is higher priority. Max priority on ESP32 is 31
20+
#define IMU_FREERTOS_TASK_PRIORITY 24 //IMU Interrupt task priority, higher number is higher priority. Max priority on ESP32 is 31, but max allowed is 24
2121

2222
//======================================================================================================================//
2323
// FREERTOS

src/madflight/imu/imu_cpp.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,25 @@ void _imu_ll_interrupt_handler();
309309

310310
void _imu_ll_interrupt_setup(int interrupt_pin) {
311311
if(!_imu_ll_task_handle) {
312-
//xTaskCreatePinnedToCore(_imu_ll_task, "_imu_ll_task", 4096, NULL, IMU_FREERTOS_TASK_PRIORITY /*priority 0=lowest*/, &_imu_ll_task_handle, othercore); //ESP32 only
313-
xTaskCreate(_imu_ll_task, "IMU", FREERTOS_DEFAULT_STACK_SIZE, NULL, IMU_FREERTOS_TASK_PRIORITY /*priority 0=lowest*/, &_imu_ll_task_handle);
312+
//
314313
#if IMU_EXEC == IMU_EXEC_FREERTOS_OTHERCORE
315314
int callcore = hal_get_core_num();
316315
int othercore = (callcore+1)%2;
317-
vTaskCoreAffinitySet(_imu_ll_task_handle, (1<<othercore)); //Sets the core affinity mask for a task, i.e. the cores on which a task can run.
316+
317+
//TODO move this to hal
318+
#if defined ARDUINO_ARCH_ESP32
319+
//note: probably don't what to use this because of single FPU context switching issues...
320+
xTaskCreatePinnedToCore(_imu_ll_task, "IMU", FREERTOS_DEFAULT_STACK_SIZE, NULL, IMU_FREERTOS_TASK_PRIORITY /*priority 0=lowest*/, &_imu_ll_task_handle, othercore); //[ESP32 only]
321+
#elif defined ARDUINO_ARCH_RP2040
322+
xTaskCreate(_imu_ll_task, "IMU", FREERTOS_DEFAULT_STACK_SIZE, NULL, IMU_FREERTOS_TASK_PRIORITY /*priority 0=lowest*/, &_imu_ll_task_handle);
323+
vTaskCoreAffinitySet(_imu_ll_task_handle, (1<<othercore)); //[RP2040 only] Sets the core affinity mask for a task, i.e. the cores on which a task can run.
324+
#else
325+
#error "IMU_EXEC == IMU_EXEC_FREERTOS_OTHERCORE not supported on this processor"
326+
#endif
327+
318328
Serial.printf(MF_MOD ": IMU_EXEC_FREERTOS_OTHERCORE call_core=%d imu_core=%d\n", callcore, othercore);
319329
#else
330+
xTaskCreate(_imu_ll_task, "IMU", FREERTOS_DEFAULT_STACK_SIZE, NULL, IMU_FREERTOS_TASK_PRIORITY /*priority 0=lowest*/, &_imu_ll_task_handle);
320331
Serial.println(MF_MOD ": IMU_EXEC_FREERTOS");
321332
#endif
322333
}

0 commit comments

Comments
 (0)