Skip to content

STMicroelectronics/STM32N6-GettingStarted-ObjectDetection

Object Detection Getting Started

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.

Directory contents

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

Table of Contents

README Content

Doc Folder Content

Features demonstrated in this example

  • 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

Hardware Support

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:

Board STM32N6570-DK board with MB1854B IMX335.

Tools version

Boot modes

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

Quickstart using prebuilt binaries

Three binaries must be programmed in the board external flash using the following procedure:

  1. Switch BOOT1 switch to right position
  2. Program Binary/ai_fsbl.hex (First stage boot loader)
  3. Program Binary/network_data.hex (params of the networks; To be changed only when the network is changed)
  4. Program Binary/STM32N6_GettingStarted_ObjectDetection.hex (firmware application)
  5. Switch BOOT1 switch to Left position
  6. 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.

How to Program hex files using STM32CubeProgrammer UI

See How to Program hex files STM32CubeProgrammer

How to Program hex files using Command line

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.hex

Quickstart using source code

Before 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

Application build and run - Dev mode

Make sure to have the switch to the right side.

STM32CubeIDE

Double click on STM32CubeIDE/.project to open project in STM32CubeIDE. Build and run.

Makefile

Before running commands below be sure to have them in your PATH.

  1. Build project using the provided Makefile:
make -j8
  1. 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
  1. 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) continue

Application build and run - Boot from flash

Make sure to have the switch to the right side.

Build the application

STM32CubeIDE

Double click on STM32CubeIDE/.project to open project in STM32CubeIDE. Build and run.

Makefile

Before running commands below be sure to have commands in your PATH.

Build project using the provided Makefile:

make -j8

Program the firmware in the external flash

Once 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.bin

You 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 0x70100000

Note: 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.

Known Issues and Limitations

  • 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

About

An AI software application package demonstrating simple implementation of object detection use case on STM32N6 product.​

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors