What causes HardFault_Handler errors and inaccurate predictions in STM32 air quality monitoring Sys?
I'm developing an air quality monitoring system on an
STM32F746
using TinyML
. The system uses a temperature, humidity, and gas sensor to predict the Air Quality Index (AQI) via a model I trained and deployed. While the code works, I sometimes get inaccurate predictions, and occasionally, the STM32 throws a HardFault_Handler
error.
Here’s the simplified inference code:
Could the hard fault be caused by memory issues or model size? How can I resolve the crash and improve prediction consistency?2 Replies
https://community.st.com/t5/stm32-mcus/how-to-debug-a-hardfault-on-an-arm-cortex-m-stm32/ta-p/672235
How to debug a HardFault on an Arm Cortex®-M STM32
Introduction For a firmware developer targeting and STM32 MCU based on a Cortex® M, they need to keep an eye on memory access, hardware availability, clock, and power to avoid running into issues that can be hard to follow and determine their root cause. Nevertheless, we can all at the end run into...
Your STM32 may optimize away changes to variables when there is inference. Declaring your
input_data
and output_data
arrays as volatile ensures that their values are properly updated during inference
volatile float input_data[3];
volatile float output_data[1];