STM32N6 NPU Deployment — Politecnico di Milano  1.0
Documentation for Neural Network Deployment on STM32N6 NPU - Politecnico di Milano 2024-2025
Application Configuration

Central configuration macros for the STM32N6570-DK pose estimation firmware. More...

Collaboration diagram for Application Configuration:

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

Detailed Description

Central configuration macros for the STM32N6570-DK pose estimation firmware.

Macro Definition Documentation

◆ AI_POSE_PP_CONF_THRESHOLD

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

Note
Lower values show more keypoints but increase false positives. Higher values reduce noise but may miss low-confidence detections (e.g., partially occluded joints).

Definition at line 245 of file app_config.h.

◆ AI_POSE_PP_POSE_KEYPOINTS_NB

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

  • 13: nose, left/right eye, left/right ear, left/right shoulder, left/right elbow, left/right wrist, left/right hip
  • 17: full COCO body keypoints (adds knees and ankles)

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.

◆ AI_SPE_MOVENET_POSTPROC_HEATMAP_HEIGHT

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

◆ AI_SPE_MOVENET_POSTPROC_HEATMAP_WIDTH

#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:

heatmap_width = NN_WIDTH / 4 = 192 / 4 = 48
#define NN_WIDTH
Neural network input image width in pixels.
Definition: app_config.h:195

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.

◆ AI_SPE_MOVENET_POSTPROC_NB_KEYPOINTS

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

◆ ASPECT_RATIO_MODE

#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:

lcd_bg_area.X0 = (LCD_FG_WIDTH - LCD_FG_HEIGHT) / 2; // centers the crop
#define LCD_FG_WIDTH
LCD foreground layer width = full screen width (800 pixels)
Definition: main.c:111
#define LCD_FG_HEIGHT
LCD foreground layer height = full screen height (480 pixels)
Definition: main.c:114
Rectangle_TypeDef lcd_bg_area
LCD background area — camera preview region.
Definition: main.c:140
uint32_t X0
Definition: main.c:126

Definition at line 145 of file app_config.h.

◆ CAMERA_FLIP

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

◆ COLOR_MODE

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

◆ NN_BPP

#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:

nn_input_size = NN_WIDTH * NN_HEIGHT * NN_BPP = 192 * 192 * 3 = 110,592 bytes
#define NN_BPP
Bytes per pixel of the NN input tensor.
Definition: app_config.h:207
#define NN_HEIGHT
Neural network input image height in pixels.
Definition: app_config.h:182

This buffer is allocated within the NPU activation SRAM banks.

Definition at line 207 of file app_config.h.

◆ NN_HEIGHT

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

◆ NN_WIDTH

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

Note
When NN_WIDTH × NN_BPP is not a multiple of 16, the DCMIPP hardware requires padding. In this case, 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.

◆ POSTPROCESS_TYPE

#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 decoder
  • POSTPROCESS_MPE_YOLO_V8_UF : YOLOv8 multi-person bounding box + keypoint decoder

For MoveNet (this deployment), the postprocessor:

  1. Reads the (48×48×13) float32 heatmap output tensor
  2. For each of the 13 keypoints, finds the peak pixel in its heatmap channel
  3. Converts peak coordinates to normalized [0,1] image coordinates
  4. Filters keypoints below AI_POSE_PP_CONF_THRESHOLD
  5. Returns a spe_pp_out_t structure with keypoint positions and confidences

Definition at line 169 of file app_config.h.

◆ USE_DCACHE

#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 buffers
  • SCB_CleanDCache_by_Addr() — before writing to DMA-read buffers
  • SCB_CleanInvalidateDCache_by_Addr() — for bidirectional DMA regions
Note
Cache management is critical for the camera pipeline: the DCMIPP DMA writes camera frames directly to memory, bypassing the cache. Without explicit invalidation, the CPU would read stale cached data.

Definition at line 76 of file app_config.h.

◆ WELCOME_MSG_0

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

◆ WELCOME_MSG_1

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

◆ WELCOME_MSG_2

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