Skip to content

move who_am_i() after soft reset and SPI toggle#103

Merged
qqqlab merged 2 commits intoqqqlab:mainfrom
tstibor:m5stampfly_bmi270_who_am_i
Mar 13, 2026
Merged

move who_am_i() after soft reset and SPI toggle#103
qqqlab merged 2 commits intoqqqlab:mainfrom
tstibor:m5stampfly_bmi270_who_am_i

Conversation

@tstibor
Copy link
Contributor

@tstibor tstibor commented Mar 12, 2026

Testing on m5stampfly the BMI270 IMU is not recognized due to failed who_am_i() returning 255, rather than the ID 0x24. This problem is caused because who_am_i() is called before soft reset and SPI toggle.

** Without patch **

Arduino library: Arduino-ESP32 v2.0.17
Board: ESP32-S3 DevKitC-1 (default board)
Processor: ESP32-S3
-D ARDUINO_BOARD=Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM) -D ARDUINO_VARIANT=esp32s3
-D ARDUINO=10812
-D ARDUINO_RUNNING_CORE=1
-D ARDUINO_EVENNO_USB_CDC_ON_BOOT=1
CFG: Loading EEPROM - OK
CFG: Loading config - madflight_board loaded OK, madflight_config loaded OK I2C: Scanning i2c_bus:0 - 0x10(16) 0x29(41) 0x40(64) 0x76(118) - Found 4 device(s) LED: RGB
RCL: Channels: roll:1 pitch:2 throttle:3 yaw:4 armed:5 flightmode:6 BAR: BMP280
BAR: BMP280 i2c_adr=0x00 SensorID=0x58
MAG: NONE
BAT: NONE
RDR: NONE
OFL: PMW3901
GPS: NONE
ALT: KALMAN3  altCov=0.200000 accCov=0.010000 biasCov=0.100000 AHR: MAHONY
IMU: BMI270
IMU: , check pin/bus/bus_type config
FATAL ERROR: IMU install failed. - Type 'help' for help...

** With patch **

Arduino library: Arduino-ESP32 v2.0.17
Board: ESP32-S3 DevKitC-1 (default board)
Processor: ESP32-S3
-D ARDUINO_BOARD=Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM) -D ARDUINO_VARIANT=esp32s3
-D ARDUINO=10812
-D ARDUINO_RUNNING_CORE=1
-D ARDUINO_EVENT_RUNNING_CORE=1
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
CFG: Loading EEPROM - OK
CFG: Loading config - madflight_board loaded OK, madflight_config loaded OK I2C: Scanning i2c_bus:0 - 0x10(16) 0x40(64) 0x76(118) - Found 4 device(s) LED: RGB
RCL: NONE - Channels: roll:1 pitch:2 throttle:3 yaw:4 armed:5 flightmode:6 BAR: BMP280
BAR: BMP280 i2c_adr=0x00 SensorID=0x58
MAG: NONE
BAT: NONE
RDR: NONE
OFL: PMW3901
GPS: NONE
ALT: KALMAN3  altCov=0.200000 accCov=0.010000 biasCov=0.100000 AHR: MAHONY
IMU: BMI270
IMU: IMU_EXEC_FREERTOS
AHR: No Magnetometer, yaw:0.00
OUT: idx:gpio:type = 0:G41:Brushed 1:G42:Brushed 2:G10:Brushed 3:G5:Brushed Setup completed, CLI started - Type 'help' for help, or 'diff' to debug

Testing on m5stampfly the BMI270 IMU is not recognized
due to failed who_am_i() returning 255, rather than the ID 0x24.
This problem is caused because who_am_i() is called before
soft reset and SPI toggle.

** Without patch **
Arduino library: Arduino-ESP32 v2.0.17
Board: ESP32-S3 DevKitC-1 (default board)
Processor: ESP32-S3
-D ARDUINO_BOARD=Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)
-D ARDUINO_VARIANT=esp32s3
-D ARDUINO=10812
-D ARDUINO_RUNNING_CORE=1
-D ARDUINO_EVENNO_USB_CDC_ON_BOOT=1
CFG: Loading EEPROM - OK
CFG: Loading config - madflight_board loaded OK, madflight_config loaded OK
I2C: Scanning i2c_bus:0 - 0x10(16) 0x29(41) 0x40(64) 0x76(118) - Found 4 device(s)
LED: RGB
RCL: Channels: roll:1 pitch:2 throttle:3 yaw:4 armed:5 flightmode:6
BAR: BMP280
BAR: BMP280 i2c_adr=0x00 SensorID=0x58
MAG: NONE
BAT: NONE
RDR: NONE
OFL: PMW3901
GPS: NONE
ALT: KALMAN3  altCov=0.200000 accCov=0.010000 biasCov=0.100000
AHR: MAHONY
IMU: BMI270
IMU: , check pin/bus/bus_type config
FATAL ERROR: IMU install failed. - Type 'help' for help...

** With patch **
Arduino library: Arduino-ESP32 v2.0.17
Board: ESP32-S3 DevKitC-1 (default board)
Processor: ESP32-S3
-D ARDUINO_BOARD=Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)
-D ARDUINO_VARIANT=esp32s3
-D ARDUINO=10812
-D ARDUINO_RUNNING_CORE=1
-D ARDUINO_EVENT_RUNNING_CORE=1
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
CFG: Loading EEPROM - OK
CFG: Loading config - madflight_board loaded OK, madflight_config loaded OK
I2C: Scanning i2c_bus:0 - 0x10(16) 0x40(64) 0x76(118) - Found 4 device(s)
LED: RGB
RCL: NONE - Channels: roll:1 pitch:2 throttle:3 yaw:4 armed:5 flightmode:6
BAR: BMP280
BAR: BMP280 i2c_adr=0x00 SensorID=0x58
MAG: NONE
BAT: NONE
RDR: NONE
OFL: PMW3901
GPS: NONE
ALT: KALMAN3  altCov=0.200000 accCov=0.010000 biasCov=0.100000
AHR: MAHONY
IMU: BMI270
IMU: IMU_EXEC_FREERTOS
AHR: No Magnetometer, yaw:0.00
OUT: idx:gpio:type = 0:G41:Brushed 1:G42:Brushed 2:G10:Brushed 3:G5:Brushed
Setup completed, CLI started - Type 'help' for help, or 'diff' to debug
@qqqlab
Copy link
Owner

qqqlab commented Mar 12, 2026

Thanks for this PR.

Does it still work if you move the who_am_i check to immediately before the soft reset?

This way it bails out before writing anything to the IMU sensor, so it doesn't potentially upset a different IMU when using auto-detect.

I recently got a stampfly, but did not get to fly it with mf yet, as you noticed. :-)

I did write a BMM150 mag driver, did you get it to work?

Also, there is still a todo go get both the pmw3901 and bmi270 to work at the same time. They are both on the same spi bus, the current code expects the imu to be the only sensor on the bus...

@tstibor
Copy link
Contributor Author

tstibor commented Mar 12, 2026

I tested moving the who_am_i check immediately before the soft reset and it works. I will update the PR.
Regarding the BMM150 it works but requires another tiny fix:

--- a/src/mag/MagGizmoBMM150.h
+++ b/src/mag/MagGizmoBMM150.h
@@ -25,7 +25,7 @@ class MagGizmoBMM150: public MagGizmo {
 
       //configure sensor
       BMM150_I2C *sensor = new BMM150_I2C(i2c, config->i2c_adr);
-      if(!sensor->begin()) {
+      if(sensor->begin()) {
         Serial.printf("RDR: BMM150 init failed.\n");
         delete sensor;
         return nullptr;

Regarding pmw3901 and bmi270 I didn't test it in detail, but e.g when connecting to BF configurator and moving the quad the rendered BF configurator gltf model for displaying IMU sometimes hangs for some millsecs.

@qqqlab
Copy link
Owner

qqqlab commented Mar 13, 2026

The BMI270 is accessed by a high priority task, which will preempt the low priority PMW3901 sensor task. As the BMI is running at a 10 times higher rate it will sort of work, but really a locking or synchronizing mechanism is needed here. Better disable the PMW for now...

Thanks for the PR and the BMM150 fix, keep those fixes coming!

@qqqlab qqqlab merged commit e5dcee9 into qqqlab:main Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants