Computer Vision application to enable the deployment of object detection models on the STM32N6570-DK board and stream results through USB using UVC/H264 format.
Following UVC resolution and framerate will be output according to connected camera :
- 1280x720@30fps for IMX335
- 1120x720@30fps for VD66GY
- 640x480@30fps for VD55G1
This top readme gives an overview of the app. Additional documentation is available in the Doc folder.
- Multi-threaded application flow (Azure RTOS ThreadX)
- NPU accelerated quantized AI model inference
- Dual DCMIPP pipes
- DCMIPP crop, decimation, downscale
- DCMIPP ISP usage
- H264 encoder
- USB UVC (Azure RTOS USBX)
- Dev mode
- Boot from external flash
-
MB1939 STM32N6570-DK
- 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
- An additional USB cable to connect USB1 (CN18) to the host computer for UVC streaming
- OTP fuses are set in this example for xSPI IOs to get the maximum speed (200MHz) on xSPI interfaces
-
3 cameras are supported:
- MB1854B IMX335 (Default camera provided with the MB1939 STM32N6570-DK board)
- STEVAL-55G1MBI VD55G1 Camera module (Use the CSI-2 cable provided with the camera module)
- STEVAL-66GYMAI VD66GY Camera module (Use the CSI-2 cable provided with the camera module)
STM32N6570-DK board with MB1854B IMX335.
- IAR Embedded Workbench for Arm (EWARM 9.40.1) + N6 patch (EWARMv9_STM32N6xx_V1.0.0)
- STM32CubeIDE (STM32CubeIDE 1.17.0)
- STM32CubeProgrammer (v2.18.0)
- STEdgeAI (v2.1.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 (Both boot switches to the right): load firmware from debug session in RAM, program firmware in external flash
- Boot from flash (Both boot switches to the left)
You can see application messages by attaching a console application to the ST-Link console output. Use the following console parameters:
- Baud rate of 115200 bps.
- No parity.
- One stop bit.
Three binaries must be programmed in the board's external flash using the following procedure:
- Set both switches to the right side.
- Program
Binary/ai_fsbl.hex
(to be done once) (First stage boot loader). - Program
Binary/network_data.hex
(parameters of the networks; to be changed only when the network is changed). - Program
Binary/x-cube-n6-ai-h264-usb-uvc.hex
(firmware application). - Set both switches to the left side.
- Power cycle the board.
- Launch host camera application
See How to Program Hex Files STM32CubeProgrammer.
Make sure to have the STM32CubeProgrammer bin folder added to 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/x-cube-n6-ai-h264-usb-uvc.hex
Observe the streaming of the camera and the output of the computer vision network on a camera application:
-
Linux users: Use a webcam application that is able to decode H264 (e.g., guvcview, VLC).
-
Windows users: Install ffmpeg and then run the following command:
ffplay.exe -f dshow -i video="STM32 uvc"
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 the AI model. See Quickstart Using Prebuilt Binaries for details.
More information about boot modes is available in the Boot Overview.
Make sure to have both switches to the right side.
Double-click on STM32CubeIDE/.project
to open the project in STM32CubeIDE. Build and run using the build and run buttons.
Double-click on EWARM/Project.eww
to open the project in the IAR IDE. Build and run using the build and run buttons.
Before running the commands below, make sure to have the necessary commands in your PATH.
- Build the 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) continue
Make sure to have both switches to the right side.
Double-click on STM32CubeIDE/.project
to open the project in STM32CubeIDE. Build with build button.
Double-click on EWARM/Project.eww
to open the project in the IAR IDE. Build with build button.
Before running the commands below, make sure to have the necessary commands in your PATH.
- Build the project using the provided
Makefile
:
make -j8
Once your app is built with Makefile, STM32CubeIDE, or EWARM, you must 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.
Set both switches to the left side.
Do a power cycle to boot from the external flash.
- (VENC_IMX335_WIDTH * 4) must be a multiple of 16
- VENC_IMX335_WIDTH must be greater or equal to VENC_IMX335_HEIGHT
- VENC_VD66GY_WIDTH must be greater or equal to VENC_VD66GY_HEIGHT
- VENC_VD55G1_WIDTH must be greater or equal to VENC_VD55G1_HEIGHT