2025-10-23 3:38 AM - last edited on 2025-10-23 4:26 AM by Andrew Neil
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
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
what could be the cause for halt ?
Edited to apply source code formatting - please see How to insert source code for future reference.
2025-10-23 4:25 AM
@Devirajkumar17 wrote:I'm using MCU core: Arduino STM32 core.
STM32Duino questions should go here: https://www.stm32duino.com/
General Arduino questions here: https://forum.arduino.cc/
@Devirajkumar17 wrote: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
That's not using Arduino.
Getting Arduino working with FreeRTOS (or any other RTOS) is going to be an issue on its own!
Search for specific tutorials on that!