Skip to main content
Associate III
July 22, 2026
Question

Problems running relocatable ai model

  • July 22, 2026
  • 0 replies
  • 5 views

hi all,

 

I am trying to flash + run a relocatable / runtime loadable model.

 

The problem is that the inference results are wrong (they never change, no matter what the buffer contains when I start the inference). If I use the stai_model files from the AI Cube Studio, the model works correctly, but is not relocatable…

 

stedgeai.exe generate -m "path/to/model.tflite" --input-data-type uint8 --no-inputs-allocation --no-outputs-allocation --target stm32n6 --st-neural-art --reloc

# final output something like this:

+--------------------------+-------------------------------+------+------------+--------+
| name (addr) | flags | foff | dst | size |
+--------------------------+-------------------------------+------+------------+--------+
| xSPI2 (0x20009332) | 0x02010500 COPY.PARAM.RCACHED | 0 | 0x72000000 | 984321 |
| AXISRAM5 (0x20009338) | 0x03020200 RESET.ACTIV.WRITE | 0 | 0x342e0000 | 409600 |
| AXISRAM4 (0x20009341) | 0x03020200 RESET.ACTIV.WRITE | 0 | 0x34270000 | 196608 |
| <undefined> (0x00000000) | 0x00000000 UNUSED | 0 | 0x00000000 | 0 |
+--------------------------+-------------------------------+------+------------+--------+

 

I try to run the inference as such:


uint32_t ai_run(uint32_t buf) {

LL_ATON_RT_RetValues_t ll_aton_ret;
LL_ATON_RT_Reset_Network(&nn_instance);

LL_ATON_Set_User_Input_Buffer(&nn_instance, 0, buf, BUF_SIZE);
LL_ATON_Cache_MCU_Clean_Invalidate_Range(buf, BUF_SIZE);

do {
ll_aton_ret = LL_ATON_RT_RunEpochBlock(&nn_instance);
/* do NOT wait for event (WFE) as it blocks all other things, potentially corrupting i2c communication.. */
#if 0
if (ll_aton_ret == LL_ATON_RT_WFE) {
LL_ATON_OSAL_WFE();
}
#endif
} while (ll_aton_ret != LL_ATON_RT_DONE);

LL_ATON_Cache_MCU_Invalidate_Range(g_npu_out_buf, g_npu_out_len);
return 0;
}

 

And I try to load the model as follows:


int ai_init(const uintptr_t file_ptr) {

ll_aton_reloc_info rt;
int res;

/* Retrieve the requested RAM size to install the model */
res = ll_aton_reloc_get_info(file_ptr, &rt);

/* Reserve executable memory region to install the model */
uintptr_t exec_ram_addr = (uint32_t)malloc(rt.rt_ram_copy + 0x1f) & ~0x1f;
assert_param(rt.ext_ram_sz == 0);

/* Create and install an instance of the relocatable model */
ll_aton_reloc_config config;
config.exec_ram_addr = exec_ram_addr;
config.exec_ram_size = rt.rt_ram_copy;
config.ext_ram_addr = 0;
config.ext_ram_size = rt.ext_ram_sz;
config.ext_param_addr = NULL;
config.mode = AI_RELOC_RT_LOAD_MODE_COPY; // | AI_RELOC_RT_LOAD_MODE_CLEAR;

res = ll_aton_reloc_install(file_ptr, &config, &nn_instance);
if (res != 0) {
Error_Handler();
}

/* Init the LL ATON stack and the instantiated model */
LL_ATON_RT_RuntimeInit();
LL_ATON_RT_Init_Network(&nn_instance);

LL_Buffer_InfoTypeDef *bufout = ll_aton_reloc_get_output_buffers_info(&nn_instance, 0);

g_npu_out_len = LL_Buffer_len(bufout);
g_npu_out_buf = (uint32_t)malloc(g_npu_out_len + 0x1f) & ~0x1f;
res = ll_aton_reloc_set_output(&nn_instance, 0, g_npu_out_buf, g_npu_out_len);
if (res != 0) {
Error_Handler();
}

assert_param(ll_aton_reloc_is_valid(&nn_instance));

return res;

}

 

does anyone know what I might be doing wrong?

 

best regards, rphii