|
STM32N6 NPU Deployment — Politecnico di Milano
1.0
Documentation for Neural Network Deployment on STM32N6 NPU - Politecnico di Milano 2024-2025
|
Central configuration macros for the STM32N6570-DK pose estimation firmware. More...
Modules | |
| Aspect Ratio Handling Modes | |
| Defines how the camera image is resized/cropped to match the NN input. | |
| Color Format Definitions | |
Macros | |
| #define | USE_DCACHE |
| Enable the ARM Cortex-M55 Data Cache (D-Cache). More... | |
| #define | CAMERA_FLIP CMW_MIRRORFLIP_NONE |
| Camera mirror/flip mode — no transformation applied. More... | |
| #define | ASPECT_RATIO_MODE ASPECT_RATIO_CROP |
| Active aspect ratio mode for this deployment. More... | |
| #define | POSTPROCESS_TYPE POSTPROCESS_SPE_MOVENET_UF |
| Select postprocessing pipeline: Single Person Estimation with MoveNet. More... | |
| #define | NN_HEIGHT (192) |
| Neural network input image height in pixels. More... | |
| #define | NN_WIDTH (192) |
| Neural network input image width in pixels. More... | |
| #define | NN_BPP 3 |
| Bytes per pixel of the NN input tensor. More... | |
| #define | COLOR_MODE COLOR_RGB |
| Active color format: RGB. More... | |
| #define | AI_POSE_PP_CONF_THRESHOLD (0.4) |
| Minimum confidence threshold for accepting a detected keypoint. More... | |
| #define | AI_POSE_PP_POSE_KEYPOINTS_NB (13) |
| Number of body keypoints output by the model. More... | |
| #define | AI_SPE_MOVENET_POSTPROC_HEATMAP_WIDTH (NN_WIDTH / 4) |
| Width of the MoveNet output heatmap in pixels. More... | |
| #define | AI_SPE_MOVENET_POSTPROC_HEATMAP_HEIGHT (NN_HEIGHT / 4) |
| Height of the MoveNet output heatmap in pixels. More... | |
| #define | AI_SPE_MOVENET_POSTPROC_NB_KEYPOINTS (AI_POSE_PP_POSE_KEYPOINTS_NB) |
| Number of keypoints for the MoveNet postprocessor. More... | |
| #define | WELCOME_MSG_0 "Single/multi pose estimation - Hand landmark" |
| Welcome screen line 0 — application description. More... | |
| #define | WELCOME_MSG_1 "st_movenet_lightning_heatmaps_192_int8_pc.tflite" |
| Welcome screen line 1 — active model filename. More... | |
| #define | WELCOME_MSG_2 "Model Running in STM32 MCU internal memory" |
| Welcome screen line 2 — memory configuration note. More... | |
Central configuration macros for the STM32N6570-DK pose estimation firmware.
| #define AI_POSE_PP_CONF_THRESHOLD (0.4) |
Minimum confidence threshold for accepting a detected keypoint.
Keypoints with heatmap peak values below this threshold are discarded and not drawn on the LCD. Value range: [0.0, 1.0].
Threshold = 0.4 means only keypoints with ≥40% confidence are displayed. This value was set in user_config.yaml under postprocessing.kpts_conf_thresh and injected here by gen_h_user_file_n6() during deployment.
Definition at line 245 of file app_config.h.
| #define AI_POSE_PP_POSE_KEYPOINTS_NB (13) |
Number of body keypoints output by the model.
The ST variant of MoveNet Lightning uses 13 keypoints (reduced from the original 17 COCO keypoints by removing ankle keypoints for embedded robustness).
Supported values: 13 or 17.
This value is used by display_keypoints_13.h to select the correct skeleton connection table at compile time.
Definition at line 261 of file app_config.h.
| #define AI_SPE_MOVENET_POSTPROC_HEATMAP_HEIGHT (NN_HEIGHT / 4) |
Height of the MoveNet output heatmap in pixels.
Symmetric with the width: 192 / 4 = 48 pixels. The model output tensor shape is: (1, 48, 48, 13).
Definition at line 281 of file app_config.h.
| #define AI_SPE_MOVENET_POSTPROC_HEATMAP_WIDTH (NN_WIDTH / 4) |
Width of the MoveNet output heatmap in pixels.
MoveNet produces heatmaps at 1/4 of the input resolution:
The postprocessor finds the argmax in each 48×48 heatmap channel to locate the corresponding keypoint.
Definition at line 273 of file app_config.h.
| #define AI_SPE_MOVENET_POSTPROC_NB_KEYPOINTS (AI_POSE_PP_POSE_KEYPOINTS_NB) |
Number of keypoints for the MoveNet postprocessor.
Alias for AI_POSE_PP_POSE_KEYPOINTS_NB = 13. Only 13 and 17 are supported for skeleton reconstruction (the skeleton connection tables are defined in display_keypoints_13.h and display_keypoints_17.h respectively).
Definition at line 291 of file app_config.h.
| #define ASPECT_RATIO_MODE ASPECT_RATIO_CROP |
Active aspect ratio mode for this deployment.
Set to ASPECT_RATIO_CROP for the MoveNet deployment. This means the DCMIPP hardware crops a 192×192 region from the center of the camera frame before feeding it to the NPU input buffer.
In main.c, this macro controls the LCD background area X0 offset:
Definition at line 145 of file app_config.h.
| #define CAMERA_FLIP CMW_MIRRORFLIP_NONE |
Camera mirror/flip mode — no transformation applied.
Raw camera output is used without spatial transformation. Other available options: CMW_MIRRORFLIP_FLIP, CMW_MIRRORFLIP_MIRROR, CMW_MIRRORFLIP_FLIP_MIRROR.
Definition at line 88 of file app_config.h.
| #define COLOR_MODE COLOR_RGB |
Active color format: RGB.
The ISP and DCMIPP pipeline deliver frames in RGB565 format. The AI runtime expects uint8 RGB input — the camera middleware handles the RGB565 → RGB888 conversion automatically. MoveNet was trained on RGB images, so COLOR_RGB is required.
Definition at line 225 of file app_config.h.
| #define NN_BPP 3 |
Bytes per pixel of the NN input tensor.
Set to 3 for RGB color images (R, G, B — one byte each). Combined with NN_WIDTH and NN_HEIGHT, defines the total input buffer size:
This buffer is allocated within the NPU activation SRAM banks.
Definition at line 207 of file app_config.h.
| #define NN_HEIGHT (192) |
Neural network input image height in pixels.
Matches the model input tensor second dimension. For MoveNet Lightning: input shape is (1, 192, 192, 3) → NN_HEIGHT = 192. The DCMIPP pipe is configured to deliver exactly this many rows.
Definition at line 182 of file app_config.h.
| #define NN_WIDTH (192) |
Neural network input image width in pixels.
Matches the model input tensor third dimension. For MoveNet Lightning: input shape is (1, 192, 192, 3) → NN_WIDTH = 192.
main.c allocates a temporary buffer dcmipp_out_nn with 16-byte alignment and calls img_crop() to extract the exact NN_WIDTH columns before inference. Definition at line 195 of file app_config.h.
| #define POSTPROCESS_TYPE POSTPROCESS_SPE_MOVENET_UF |
Select postprocessing pipeline: Single Person Estimation with MoveNet.
This macro selects the postprocessing algorithm at compile time. It controls conditional compilation in main.c, display_spe.c/display_mpe.c, and the postprocessing library.
Two options are available:
POSTPROCESS_SPE_MOVENET_UF : MoveNet single-person heatmap decoderPOSTPROCESS_MPE_YOLO_V8_UF : YOLOv8 multi-person bounding box + keypoint decoderFor MoveNet (this deployment), the postprocessor:
Definition at line 169 of file app_config.h.
| #define USE_DCACHE |
Enable the ARM Cortex-M55 Data Cache (D-Cache).
When defined, the firmware enables the 32KB L1 D-Cache at startup in Hardware_init(). This significantly reduces latency for repeated accesses to activation buffers and weight data stored in external OctoFlash/PSRAM.
Cache coherency is maintained manually using:
SCB_InvalidateDCache_by_Addr() — before reading DMA-written buffersSCB_CleanDCache_by_Addr() — before writing to DMA-read buffersSCB_CleanInvalidateDCache_by_Addr() — for bidirectional DMA regionsDefinition at line 76 of file app_config.h.
| #define WELCOME_MSG_0 "Single/multi pose estimation - Hand landmark" |
Welcome screen line 0 — application description.
Displayed on the LCD for the first 4 seconds after boot.
Definition at line 301 of file app_config.h.
| #define WELCOME_MSG_1 "st_movenet_lightning_heatmaps_192_int8_pc.tflite" |
Welcome screen line 1 — active model filename.
Injected by gen_h_user_file_n6() from the model path in user_config.yaml. Allows the user to immediately identify which model is running on the board.
Definition at line 310 of file app_config.h.
| #define WELCOME_MSG_2 "Model Running in STM32 MCU internal memory" |
Welcome screen line 2 — memory configuration note.
Indicates that model weights are stored in STM32N6 internal OctoFlash.
Definition at line 316 of file app_config.h.