In this section, you will deploy the model directly on the STM32 board.
STM32CubeMX
is a graphical tool for configuring STM32 microcontrollers.
STM32Cube.AI
is an extension of STM32CubeMX to import ML models.
Download and install STM32CubeMX from the STM32CubeMX product page .
Open STM32CubeMX IDE.
Click Access to Board Selector
. Find your B-L475E-IOT01A
board and click Start Project
.
Go to Project Manager
. Enter a project name and select the project location where the project will be saved.
Under Pinout & Configuration
, expand Pinout
menu, and click Clear pinouts
.
Expand Software Packs
menu, and click Select Components
.
Locate X-CUBE-AI
, and click its Install
button.
Expand the menu and enable X-CUBE-AI
> Core
. For device application, choose Validation
. If the status shows a yellow warning, click Resolve
to install any necessary dependencies.
Click 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 Categories
.
click 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.
Click 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.
Click Show graph
to visualize your model.
Click 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 OK
.A sample application is provided. This uses a feature-based model, trained with the letters O
and 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 main()
to
MX_USART1_UART_Init()
and move to before the call to
MX_X_CUBE_AI_Init()
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 Import
. Select Existing project into workspace
. Go to tf_stm32
folder and select MCU_Activity_Recognition
.
Open 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 Run As
.
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 Application
.
Click Generate Code
then the project is updated.
Open STM32CubeIDE
. Since you re-generated the code again, you need to delete the existing project and import the project again.
Open X-CUBE-AI/App/app_x-cube-ai.c
. This is the auto-generated code by STM32CubeMX
.
Between USER_CODE_BEGIN
and 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