This project provides an STM32 microcontroller embedded real-time environment to execute STEdgeAI generated models targeting object detection application. The code developement is lead by its understandability rather than its performance, and is intended to be used as a starting point for further development.
This is a standalone project that can be used as-is to deploy the application on the hardware. However, it is also part of the ST ModelZoo repo and is needed to deploy the object detection use case. The ModelZoo allows you to train, evaluate and deploy automatically any supported model. If you wish to use it as part of the ModelZoo, please refer to the ModelZoo README on how to use it.
This top readme gives an overview of the app. Additional documentation is available in the Doc folder.
This repository is structured as follows:
| Directory | Content |
|---|---|
| Inc | Application include files |
| Src | Application source files |
| Application/Model/* | Placeholder for AI C-model; files generated by cubeAI |
| STM32Cube_FW_N6/Drivers/CMSIS | CMSIS Drivers |
| STM32Cube_FW_N6/Drivers/BSP | Board Support Package and Drivers |
| STM32Cube_FW_N6/Drivers/STM32XXxx_HAL_Driver | Hardware Abstraction Layer for STM32XXxx family products |
| Middlewares/AI_Runtime | Placeholder for AI runtime library |
| Middlewares/Camera_Middleware | Middleware to ease camera configuration |
| Middlewares/lib_vision_models_pp | Computer vision models post processing |
README Content
- Features demonstrated in this example
- Hardware Support
- Tools version
- Boot modes
- Quickstart using prebuilt binaries
- Quickstart using source code
- Known Issues and Limitations
Doc Folder Content
- Application overview
- Boot Overview
- Deploy your tflite model
- Camera build options
- Camera Orientation
- Aspect Ratio mode
- Sequential application flow
- NPU accelerated quantized AI model inference
- Dual DCMIPP pipes
- DCMIPP crop, decimation, downscale
- DCMIPP ISP usage
- LTDC dual-layer implementation
- Dev mode
- Boot from External Flash
The development platform:
- STM32N6570-DK discovery board
- The board should be connected to the onboard ST-LINK debug adapter CN6 with a USB-C to USB-C cable to ensure sufficient power
- Set the boot mode in dev mode (BOOT1 switch to right position. BOOT0 switch position doesn't matter)
- OTP fuses are set in this example for xSPI IOs in order to get the maximum speed (200MHz) on xSPI interfaces
And one of the following camera modules:
- Provided IMX335 camera module
- STEVAL-55G1MBI
- STEVAL-66GYMAI1
STM32N6570-DK board with MB1854B IMX335.
- STM32CubeIDE (STM32CubeIDE 1.17.0)
- STM32CubeProgrammer (v2.18.0)
- STEdgeAI (v2.0.0)
The STM32N6 does not have any internal flash. To retain your firmware after a reboot, you must program it in the external flash. Alternatively, you can load your firmware directly from SRAM (dev mode). However, in dev mode if you turn off the board, your program will be lost.
Boot modes:
- Dev mode (boot switch to the right): load firmware from debug session in RAM, program firmware in external flash
- Boot from flash (boot switch to the left): boot from firmware in external flash
Three binaries must be programmed in the board external flash using the following procedure:
- Switch BOOT1 switch to right position
- Program
Binary/ai_fsbl.hex(First stage boot loader) - Program
Binary/network_data.hex(params of the networks; To be changed only when the network is changed) - Program
Binary/STM32N6_GettingStarted_ObjectDetection.hex(firmware application) - Switch BOOT1 switch to Left position
- Power cycle the board
Note: The Binary/STM32N6_GettingStarted_ObjectDetection.hex firmware is built for MB1939 STM32N6570-DK REV C02 with IMX335 Camera module.
Note: The Binary/ai_fsbl.hex firmware is built for MB1939 STM32N6570-DK REV C02.
See How to Program hex files STM32CubeProgrammer
Make sure to have the STM32CubeProgrammer bin folder added in your path.
export DKEL="<STM32CubeProgrammer_N6 Install Folder>/bin/ExternalLoader/MX66UW1G45G_STM32N6570-DK.stldr"
# First Stage Boot loader
STM32_Programmer_CLI -c port=SWD mode=HOTPLUG -el $DKEL -hardRst -w Binary/ai_fsbl.hex
# Network parameters and biases
STM32_Programmer_CLI -c port=SWD mode=HOTPLUG -el $DKEL -hardRst -w Binary/network_data.hex
# Application Firmware
STM32_Programmer_CLI -c port=SWD mode=HOTPLUG -el $DKEL -hardRst -w Binary/STM32N6_GettingStarted_ObjectDetection.hexBefore building and running the application you have to program network_data.hex (model weights and biases).
This step only has to be done once unless you change AI model.
See Quickstart using prebuilt binaries for details.
More information about boot modes is available at Boot Overview
Make sure to have the switch to the right side.
Double click on STM32CubeIDE/.project to open project in STM32CubeIDE. Build and run.
Before running commands below be sure to have them in your PATH.
- Build project using the provided
Makefile:
make -j8- Open a gdb server connected to the STM32 target:
ST-LINK_gdbserver -p 61234 -l 1 -d -s -cp <path-to-stm32cubeprogramer-bin-dir> -m 1 -g- In a separate terminal session launch a GDB session to load the firmware image into the device memory:
$ arm-none-eabi-gdb build/Project.elf
(gdb) target remote :61234
(gdb) monitor reset
(gdb) load
(gdb) continueMake sure to have the switch to the right side.
Double click on STM32CubeIDE/.project to open project in STM32CubeIDE. Build and run.
Before running commands below be sure to have commands in your PATH.
Build project using the provided Makefile:
make -j8Once your app is built with Makefile, STM32CubeIDE, you can add a signature to the bin file:
STM32_SigningTool_CLI -bin build/Project.bin -nk -t ssbl -hv 2.3 -o build/Project_sign.binYou can program the signed bin file at the address 0x70100000.
export DKEL="<STM32CubeProgrammer_N6 Install Folder>/bin/ExternalLoader/MX66UW1G45G_STM32N6570-DK.stldr"
# Adapt build path to your IDE
STM32_Programmer_CLI -c port=SWD mode=HOTPLUG -el $DKEL -hardRst -w build/Project_sign.bin 0x70100000Note: Only the App binary needs to be programmed if the fsbl and network_data.hex was previously programmed.
Put the switch to the left side.
Do a power cycle to boot from the external flash.
- Only RGB888 format for nn input has been tested.
- Only UINT8 format for nn input is supported.
- ASPECT_RATIO_FULLSCREEN does not work as expected