Skip to main content
ST Migration account
ST Community Manager
August 22, 2026
Solved

USART2 Handler got overwrited by stai_network_run

  • August 22, 2026
  • 1 reply
  • 13 views

This account only shares restored community content posted by members between May 22 and June 9, 2026, who did not register for the new community.


Dear ST Community, 
I'm trying to integrate my ST Edge AI model C code (generated from ST Edge AI Cloud) to my current application.

- Part Number: STM32F411CE6
- Environment: STM32CubeMX: 6.17; ST Edge AI Core v4.0.0-20500 359356bb0

- Detail of my issue:

   At line 63 below: huart2.Instance = 0x40004400

   After successfully execute stat_network_run() (line 65): huart2.Instance = 0x582cc4de -> This causes Bus Fault to be triggered in line 70. 

   My main function:   

void print_to_uart(UART_HandleTypeDef *huart, const char *format, ...) {
char buffer[256];
int cx;
va_list args;
va_start(args, format);
cx = vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
if (cx >= 0 && cx < (int)(sizeof(buffer))) {
HAL_UART_Transmit(huart, (uint8_t*) buffer, cx, 1000);
} }
// ...
STAI_ALIGNED(STAI_NETWORK_CONTEXT_ALIGNMENT) static stai_network network_context[STAI_NETWORK_CONTEXT_SIZE] = {0};
``
/* Global c-array to handle the activations buffer */
STAI_ALIGNED(STAI_NETWORK_ACTIVATION_1_ALIGNMENT) static uint8_t activations[STAI_NETWORK_ACTIVATION_1_SIZE_BYTES];
``
/* Array to store the data of the input tensor */
STAI_ALIGNED(STAI_NETWORK_IN_1_ALIGNMENT) static int16_t in_data[STAI_NETWORK_IN_1_HEIGHT][STAI_NETWORK_IN_1_CHANNEL];
``
/* c-array to store the data of the output tensor */
STAI_ALIGNED(STAI_NETWORK_OUT_1_ALIGNMENT) static int8_t out_data[STAI_NETWORK_OUT_1_SIZE];
``
/* Array of pointer to manage the model's input/output tensors */
static stai_ptr stai_input[STAI_NETWORK_IN_NUM];
static stai_ptr stai_output[STAI_NETWORK_OUT_NUM];
``
/* Simple rounding helper */
static inline int32_t stai_roundf(float v) {
return (int32_t)(v + (v >= 0.0f ? 0.5f : -0.5f));
}
``
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
print_to_uart(&huart2, "rn-- Application started --rn");
``
stai_return_code ret;
``
/* 1. Init library */
/* Init runtime */
ret = stai_runtime_init();
if (ret != STAI_SUCCESS) { }
``
/* Init network context */
ret = stai_network_init(network_context);
if (ret != STAI_SUCCESS) { }
``
/* Mapping activation buffer */
const stai_ptr acts[] = {activations}; // acts[0] points to activations[0]
ret = stai_network_set_activations(network_context, acts, STAI_NETWORK_ACTIVATIONS_NUM); // set activation buffer addr to context
if (ret != STAI_SUCCESS) { }
``
/* Quantize the input from float to int16 */
/* q = round(x / scale) + zero_point */
for (int i = 0; i < STAI_NETWORK_IN_1_HEIGHT; i++) {
for (int j = 0; j < STAI_NETWORK_IN_1_CHANNEL; j++) {
in_data[i][j] = (int16_t)0;
}
}
``
/* 2. Inference */
/* Set network input/output buffers */
const stai_ptr inputs_ptr[] = {(stai_ptr)&in_data[0][0]};
ret = stai_network_set_inputs(network_context, inputs_ptr, STAI_NETWORK_IN_NUM);
if (ret != STAI_SUCCESS) { }
``
const stai_ptr outputs_ptr[] = {(stai_ptr)out_data};
ret = stai_network_set_outputs(network_context, outputs_ptr, STAI_NETWORK_OUT_NUM);
if (ret != STAI_SUCCESS) { }
``
print_to_uart(&huart2, "Before inferencern");
``
/* Perform the inference. The issue is happeninng here */
ret = stai_network_run(network_context, STAI_MODE_SYNC);
if (ret != STAI_SUCCESS) {
ret = stai_network_get_error(network_context);
print_to_uart(&huart2, "Errorrn");
}
``
print_to_uart(&huart2, "Perform inference DONErn");
}

- Occurence: Every time

Can you please let me know any debugging suggestion in this case? 

Thank you very much for your help.

-- 

Ps: I tried increased _Min_Stack_Size in the linker script, however, it looks like the problem didn't come from stack size. 

Best answer by ST Migration account

Problem solved.

I found out that the out_data didn't matched the model specification, it should be int16_t.

 

1 reply

ST Migration account
ST Migration accountAuthorBest answer
ST Community Manager
August 22, 2026

Problem solved.

I found out that the out_data didn't matched the model specification, it should be int16_t.

 

This account only shares restored community content posted by members between May 22 and June 9, 2026, who did not register for the new community.