cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Duino: ICM‑20948 & ICP201xx init() hang in FreeRTOS; works bare-metal

Devirajkumar17
Associate

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

what could be the cause for halt ?


Edited to apply source code formatting - please see How to insert source code for future reference.

1 REPLY 1
Andrew Neil
Super User

@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


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!

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.