In this section, you will deploy the model directly on the STM32 board.
Download and install STM32CubeMX from the STM32CubeMX product page .
Open STM32CubeMX IDE.
Access to Board Selector. Find your
B-L475E-IOT01A board and click
Project Manager. Enter a project name and select the project location where the project will be saved.
Pinout & Configuration, expand
Pinout menu, and click
Software Packs menu, and click
X-CUBE-AI, and click its
Expand the menu and enable
Core. For device application, choose
Validation. If the status shows a yellow warning, click
Resolve to install any necessary dependencies.
OK when done.
You will now validate the NN model built in the previous section on the desktop and the development board.
On the STM32CubeAI menu, locate
X-CUBE-AI configuration from the list of
Add network. Browse to the generated model (
.h5 file). You can also specify other values, such as validation input, and validation output. Leave as default for now.
Analyze, then it will generate a detailed report on the model. You can check the number of parameters, the size of the weights, and the amount of memory to be used.
Show graph to visualize your model.
Validate on Desktop to validate the model with the provided input and output on your desktop.
To validate the model on the target, you need to first generate code and install the code on the target.
Validate on target, and enable
Automatic compilation and download. Select the appropriate toolchain (
STM32CubeIDE), and click
A sample application is provided. This uses a feature-based model, trained with the letters
S written in a horizontal plane.
There is a bug in the example as supplied. You must edit
/Core/Src/main.c before building.
Locate the function call in
and move to before the call to
Using a terminal application (such as
PuTTY), set up the serial connection to the board.
COM number will be as before. The baud rate should be 115200.
Import the application. Click the File tab and click
Existing project into workspace. Go to
tf_stm32 folder and select
X-CUBE-AI/App/app_x-cube-ai.c. Observe that functions are provided for data acquisition from the accelerometer sensor and feature extraction.
Build application and flash to target with
Observe output on the terminal.
Press the blue button on the board, draw a letter, then press the button again.
You can create your own application from the model you have trained.
Open the list of Software Packages. Change the device application as
Generate Code then the project is updated.
STM32CubeIDE. Since you re-generated the code again, you need to delete the existing project and import the project again.
X-CUBE-AI/App/app_x-cube-ai.c. This is the auto-generated code by
USER_CODE_END, you can write code for your application.
There are two main functions that you should implement:
acquire_and_process_data() is for getting data from sensors and processing the data, for example, extracting features.
postprocess() is for postprocessing the output