...

Getting Started with STM32N6 Vision: Running Your First Object Detection Model

A hands-on walkthrough for deploying a pretrained YOLOv8n model to the STM32N6's onboard NPU, from toolchain setup to reading live detection results off a camera feed.

In our previous article we explained what the STM32N6’s NPU actually is and why it matters. This guide is the hands-on follow-up: getting a real object detection model running on the chip, from a fresh toolchain install to live detections off a camera feed.

What You Need

  • An STM32N6-based board (our NVX-N6 Vision or an equivalent eval board)
  • A MIPI CSI-2 or DCMI camera module compatible with your board
  • STM32CubeIDE and the STM32Cube.AI expansion pack installed
  • A pretrained YOLOv8n model, or your own trained in PyTorch/TensorFlow

Setting Up the Toolchain

Install STM32CubeIDE, then add the STM32Cube.AI expansion pack through the package manager. This is what handles converting a standard ONNX or TensorFlow Lite model into instructions the NPU can actually execute — you are not writing NPU assembly by hand. Cube.AI analyzes your model graph and maps supported operations onto the Neural-ART accelerator, falling back to the Cortex-M55 core for anything it cannot offload.

Converting the Model

Export your YOLOv8n model to ONNX format, then run it through the Cube.AI analyzer:

stm32ai analyze --model yolov8n.onnx --target stm32n6

stm32ai generate --model yolov8n.onnx --target stm32n6 \
  --output ./generated --compression int8

The --compression int8 flag quantizes the model to 8-bit integers, which is what lets the NPU hit its rated 600 GOPS and keeps the model small enough to fit in the STM32N6’s onboard RAM. Expect a small accuracy drop versus the full-precision model — usually a percentage point or two on standard benchmarks — which is a reasonable tradeoff for running entirely on-chip with no cloud round-trip.

Integrating the Camera Pipeline

The STM32N6’s dedicated image signal processor (ISP) handles camera input independently of the NPU, so frames flow: camera sensor → ISP → memory buffer → NPU inference → your application code. In STM32CubeIDE, configure the DCMI or CSI-2 peripheral for your specific sensor’s resolution and pixel format, then set up a double-buffered DMA transfer so one frame is being processed while the next is captured.

HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_CONTINUOUS,
                    (uint32_t)&frame_buffer[0], FRAME_SIZE);

// In the frame-ready callback:
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi) {
  ai_run_inference(active_buffer, detection_results);
  swap_buffers();
}

Reading the Results

YOLOv8n outputs bounding boxes, class IDs, and confidence scores per detected object. Filter results below a confidence threshold (0.5 is a reasonable starting point) and apply non-maximum suppression to collapse overlapping boxes around the same object before acting on the output — most Cube.AI generated code includes a post-processing helper for this so you are not implementing NMS from scratch.

Realistic Expectations

At INT8 precision on a 640×480 input, expect roughly 20–25fps for YOLOv8n on the STM32N6 — enough for real-time detection in robotics, security, and industrial inspection applications, though larger input resolutions or heavier model variants will trade frame rate for accuracy. If you need more headroom, cropping the ISP output to a smaller region of interest before inference is often more effective than shrinking the whole frame.

Next Steps

Once a pretrained model runs reliably, the natural next step is training on your own dataset — swapping in domain-specific classes rather than the generic COCO categories YOLOv8n ships with by default — which is a good subject for a follow-up guide.

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.