STM32Duino: ICM‑20948 & ICP201xx init() hang in FreeRTOS; works bare-metal
Hello,
I’m using an STM32H562RGT6‑based board with a built‑in ICM‑20948 IMU and ICP201xx pressure sensor. When I run bare‑metal code (no RTOS) the I2C communication with both sensors works fine and I can read data. However, as soon as I enable FreeRTOS (Arduino core), the program prints “Initializing IMU...” and then stalls inside myIMU.init() (similarly ICP.init() stalls if I try that). In bare‑metal the same init completes and data is available.
What I’ve observed and tried
- I2C scanner (bare‑metal): devices found at 0x64 (ICP) and 0x69 (ICM).
- Minimal bare-metal IMU example: init() returns true and I get accelerometer values.
- With FreeRTOS: prints "Initializing IMU..." and never reaches "ICM20948 connected." or the error print.
- I tried:
- Creating IMU with explicit Wire pointer: ICM20948_WE myIMU(&Wire, 0x69);
- Configuring Wire.setSDA / setSCL / begin before init
- Moving init() into an RTOS task after scheduler start
- Reducing task stack sizes
- Checking heap with xPortGetFreeHeapSize().
this code (FreeRTOS + IMU init — this hangs at init)
I'm using MCU core: Arduino STM32 core
#include <STM32FreeRTOS.h>
#include <Wire.h>
#include <ICM20948_WE.h>
#define ICM_ADDR 0x69
ICM20948_WE myIMU(&Wire, ICM_ADDR);
void setup() {
Serial.begin(115200); while (!Serial) {}
Wire.setSDA(PB12); Wire.setSCL(PB10); Wire.begin(); Wire.setClock(400000);
Serial.println("Initializing IMU...");
if (!myIMU.init()) {
Serial.println("ICM20948 not responding!");
while (1) delay(1000);
}
Serial.println("ICM20948 connected.");
vTaskStartScheduler();
}
void loop() {}code (bare-metal, no FreeRTOS — works):
#include <Wire.h>
#include <ICM20948_WE.h>
#define ICM_ADDR 0x69
ICM20948_WE myIMU(&Wire, ICM_ADDR);
void setup() {
Serial.begin(115200); while (!Serial) {}
Wire.setSDA(PB12); Wire.setSCL(PB10); Wire.begin(); Wire.setClock(400000);
Serial.println("Initializing IMU...");
if (!myIMU.init()) {
Serial.println("ICM20948 not responding!");
while (1) delay(1000);
}
Serial.println("ICM20948 connected.");
}
void loop() {}References
- ST Community thread with similar symptoms: https://community.st.com/t5/stm32-mcus-embedded-software/stm32f103c8t6-icm20948-imu-not-detected-when-using-freertos-with/td-p/811570
what could be the cause for halt ?
Edited to apply source code formatting - please see How to insert source code for future reference.
