cancel
Showing results for 
Search instead for 
Did you mean: 

Problems generating ONNX model with ST Edge AI for Nucleo-N657X0-Q

Dresult
Associate III

Hi everyone,
I'm having trouble generating a project to run an AI model on the Nucleo-N657X0-Q board.

I open STM32CubeMX version 6.14.1, select the board, choose "Secured Application", and then when I select the X-CUBE-AI package, it asks for the ZIP file available here:
https://www.st.com/en/development-tools/stedgeai-core.html?ecmp=tt9470_gl_link_feb2019&rt=db&id=DB4255

I download it, choose to use X-CUBE-AI in the Application domain, and when I try to select the ONNX model, it asks whether I want to optimize peripherals and clock. At this point, whether I click "Yes" or "No", CubeMX freezes indefinitely.

I’ve already tried using CubeMX version 6.13 as well, but it didn’t help.

My suspicion is that the problem might be related to the version of ST Edge AI. Version 2.1 on the ST Edge AI Developer Cloud throws an error during optimization (although maybe it's unrelated). Also, when selecting the package ZIP file, the dialog only shows folders, not ZIP files. I have to manually navigate to the directory and enter the ZIP file name in the dialog box to select it. However, I can't try older versions as I can't download them from the website.

Is there any way to fix this issue ?

 

N.B. I am working on Windows 11. However, I have the problems also on a Ubuntu system. I am attaching the resulting log file if it could be of help.

9 REPLIES 9
Julian E.
ST Employee

Hello @Dresult,

 

I don't really understand why it asks for the zip when you select X Cube AI?

 

The version 10.1.0 of X Cube AI is out, do you have it installed? Maybe, if you only have the 10.0.0 it creates strange behavior?

Could you try to install the version 10.1.0 from the main page of CubeMX and try again? I cannot reproduce your behavior.

JulianE_0-1747829957353.png

 

You may have to try uninstalling every version of the X Cube AI inside CubeMX to see if it helps.

 

Have a good day

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi @Julian E., thank you very much for your reply!

I've updated to version 10.1.0, however, if I make a new project and try to use X-CUBE-AI I still get CubeMX freezing. A temporary solution I am exploiting is using the XIP template from this GitHub repository: https://github.com/stm32-hotspot/STM32N6_FSBL_Modes/tree/main

With that, when I am asked if I want to set the clock and peripherals for improved peformance everything works smoothly.

On the other hand, there is an issue when trying to compile for the Neural-ART: when I try to analyze the model, I get an error with the following output:

Analyzing model 
C:/Users/windows/STM32Cube/Repository//Packs/STMicroelectronics/X-CUBE-AI/10.1.0/Utilities/windows/stedgeai.exe analyze --target stm32n6 --name network -m C:/Users/windows/Downloads/model_cr4_PTQquantized_QDQ.onnx --st-neural-art n6-allmems-O1@C:/Users/windows/STM32Cube/Repository//Packs/STMicroelectronics/X-CUBE-AI/10.1.0/scripts/N6_scripts/user_neuralart.json --workspace C:/Users/windows/AppData/Local/Temp/mxAI_workspace11903257383180013050355192454087222 --output C:/Users/windows/.stm32cubemx/network_output 
ST Edge AI Core v2.1.0-20194 329b0e98d 
WARNING: Unsupported keys in the current profile n6-allmems-O1 are ignored: memory_desc 
 > memory_desc is not a valid key anymore, use machine_desc instead 
 >>>> EXECUTING NEURAL ART COMPILER 
   C:/Users/windows/STM32Cube/Repository/Packs/STMicroelectronics/X-CUBE-AI/10.1.0/Utilities/windows/atonn.exe -i "C:/Users/windows/.stm32cubemx/network_output/model_cr4_PTQquantized_QDQ_OE_3_2_0.onnx" --json-quant-file "C:/Users/windows/.stm32cubemx/network_output/model_cr4_PTQquantized_QDQ_OE_3_2_0_Q.json" -g "network.c" --load-mdesc "C:/Users/windows/STM32Cube/Repository/Packs/STMicroelectronics/X-CUBE-AI/10.1.0/Utilities/configs/stm32n6.mdesc" --load-mpool "C:/Users/windows/STM32Cube/Repository/Packs/STMicroelectronics/X-CUBE-AI/10.1.0/scripts/N6_scripts/my_mpools/stm32n6.mpool" --save-mpool-file "C:/Users/windows/AppData/Local/Temp/mxAI_workspace11903257383180013050355192454087222/neural_art__network/stm32n6.mpool" --out-dir-prefix "C:/Users/windows/AppData/Local/Temp/mxAI_workspace11903257383180013050355192454087222/neural_art__network/" --optimization 1 --all-buffers-info --mvei --cache-maintenance --Oauto-sched --native-float --enable-virtual-mem-pools --Omax-ca-pipe 4 --Ocache-opt --Os --output-info-file "c_info.json" 
    
      >>> Shell execution has FAILED (returned code = 255) 
      $ C:\Users\windows\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\10.1.0\Utilities\windows\atonn.exe -i C:\Users\windows\.stm32cubemx\network_output\model_cr4_PTQquantized_QDQ_OE_3_2_0.onnx --json-quant-file C:\Users\windows\.stm32cubemx\network_output\model_cr4_PTQquantized_QDQ_OE_3_2_0_Q.json -g network.c --load-mdesc C:\Users\windows\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\10.1.0\Utilities\configs\stm32n6.mdesc --load-mpool C:\Users\windows\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\10.1.0\scripts\N6_scripts\my_mpools\stm32n6.mpool --save-mpool-file C:\Users\windows\AppData\Local\Temp\mxAI_workspace11903257383180013050355192454087222\neural_art__network\stm32n6.mpool --out-dir-prefix C:\Users\windows\AppData\Local\Temp\mxAI_workspace11903257383180013050355192454087222\neural_art__network/ --optimization 1 --all-buffers-info --mvei --cache-maintenance --Oauto-sched --native-float --enable-virtual-mem-pools --Omax-ca-pipe 4 --Ocache-opt --Os --output-info-file c_info.json 
      assertion "pool != nullptr" failed: file "/c/local/jenkins_cloud/workspace/2-STEDGEAI_BuildAtonnExe_Win/git/onnx_backend/include/live_range.hpp", line 314, function: const mem_pool_desc* live_range::get_mem_pool() const 
      saving memory pool description "C:/Users/windows/AppData/Local/Temp/mxAI_workspace11903257383180013050355192454087222/neural_art__network/stm32n6.mpool" 
       Internal compiler error (signo=6), please report it 
      <<< 
    
   E103(CliRuntimeError): Error calling the Neural Art compiler - ['', 'assertion "pool != nullptr" failed: file "/c/local/jenkins_cloud/workspace/2-STEDGEAI_BuildAtonnExe_Win/git/onnx_backend/include/live_range.hpp", line 314, function: const mem_pool_desc* live_range::get_mem_pool() const', 'saving memory pool description "C:/Users/windows/AppData/Local/Temp/mxAI_workspace11903257383180013050355192454087222/neural_art__network/stm32n6.mpool"', '', ' Internal compiler error (signo=6), please report it']

This happens using profile n6-allmems-O1, but similar error also appears with other profiles.

It seems related to the ST Edge AI version. Indeed, using version 2.1.0 I get the same error even on ST Edge AI Developer Cloud for the STM32N657-DK. There, if I switch back to 2.0.0 it compiles the model correctly.

No problems when compiling for the MCU runtime (apart from the problem described here that seems related to the xspi memory clock: https://community.st.com/t5/edge-ai/unable-to-run-application-on-nucleo-n657x0-q-via-stm32cubeide/td-p/802137)

UPDATE:

I was able to "temporaly" correct the problem above. I attach the file .ioc I am using.

Briefly as the error says, in 

C:/Users/windows/STM32Cube/Repository//Packs/STMicroelectronics/X-CUBE-AI/10.1.0/scripts/N6_scripts/user_neuralart.json

I changed all the occurrences for memory_desc to machine_desc and then adjusted the path to point to ../my_mdescs/.

At first I was able to compile my model for the Neural-ART. However, now I still get error from the compiler because seems to not see any memory pool...

I have also noticed that using CUBE-AI version 10.0.0 and the MCU runtime (so, no accelerator), my model run on average in 400 ms, with version 10.1.0 in about 1370 ms...

 

@Julian E. would it be possible to get the old zip file to enable Neural-ART with CUBE-AI version 10.0.0 ? It is no longer available on the site...

Hello @Dresult 

 

The .raw generated contains your models' weights and fixed parameters that will further be used for inference. Using CubeProgrammer, you cannot directly flash this kind of file. You first need to convert it either to .bin and then specify the download address when flashing or to .hex and then specifiy the download address in the conversion command.

 

The point in memory where you'll download it must be set accordingly to the address specified on your memory pool. You can access your memory pool on X-CUBE-AI Advanced Settings. Go on to your network and click on the blue icon just above "Show graph" then click on "Memory pool". You'll see that the starting address of the external flash (octoFlash) is by default 0x70000000. Therefore, the middleware by default generates an application code that refers to the weights starting in this position. However, this is the address where your FSBL is also downloaded. So, you have to change in order not to overwrite the FSBL.

 

The memory pool configuration file is in the ST Edge AI Neural ART package. This package may be located in two different places depending on how you've downloaded it: it is either on your X-CUBE-AI path (C:\Users\<Your user>\STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-AI\10.0.0\scripts\N6\_scripts\my\_mpools) or on your ST Edge AI path (C:\ST\STEdgeAI\2.0\scripts\N6\_scripts\my\_mpools). The file used by default in the model image generation is stm32n6.mpool. In this file, you can confirm that the OctoFlash is mapped to begin at 0x70000000 and you have to change it to another address that doesn't conflic with neither FSBL or Appli. So you can for example, set the OctoFlash starting address to 0x70380000. And then you download the image at this address.

 

After modifying the memory pool, rebuild your project. Your network application code should now refer to this new address you set.

 

Moreover, in case your generated model weights image is invalid for whatever reason, you can generate it directly with ST Edge AI Core. You can do such following the step-by-step:

 

To generate your model binary image, you have to go through the following step-by-step.

 

    - Add ST Edge AI windows installation folder on your enviromment variables path. Normally, your installation path by default is either C:/ST/STEdge AI/ 2.0/Utilities/windows or C:/Users/<your_user>/STM32Cube/Repository/Packs/STMicroelectronics/X-CUBE-AI/<Version>/Utilities/windows.
    Go to ST Edge AI "N6_scripts" folder. Add your model on "models" folder.
    Execute the following generate command.

 

        stedgeai generate --model Model_File.tflite --target
        stm32n6 --st-neural-art default@user_neuralart.json

 

    - Two new folders were generated. st_ai_output contains the raw image. The file format must be modified to .bin. So copy it to the and change its format. You can use the following command.

 

        cp .\st_ai_output\network_atonbuf.xSPI2.raw network_
        data.xSPI2.bin

 

    - Now you should also add arm-none-eabi-objcopy path to your enviromment variables path. You can find it in your STM32CubeIDE installation folder, which is likely C:/ST/STM32CubeIDE_<Version>/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin. This command allows you to modify your generated .bin file into a .hex whose flash address is already specified.

 

        arm-none-eabi-objcopy -I binary network_data.xSPI2.bin
        --change-addresses 0x70380000 -O ihex network_data.he

 

Have a good day,

Julian

 


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

The problem is that even if I wanted to use the stedgeai command outside of CubeMX I still get the same error as before, so I was asking if it was possible to get the extension to enable Neural-ART with CUBE-AI 10.0.0 (I can't find it on the site anymore). There I am sure that the onnx model is filled in.

 

C:\ST\STEdgeAI\2.1\Utilities\windows>stedgeai generate --model C:\Users\windows\Desktop\test_p\mod_sigm.onnx --target stm32n6 --st-neural-art profile_O3@C:\ST\STEdgeAI\2.1\scripts\N6_scripts\user_neuralart.json
ST Edge AI Core v2.1.0-20194 329b0e98d
 >>>> EXECUTING NEURAL ART COMPILER
   C:/ST/STEdgeAI/2.1/Utilities/windows/atonn.exe -i "C:/ST/STEdgeAI/2.1/Utilities/windows/st_ai_output/mod_sigm_OE_3_2_0.onnx" --json-quant-file "C:/ST/STEdgeAI/2.1/Utilities/windows/st_ai_output/mod_sigm_OE_3_2_0_Q.json" -g "network.c" --load-mdesc "C:/ST/STEdgeAI/2.1/scripts/N6_scripts/my_mdescs/stm32n6.mdesc" --load-mpool "C:/ST/STEdgeAI/2.1/scripts/N6_scripts/my_mpools/stm32n6.mpool" --save-mpool-file "C:/ST/STEdgeAI/2.1/Utilities/windows/st_ai_ws/neural_art__network/stm32n6.mpool" --out-dir-prefix "C:/ST/STEdgeAI/2.1/Utilities/windows/st_ai_ws/neural_art__network/" -O3 --all-buffers-info --mvei --cache-maintenance --Oauto-sched --native-float --enable-virtual-mem-pools --Omax-ca-pipe 4 --Ocache-opt --Os --csv-file "aton_csv.csv" --output-info-file "c_info.json"

      >>> Shell execution has FAILED (returned code = 255)
      $ C:\ST\STEdgeAI\2.1\Utilities\windows\atonn.exe -i C:\ST\STEdgeAI\2.1\Utilities\windows\st_ai_output\mod_sigm_OE_3_2_0.onnx --json-quant-file C:\ST\STEdgeAI\2.1\Utilities\windows\st_ai_output\mod_sigm_OE_3_2_0_Q.json -g network.c --load-mdesc C:\ST\STEdgeAI\2.1\scripts\N6_scripts\my_mdescs\stm32n6.mdesc --load-mpool C:\ST\STEdgeAI\2.1\scripts\N6_scripts\my_mpools\stm32n6.mpool --save-mpool-file C:\ST\STEdgeAI\2.1\Utilities\windows\st_ai_ws\neural_art__network\stm32n6.mpool --out-dir-prefix C:\ST\STEdgeAI\2.1\Utilities\windows\st_ai_ws\neural_art__network/ -O3 --all-buffers-info --mvei --cache-maintenance --Oauto-sched --native-float --enable-virtual-mem-pools --Omax-ca-pipe 4 --Ocache-opt --Os --csv-file aton_csv.csv --output-info-file c_info.json

      assertion "pool != nullptr" failed: file "/c/local/jenkins_cloud/workspace/2-STEDGEAI_BuildAtonnExe_Win/git/onnx_backend/include/live_range.hpp", line 314, function: const mem_pool_desc* live_range::get_mem_pool() const
      saving memory pool description "C:/ST/STEdgeAI/2.1/Utilities/windows/st_ai_ws/neural_art__network/stm32n6.mpool"
       Internal compiler error (signo=6), please report it
      <<<

   E103(CliRuntimeError): Error calling the Neural Art compiler - ['', 'assertion "pool != nullptr" failed: file "/c/local/jenkins_cloud/workspace/2-STEDGEAI_BuildAtonnExe_Win/git/onnx_backend/include/live_range.hpp", line 314, function: const mem_pool_desc* live_range::get_mem_pool() const', 'saving memory pool description "C:/ST/STEdgeAI/2.1/Utilities/windows/st_ai_ws/neural_art__network/stm32n6.mpool"', '', ' Internal compiler error (signo=6), please report it']

 

It seems related to an issue with the ONNX backend used in this new version of ST Edge AI as I am able to compile tflite models...

Hello @Dresult,

 

Indeed, the NPU addon does not exist anymore on st.com.
I am waiting for more information about that.

Could you send me you user_neuralart.json and the memory pool file corresponding to the profile_O3 that you are using (probably stm32n6.mpool). Your error is quite strange and seems related to that more than your model.

Have a good day,

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Absolutely! I'm attanching the three files involved.

However, my opinion is that the problem derives from the ONNX backend used in version 2.1.0 as tflite models seems to be generated without problems.

Thanks

 

We are looking at how to handle the zip issue, but I attached it here for you to use it in the meantime

 

Have a good day,

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi @Julian E. , thanks a lot for the zip file.

Now I am able to generate the model both from the command line and from CubeMX.

I tried to generate the project (starting from changing the xSPI2 address to 0x7100000), but when I tried to compile it from STM32CubeIDE I encountered the same error here https://community.st.com/t5/edge-ai/not-able-to-build-the-generated-c-code-from-developer-zone-in/td-p/794225. I tried to overcome by copying ai_io_buffers_ATON.c/.h from a previous trial (I attach to the post in case they could be useful) and also network.h which is not generated. The model compiles. I signed bot the Application and the FSBL and generated the hex file as you specified above: I renamed C:\Users\windows\.stm32cubemx\network_output\network_atonbuf.xSPI2.raw in *.bin and then I executed the command 

arm-none-eabi-objcopy.exe -I binary C:\Users\windows\Desktop\testnet2\network_atonbuf.xSPI2.bin --change-address 0x71000000 -O ihex C:\Users\windows\Desktop\testnet2\network_data.hex

Finally, I programmed the board with the resulting three files: at 0x70000000 the FSBL, then at 0x70100000 the Application (as specified in the extmem_manager) and finally the network parameters at 0x71000000.

From TeraTerm I can see that the validation process starts and waits for inputs but when I try to perform the validation on target from CubeMX it reaches a read timeout as follows:

Starting AI validation on target with random data... 
C:/Users/windows/STM32Cube/Repository/Packs/STMicroelectronics/X-CUBE-AI/10.0.0/Utilities/windows/stedgeai.exe validate --target stm32n6 --name network -m C:/Users/windows/Desktop/test_p/mod_sigm.onnx --st-neural-art profile_O3@C:/Users/windows/STM32Cube/Repository/Packs/STMicroelectronics/X-CUBE-AI/10.0.0/scripts/N6_scripts/user_neuralart.json --workspace C:/Users/windows/AppData/Local/Temp/mxAI_workspace29169355158650015189582760084844989 --output C:/Users/windows/.stm32cubemx/network_output --mode target --desc serial:209700 
ST Edge AI Core v2.0.0-20049 
Setting validation data... 
 generating random data, size=10, seed=42, range=(0, 1) 
   I[1]: (10, 4096, 1, 1)/float32, min/max=[-0.690983, 0.643777], mean/std=[-0.024376, 0.384810] 
    c/I[1] conversion [Q(0.00523477,4)]-> (10, 4096, 1, 1)/int8, min/max=[-128, 127], mean/std=[-0.657275, 73.511188] 
    m/I[1] no modification. 
 no output/reference samples are provided 
Creating c (debug) info json file C:\Users\windows\AppData\Local\Temp\mxAI_workspace29169355158650015189582760084844989\network_c_info.json 
  
 Exec/report summary (validate) 
 --------------------------------------------------------------------------------------------------------------- 
 model file         :   C:\Users\windows\Desktop\test_p\mod_sigm.onnx                                            
 type               :   onnx                                                                                     
 c_name             :   network                                                                                  
 options            :   allocate-inputs, allocate-outputs                                                        
 optimization       :   balanced                                                                                 
 target/series      :   stm32n6npu                                                                               
 workspace dir      :   C:\Users\windows\AppData\Local\Temp\mxAI_workspace29169355158650015189582760084844989    
 output dir         :   C:\Users\windows\.stm32cubemx\network_output                                             
 model_fmt          :   ss/sa per channel                                                                        
 model_name         :   mod_sigm                                                                                 
 model_hash         :   0x6570c3427d14e68d2310ac1f26943ae0                                                       
 params #           :   1,100,385 items (4.20 MiB)                                                               
 --------------------------------------------------------------------------------------------------------------- 
 input 1/1          :   'input', int8(1x4096x1), 4.00 KBytes, QLinear(0.005234772,4,int8), activations           
 output 1/1         :   'output_sigmoid', f32(1x1), 4 Bytes, activations                                         
 macc               :   266,985,533                                                                              
 weights (ro)       :   1,104,120 B (1078.24 KiB) (1 segment) / -3,297,420(-74.9%) vs float model                
 activations (rw)   :   112,648 B (110.01 KiB) (1 segment) *                                                     
 ram (total)        :   112,648 B (110.01 KiB) = 112,648 + 0 + 0                                                 
 --------------------------------------------------------------------------------------------------------------- 
 (*) 'input'/'output' buffers can be used from the activations buffer 
Running the ONNX model... 
Running the ST.AI c-model (AI RUNNER)...(name=network, mode=TARGET) 
 Proto-buffer driver v2.0 (msg v3.1) (Serial driver v1.0 - COM3:209700) ['network'] 
  Summary 'network' - ['network'] 
  --------------------------------------------------------------------------------------------------------- 
  I[1/1] 'Input_0_out_0'      :   int8[1,4096,1], 4096 Bytes, QLinear(0.005234772,4,int8), activations 
  O[1/1] 'Sigmoid_35_out_0'   :   f32[1,1], 4 Bytes, activations 
  n_nodes                     :   34 
  activations                 :   1012656 
  compile_datetime            :   May 23 2025 16:49:08 
  --------------------------------------------------------------------------------------------------------- 
  protocol                    :   Proto-buffer driver v2.0 (msg v3.1) (Serial driver v1.0 - COM3:209700) 
  tools                       :   ST Neural ART (LL_ATON api) v1.0.0 
  runtime lib                 :   atonn-v1.0.0-rc0-16-g0307e413 (optimized SW lib v1.0.0-7112010c GCC) 
  capabilities                :   IO_ONLY, PER_LAYER, PER_LAYER_WITH_DATA 
  device.desc                 :   stm32 family - 0x486 - STM32N6 @600/600MHz 
  device.attrs                :   fpu,core_icache,core_dcache,npu_cache,npu_freq=800mhz,nic_freq=400mhz 
  --------------------------------------------------------------------------------------------------------- 
 Warning: C-network signature checking is skipped on ST Neurla-ART NPU 
LOAD ERROR: STM32 - read timeout 50078.0ms/50000ms 
Validation ended

 I suppose it could be a problem related to accessing the parameters in memory, related to the I/O buffers or due to the NPU which doesn't start, what do you think ?

 

This is the output from the uart:

#
# AI Validation ATONN/NPU 0.3
#

Compiled with GCC 13.3.1
STM32 device configuration...
 Device       : DevID:0x0486 (STM32N6) RevID:0x0000
 Core Arch.   : M55 - FPU  used
 HAL version  : 0x01000000
 SYSCLK clock : 600 MHz
 HCLK clock   : 600 MHz
 CACHE conf.  : $I/$D=(True,True)
 Timestamp    : DWT only (delay(1)=1.004 ms)

ATONN RT
--------------------------------------------------
 version         : atonn-v1.0.0-rc0-16-g0307e413
 network rt lib  : v1.0.0-7112010c
   compiled with : GCC 13.3.1

C-Model
--------------------------------------------------
 name          : network
 n_epochs      : 34
 params        : n.a.
 activations   : 988 KiB
 n_inputs      : 1
 name    : Input_0_out_0
  addr   : 0x342e0000 (4096 bytes)  (8 bits)
  type   : 3 shape(3)=(1,4096,1)
  quant  : scale=0.005235, zp=4
 n_outputs     : 1
 name    : Sigmoid_35_out_0
  addr   : 0x342e0000 (4 bytes)  (32 bits)
  type   : 1 shape(2)=(1,1)

-------------------------------------------
| READY to receive a CMD from the HOST... |
-------------------------------------------

# Note: At this point, default ASCII-base terminal should be closed
# and a serial COM interface should be used
# (i.e. Python stm32com module). Protocol version = 3.1

 

By the way, is there any possibility to get the project files in use in the cloud for the STM32N657-DK so I can substitute the network and compile them locally for my Nucleo ?