# stm32ai-perf
**Repository Path**: mirrors_STMicroelectronics/stm32ai-perf
## Basic Information
- **Project Name**: stm32ai-perf
- **Description**: MLPerf (tm) Tiny Deep Learning Benchmarks for STM32 devices
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2022-02-23
- **Last Updated**: 2026-02-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# MLPerf™ Tiny Deep Learning Benchmarks for STM32 devices
The goal of MLPerf™ Tiny is to provide a representative set of deep neural nets
and benchmarking code to compare performance between embedded devices. These devices
typically run at between 10MHz and 250MHz, and can perform inference using less
then 50mW of power.
For this Benchmark we are suggesting 3 Boards:
- [NUCLEO-H7A3ZI-Q](https://www.st.com/en/evaluation-tools/nucleo-h7a3zi-q.html#sample-buy)
- [NUCLEO-U575ZI-Q](https://www.st.com/en/evaluation-tools/nucleo-u575zi-q.html#sample-buy)
- [NUCLEO-L4R5ZI](https://www.st.com/en/evaluation-tools/nucleo-l4r5zi.html#sample-buy)
In this guide, we will learn how to generate the projects for the previous boards.
## Before You Start
You need to download and install the following software:
- [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html) ( v6.10.0 )
- [STM32CubeIDE](https://www.st.com/en/development-tools/stm32cubeide.html) ( v1.14.1 )
- [IAR EW for ARM](https://www.iar.com/products/architectures/arm/iar-embedded-workbench-for-arm/) ( v9.50.1 )
- [STM32CubeProg](https://www.st.com/en/development-tools/stm32cubeprog.html) ( v2.15.0 )
- [STM32Cube.AI](https://www.st.com/en/embedded-software/x-cube-ai.html) ( v9.0.0 )
Also we need to download the following pretrained quantized model from MLCommons™ Github:
- [Anomaly Detection](https://github.com/mlcommons/tiny/blob/master/benchmark/training/anomaly_detection/trained_models/ad01_int8.tflite)
- [Image Classification](https://github.com/mlcommons/tiny/blob/master/benchmark/training/image_classification/trained_models/pretrainedResnet_quant.tflite)
- [Keyword Spotting](https://github.com/mlcommons/tiny/blob/master/benchmark/training/keyword_spotting/trained_models/kws_ref_model.tflite)
- [Person Detection](https://github.com/mlcommons/tiny/blob/master/benchmark/training/visual_wake_words/trained_models/vww_96_int8.tflite)
### NUCLEO-H7A3ZI-Q Projects
In this section we will explain how to generate the different benchmark projects for the **NUCLEO-H7A3ZI-Q** board.
We will take the Image Classification benchmark project as an example and then exactly the same steps should be repeated for the rest of the scenarios (Anomaly Detection, Keyword Spotting and Person Detection)
### Generate the project using STM32CubeMX
**1. Download the [Image Classification](https://github.com/mlcommons/tiny/blob/master/benchmark/training/image_classification/trained_models) model and then save it under**
```bash
...\stm32ai-perf\STM32_H7A3ZI\image_classification
```
You should have something like this to start:

**2. Open the .ioc file and follow the next steps to generate your project template:**

### Configure and build the project using STM32CubeIDE
After generating the project using STM32CubeMX you should have something like this in your workspace:

**1. Open the .cproject file and follow the next steps to configure your project:**

**2. Modify the main.c file:**
2.1 Open main.c located under Project Explorer:

2.2 Under Private includes add the following:
```bash
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "submitter_implemented.h"
/* USER CODE END Includes */
```
2.3 Add the following line to USER CODE Section 2:
```bash
/* USER CODE BEGIN 2 */
ee_benchmark_initialize();
/* USER CODE END 2 */
```
**2. Modify the stm32h7xx_it.c file:**
2.1 Open stm32h7xx_it.c located under Project Explorer:

2.2 Delete any initial code in the file located after the following lines:
```bash
/******************************************************************************/
/* STM32H7xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32h7xx.s). */
/******************************************************************************/
```
2.3 Configure the TCM memory on the STM32H7A3 :
Under the project, open the file called **STM32H7A3ZITXQ_FLASH.ld**.
Under this file :
- Specify the memory area :
```bash
/* Specify the memory areas */
MEMORY
{
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
DTCMRAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
/*DTCMRAM2 (xrw) : ORIGIN = 0x20010000, LENGTH = 64K*/
RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 1024K
RAM_CD (xrw) : ORIGIN = 0x30000000, LENGTH = 128K
RAM_SRD (xrw) : ORIGIN = 0x38000000, LENGTH = 32K
}
```
- Set data sections, into DTCMRAM1 :
```bash
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >DTCMRAM1
```
**3. Build the project in Release mode:**
Set the project to the release mode as the following and then click on build :

### Flash the board using STM32CubeProg
Next we will demonstarte how to flash your NUCLEO-H7A3ZI-Q board with the binary file you generated in the previous step
**1. Verify the board configuration:**
Make sure that your board has the the following jumpers fitted:

**2. Flash the board:**
Connect the board to the laptop using a usb cable and use STM32CubeProg to flash the board as the following:

### Energy mode setup
For energy mode the **EE_CFG_ENERGY_MODE** flag should be set to **1**.

You need to make sure that the **MCU_RST** and the **MCU_VDD** jumpers are **not fitted**.
The final setup should look like the following:

**Make sure to push the Reset Button (the Black Button) on the board before starting the benchmark software.**
For more details about the energy benchmark and EEMBCs EnergyRunner™ benchmark framework please refer to this [link](https://github.com/eembc/energyrunner)
### Performance mode setup
For Performance mode the **EE_CFG_ENERGY_MODE** flag should be set to **0**.

The board should be connected to the laptop using a usb cable and you need to make sure that the **MCU_RST** and the **MCU_VDD** jumpers are **fitted**.
**Make sure to push the Reset Button (the Black Button) on the board before starting the benchmark software.**
For more details about the Performance mode and EEMBCs EnergyRunner™ benchmark framework please refer to this [link](https://github.com/eembc/energyrunner)
## NUCLEO-U575ZI-Q Projects
In this section we will explain how to generate the different benchmark projects for the **NUCLEO-U575ZI-Q** board.
We will take the Anomaly Detection benchmark project as an example and then exactly the same steps should be repeated for the rest of the scenarios (Image Classification, Keyword Spotting and Person Detection)
### Generate the project using STM32CubeMX
**1. Download the [Anomaly Detection](https://github.com/mlcommons/tiny/blob/master/benchmark/training/anomaly_detection/trained_models/ad01_int8.tflite) model and then save it under**
```bash
...\stm32ai-perf\STM32_U575ZI\anomaly_detection
```
You should have something like this to start:

**2. Open the .ioc file and follow the next steps to generate your project template:**

### Configure and build the project using STM32CubeIDE
After generating the project using STM32CubeMX you should have something like this in your workspace:

**1. Open the .cproject file and follow the next steps to configure your project:**

**2. Modify the main.c file:**
2.1 Open main.c located under Project Explorer:

2.2 Under Private includes add the following:
```bash
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "submitter_implemented.h"
/* USER CODE END Includes */
```
2.3 Add following code in USER CODE Section 2:
```bash
/* USER CODE BEGIN 2 */
ee_benchmark_initialize();
/* USER CODE END 2 */
```
**2. Modify the stm32u5xx_it.c file:**
2.1 Open stm32u5xx_it.c located under Project Explorer:

2.2 Delete any initial code in the file located after the following lines:
```bash
/******************************************************************************/
/* STM32U5xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32u5xx.s). */
/******************************************************************************/
```
**3. Build the project in Release mode:**
Set the project to the release mode as the following and then click on build :

### Flash the board using STM32CubeProg
Next we will demonstarte how to flash your NUCLEO-U575ZI-Q board with the binary file you generated in the previous step
**1. Verify the board configuration:**
Make sure that your board has the the following jumpers fitted:

**2. Flash the board:**
Connect the board to the laptop using a usb cable and use STM32CubeProg to flash the board as the following:

### Energy mode setup
For energy mode the **EE_CFG_ENERGY_MODE** flag should be set to **1**.

You need to make sure that the **T_NRST** and the **IDD** jumpers are **not fitted**.
The final setup should look like the following:

**Make sure to push the Reset Button (the Black Button) on the board before starting the benchmark software.**
For more details about the energy benchmark and EEMBCs EnergyRunner™ benchmark framework please refer to this [link](https://github.com/eembc/energyrunner)
### Performance mode setup
For Performance mode the **EE_CFG_ENERGY_MODE** flag should be set to **0**.

The board should be connected to the laptop using a usb cable and you need to make sure that the **T_NRST** and the **IDD** jumpers are **fitted**.
**Make sure to push the Reset Button (the Black Button) on the board before starting the benchmark software.**
For more details about the Performance mode and EEMBCs EnergyRunner™ benchmark framework please refer to this [link](https://github.com/eembc/energyrunner)
## NUCLEO-L4R5ZI Projects
In this section we will explain how to generate the different benchmark projects for the **NUCLEO-L4R5ZI** board.
We will take the Person Detection benchmark project as an example and then exactly the same steps should be repeated for the rest of the scenarios (Anomaly Detection, Keyword Spotting and Image Classification)
### Generate the project using STM32CubeMX
**1. Download the [Person Detection](https://github.com/mlcommons/tiny/blob/master/benchmark/training/visual_wake_words/trained_models/vww_96_int8.tflite) model and then save it under**
```bash
...\stm32ai-perf\STM32_L4R5ZI\person_detection
```
You should have something like this to start:

**2. Open the .ioc file and follow the next steps to generate your project template:**

### Configure and build the project using STM32CubeIDE
After generating the project using STM32CubeMX you should have something like this in your workspace:

**1. Open the .cproject file and follow the next steps to configure your project:**

**2. Modify the main.c file:**
2.1 Open main.c located under Project Explorer:

2.2 Under Private includes add the following:
```bash
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "submitter_implemented.h"
/* USER CODE END Includes */
```
2.3 Add the following line to USER CODE Section 2:
```bash
/* USER CODE BEGIN 2 */
ee_benchmark_initialize();
/* USER CODE END 2 */
```
**2. Modify the stm32l4xx_it.c file:**
2.1 Open stm32l4xx_it.c located under Project Explorer:

2.2 Delete any initial code in the file located after the following lines:
```bash
/******************************************************************************/
/* STM32L4xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32l4xx.s). */
/******************************************************************************/
```
**3. Build the project in Release mode:**
Set the project to the release mode as the following and then click on build :

### Flash the board using STM32CubeProg
Next we will demonstarte how to flash your NUCLEO-L4R5ZI board with the binary file you generated in the previous step
**1. Verify the board configuration:**
Make sure that your board has the the following jumpers fitted:

**2. Flash the board:**
Connect the board to the laptop using a usb cable and use STM32CubeProg to flash the board as the following and before flashing your board make sure that your board is in single bank, for this you need to go under option bytes then user configuration and let DBANK bit unchecked.

### Energy mode setup
For energy mode the **EE_CFG_ENERGY_MODE** flag should be set to **1**.

You need to make sure that the **MCU_RST** and the **IDD** jumpers are **not fitted**.
The final setup should look like the following:

**Make sure to push the Reset Button (the Black Button) on the board before starting the benchmark software.**
For more details about the energy benchmark and EEMBCs EnergyRunner™ benchmark framework please refer to this [link](https://github.com/eembc/energyrunner)
### Performance mode setup
For Performance mode the **EE_CFG_ENERGY_MODE** flag should be set to **0**.

The board should be connected to the laptop using a usb cable and you need to make sure that the **MCU_RST** and the **IDD** jumpers are **fitted**.
**Make sure to push the Reset Button (the Black Button) on the board before starting the benchmark Software.**
For more details about the Performance mode and EEMBCs EnergyRunner™ benchmark framework please refer to this [link](https://github.com/eembc/energyrunner)