Skip to main content
Associate
Question

STM32N657 as a drone flight controller: NPU inference next to an 8 kHz control loop (notes + two questions)

We’ve been running a flight controller on the STM32N657 and wanted to share some measurements and ask about two things we’re unsure of.

 

Setup: OV9281 global-shutter camera (120 fps, 320 x 240) over CSI-2 into DCMIPP, an INT8 gate-detection network on the Neural-ART NPU, policy + state estimator on the Cortex-M55 with Helium, attitude loop at 8 kHz.

 

Measured on our engineering sample:

- CSI-2 DMA into SRAM + ISP: 0.41 ms

- NPU inference (INT8): 1.92 ms

- Policy MLP + state estimator: 0.06 ms

- Mixer + bidirectional DShot: 0.13 ms

Camera to motor command is about 10.8 ms, dominated by the 8.3 ms frame interval.

 

Questions:

1. When the NPU and the M55 both hit XSPI-mapped memory (we keep frame buffers and activations in external PSRAM), what's the recommended way to keep control-loop ISR jitter low? Loop code and its data already sit in internal SRAM; is there anything on the bus/arbitration side we should know about?

2. Is there an ST example that feeds DCMIPP output straight into the NPU input buffer, and has anyone measured how much that saves versus going through an intermediate buffer?

 

Happy to share more detail if it's useful to others.

 

--

Štěpán Kaiser, Remānguys (maker of the SILM N6 board: https://silm-n6.honza-071.workers.dev/?ref=st)

3 replies

ST Technical Moderator

Hi ​@remanguys 

  1. Did you measure the loop’s timing while the camera and NPU are active to see whether sharing is actually causing jitter?
  2. This demo gets the model input pointer with stai_network_get_inputs(), passes it to CameraPipeline_NNPipe_Start(nn_in, CMW_MODE_SNAPSHOT), and waits for capture completion before starting inference. 
To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
remanguysAuthor
Associate

Thanks @FBL, that helps with question 2. The snapshot pattern (stai_network_get_inputs() -> CameraPipeline_NNPipe_Start(nn_in, CMW_MODE_SNAPSHOT) -> wait for capture, then inference) serializes capture and inference, which also makes it easier to isolate where any jitter comes from.

To your question: not yet in a way I would trust. Next step is a GPIO toggle at the start of the control loop ISR, captured on a logic analyzer in three states: camera and NPU idle, camera streaming only, camera plus NPU inference. I will post the period histograms here.

If the jitter only shows up with the NPU active, is there a recommended way to keep the control-loop data and the ISR in TCM so they stay off the AXI path the NPU is using?

ST Technical Moderator

Hi ​@remanguys 

Great, keep me updated on the timing results. If the NPU adds jitter, try placing the control loop ISR, stack, and frequently used data in TCM, while keeping NPU input output and intermediate buffers out of that memory. Then compare worst case ISR jitter with the NPU idle and active.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL