wafa_ath
wafa_ath
DIIDevHeads IoT Integration Server
Created by wafa_ath on 9/27/2024 in #firmware-and-baremetal
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:
#include "main.h"
#include "stm32f7xx_hal.h"
#include "tinyml_model.h"

float input_data[3];
float output_data[1];

float read_temperature() { return 25.0; }
float read_humidity() { return 60.0; }
float read_gas_level() { return 150.0; }

int main(void) {
HAL_Init();
SystemClock_Config();

while (1) {
input_data[0] = read_temperature();
input_data[1] = read_humidity();
input_data[2] = read_gas_level();

if (predict_air_quality(input_data, output_data) != 0) {
printf("Inference error\n");
} else {
printf("Predicted AQI: %.2f\n", output_data[0]);
}

HAL_Delay(1000);
}
}
#include "main.h"
#include "stm32f7xx_hal.h"
#include "tinyml_model.h"

float input_data[3];
float output_data[1];

float read_temperature() { return 25.0; }
float read_humidity() { return 60.0; }
float read_gas_level() { return 150.0; }

int main(void) {
HAL_Init();
SystemClock_Config();

while (1) {
input_data[0] = read_temperature();
input_data[1] = read_humidity();
input_data[2] = read_gas_level();

if (predict_air_quality(input_data, output_data) != 0) {
printf("Inference error\n");
} else {
printf("Predicted AQI: %.2f\n", output_data[0]);
}

HAL_Delay(1000);
}
}
Could the hard fault be caused by memory issues or model size? How can I resolve the crash and improve prediction consistency?
3 replies