2022-06-30 10:26 PM
Hi,
I created my own model and tried to import it into the STM32L476 MCU.
When I execute the ai_network_run( ) function, I got the hard fault interrupt.
Here is the function below.
( I refered the code from here :
https://wiki.st.com/stm32mcu/wiki/AI:How_to_perform_motion_sensing_on_STM32L4_IoTnode)
static void AI_Run(float *pIn, float *pOut)
{
ai_i32 batch;
ai_error err;
/* Update IO handlers with the data payload */
ai_input[0].data = AI_HANDLE_PTR(pIn);
ai_output[0].data = AI_HANDLE_PTR(pOut);
batch = ai_network_run(network, ai_input, ai_output);
if (batch != 1)
{
err = ai_network_get_error(network);
printf("AI ai_network_run error - type=%d code=%d\r\n", err.type, err.code);
Error_Handler();
}
}
I have checked the 'ai_input' and 'ai_output' values and they all pointed well.
Here is the main loop.
while (1)
{
AccelReadValues(0x32, 6);
x = ((AccelData[1] << 8) | AccelData[0]);
y = ((AccelData[3] << 8) | AccelData[2]);
z = ((AccelData[5] << 8) | AccelData[4]);
ACC_Value_Raw.AccX = (x * .039);
ACC_Value_Raw.AccY = (y * .039);
ACC_Value_Raw.AccZ = (z * .039);
HAL_Delay(50);
aiInData[write_index++] = ACC_Value_Raw.AccX;
aiInData[write_index++] = ACC_Value_Raw.AccY;
aiInData[write_index++] = ACC_Value_Raw.AccZ;
// AI_NETWORK_IN_1_SIZE = (24 * 3 * 1)
if (write_index >= AI_NETWORK_IN_1_SIZE)
{
printf("Running inference\r\n");
AI_Run(aiInData, aiOutData);
/* Output results */
for (uint32_t i = 0; i < AI_NETWORK_OUT_1_SIZE; i++)
{
printf("%8.6f ", aiOutData[i]);
}
uint32_t class = argmax(aiOutData, AI_NETWORK_OUT_1_SIZE);
printf(": %d - %s\r\n", (int) class, activities[class]);
write_index = 0;
}
//MX_X_CUBE_AI_Process();
}
I read the X, Y, and Z of the accelerometer sensor data.
Do you have any ideas on how I could handle this situation?
Thanks,
2022-07-07 04:13 PM
Okay, Here is my AI_Init and AI_Run function.
I didn't modify any code from the WIKI page.
static void AI_Init(void)
{
ai_error err;
/* Create a local array with the addresses of the activations buffers */
const ai_handle act_addr[] = { activations };
/* Create an instance of the model */
err = ai_network_create_and_init(&network, act_addr, NULL);
if (err.type != AI_ERROR_NONE) {
printf("ai_network_create error - type=%d code=%d\r\n", err.type, err.code);
Error_Handler();
}
ai_input = ai_network_inputs_get(network, NULL);
ai_output = ai_network_outputs_get(network, NULL);
}
static void AI_Run(float *pIn, float *pOut)
{
ai_i32 batch;
ai_error err;
/* Update IO handlers with the data payload */
ai_input[0].data = AI_HANDLE_PTR(pIn);
ai_output[0].data = AI_HANDLE_PTR(pOut);
printf("------------------\n");
batch = ai_network_run(network, ai_input, ai_output);
printf("a----------------\n");
if (batch != 1) {
err = ai_network_get_error(network);
printf("AI ai_network_run error - type=%d code=%d\r\n", err.type, err.code);
Error_Handler();
}
}
2022-07-19 12:01 AM
Hello
I have implemented the wiki on a set up as close as yours : Nucleo-L476RG + IKS01A3 with the LSM6DS0 accelerometer
and all run fine without any hardfault ...
by the way, did you try to run the provided model in the wiki (https://github.com/STMicroelectronics/stm32ai/raw/master/AI_resources/HAR/model.h5) ?
best regards
L.
2022-07-19 01:33 AM
Also, one question, in your main , do you initialize the AI twice ?
...
MX_X_CUBE_AI_Init();
AccelInit();
AI_Init();
...
I think that MX_X_CUBE_AI_Init() is code generated for application template ... but you are using AI_Init() provided by the wiki.