Real-time camera pipeline on a microcontroller
Our camera module’s microcontroller, an STM32N657, now captures, scores and compresses 15 frames per second, up from about 3. The per-capture work dropped from 300 ms to 65.7 ms. Four changes made that possible: a table-driven CRC, a DMA send queue, image pipes that never stop, and a neural network that runs while the JPEG encoder works. In the final bench run, 163 of 168 capture periods were at or under 70 ms, with 0 checksum errors and 0 overwritten frames.
This post walks through the starting loop and each of the four steps with its measured result. It then compares the stage timings side by side and closes with what this lets EverBowl do.
The short version
• A loop that did every stage in sequence spent 300 ms per capture, which capped it at about 3 fps even when run back to back.
• Moving the image link onto a DMA queue with 7 slots of 128 KB took sending out of the capture path and raised the rate to 5.0 fps.
• Keeping the image pipes running on rotating buffers cut the wait for a frame from 115 ms to 3.1 ms and reached 12.0 fps.
• Running the network on the NPU while the JPEG encoder and CRC work brought each capture to 65.7 ms, which is 15.0 fps.
Why was the starting loop stuck at 3 fps?
The camera module runs on an STM32N657, a Cortex-M55 microcontroller with ST’s Neural-ART NPU and a hardware JPEG codec, clocked at 400 MHz in our firmware. ST’s STM32N657X0 product page and reference manual RM0486 cover the NPU and the JPEG codec in detail.
Each capture on the camera module produces two things from one sensor frame. The hardware image pipeline delivers a 768 × 432 color frame for a JPEG at quality 85, and a 224 × 224 tile for the dog-image network on the neural accelerator (NPU). The pipeline itself is described in our post on the all-hardware image pipeline, and the network in our post on the first neural network on the camera module.
The first live loop ran once per second and did everything in order. It paused the pipes on a frame boundary, ran the network, encoded the JPEG, computed a CRC32, sent the frame over the bench link, and resumed. We timed every stage with the CPU’s cycle counter over 64 captures.
The medians were 88 ms to wait for the frame and pause, 47.4 ms for the network, 20.6 ms for the JPEG, 21.3 ms for the CRC and 125.2 ms to send a 37.9 KB JPEG at 3 Mbaud, for 300 ms in total. Every stage waited for the one before it, so the loop could never pass about 3 fps.
From then on, every capture printed one timing line. It lists each stage in microseconds, the start-to-start period, the send queue’s queued, sent and dropped counts, and how many claimed frames overlapped a newer one. Each step below was judged on those lines, not on how the image looked.
Step 1: A table-driven CRC32 and back-to-back capture
The CRC32 that protects each JPEG on the link was computed bit by bit. Replacing it with the standard 256-entry lookup table, which processes a byte per step, cut it from 21.3 ms to 3.7 ms.
The capture step also moved off the one-second housekeeping tick and onto its own cadence, so it could run on every new frame. Auto exposure and white balance stay on the one-second tick, as covered in our post on auto exposure and white balance on a microcontroller camera. Running back to back, each capture took 279.8 ms of work, and the loop completed 180 captures in 60 s, which is 3.0 fps, with 0 checksum errors. The remaining time, about 53 ms per capture, went to the main loop between captures.
Step 2: A DMA UART send queue that takes sending off the capture path
Sending each JPEG at 3 Mbaud took a median of 93.4 ms, which is about 28 KB at line speed, and the CPU did nothing else meanwhile. (JPEG size changes with the scene.) The link now has a send queue instead. Each JPEG is encoded straight into one of 7 slots of 128 KB in external memory, and a DMA channel drains the queue from its transfer-complete interrupt.
Console text goes through its own 16 KB ring on the same channel, and never splits a frame. A change of link speed flushes the queue before the port is set up again.
If all 7 slots are still waiting to go out, the new frame is dropped and counted instead of stalling the capture. The send stage fell from 93.4 ms to 0.002 ms. Over 300 captures, each capture took 186.2 ms of work and one began every 199.9 ms, which is 5.0 fps, with 0 drops and 0 checksum errors.
Step 3: Continuous capture with rotating frame buffers
The loop still paused the pipes for each capture, so a frame could not change while it was being read. Waiting for a frame boundary, pausing and resuming took 115 ms. The pipes now run continuously into rotating buffers: two for the color frame and three for the network tile. The frame-complete interrupt records the newest finished buffer, and the capture step claims it.
Both pipes must deliver the same sensor frame. The claim therefore checks that they finished within 2 ms of each other. In the code below, look for the d <= 2U check, which accepts a matching pair, and the else branch, which drops the older frame:
if (s_tb1.latest >= 0 && s_tb2.latest >= 0 && (HAL_GetTick() - s_tb1.latest_tick) <= fresh_ms) {
uint32_t d = s_tb1.latest_tick - s_tb2.latest_tick;
if (d <= 2U || d >= 0xFFFFFFFEU) { /* same sensor frame: both pipes complete within 2 ms */
s_tb1.held = s_tb1.latest; s_tb2.held = s_tb2.latest;
s_tb1.latest = -1; s_tb2.latest = -1;
f->frame = s_tb1.latest_frame; f->tick_ms = s_tb1.latest_tick;
f->y = (const uint8_t *)s_tb1.ybuf[s_tb1.held]; f->uv = (const uint8_t *)s_tb1.uvbuf[s_tb1.held];
f->tile = (const uint8_t *)s_tb2.ybuf[s_tb2.held];
f->yuv_buf = s_tb1.held; f->tile_buf = s_tb2.held;
s_last_y = f->y; s_last_tile = f->tile;
ok = 1;
} else { /* out of step: drop the older one */
if ((int32_t)d < 0) { s_tb1.latest = -1; } else { s_tb2.latest = -1; }
s_tb_mismatch++;
}The network tile gets three buffers because it is held for the whole network run. When a tile frame completes, the interrupt points the hardware at a buffer that is neither the newest nor the one being held, so the held tile is never written.
The color frame has two buffers, so it is encoded first, in about 21.7 ms, which finishes inside one sensor frame. That frees its buffer before the camera needs it again. A check after encoding then confirms that the buffer was not rewritten while it was being read.

The check uses frame counts and time. If two newer frames have completed, the buffer was certainly rewritten. If one newer frame completed more than 12 ms ago, the camera’s writer may have passed the encoder, so that is counted as overwritten too. Otherwise the encoder, which reads top to bottom like the camera writes, stayed ahead. The sensor’s line length also dropped from 6x to 2.5x, and the exposure was rescaled from 343 to 823 lines, so the image kept the same brightness at a higher frame rate.
Over 720 captures, waiting for a frame took 3.1 ms, each capture took 82.7 ms of work, and one began every 83.2 ms, which is 12.0 fps. The run had 0 overwritten frames and 0 mismatched pipe pairs.
Step 4: Asynchronous NPU inference alongside JPEG encoding
At 12 fps, the network and the JPEG still took turns. The NPU runtime now runs asynchronously: the capture step starts the network, which copies the tile in and returns at once. The NPU’s interrupt marks each finished block of layers, and one short call ends that block and starts the next. The JPEG encoder’s wait loop and the CRC, which runs in 1 KB chunks, both make that call between their own work. In the code below, look for the idle hook set before encoding and the App_NPU_Poll() call inside the CRC loop:
App_JPEG_SetIdleHook((nrc >= 0 && !serial) ? App_NPU_PollHook : NULL);
int jrc = App_JPEG_EncodeYUV420_DMA(cf.y, cf.uv, NULL,
APP_CAM_PIPE1_W, APP_CAM_PIPE1_H, jpg, jmax, &jl, EVIDENCE_JPEG_QUALITY, &bm);
App_JPEG_SetIdleHook(NULL);
int torn = App_Camera_YUVTornCheck(&cf);
App_Camera_ReleaseYUV();
uint32_t u2 = cap_cyc();
uint32_t jcrc = 0xFFFFFFFFU, crc_own = 0;
if (jrc == 0) {
for (uint32_t off = 0; off < jl; off += 1024U) {
uint32_t n = (jl - off) > 1024U ? 1024U : (jl - off);
uint32_t c0 = cap_cyc();
jcrc = App_ImgLink_CRC32_Update(jcrc, jpg + off, n);
crc_own += cap_cyc() - c0;
if (nrc >= 0 && !serial) { (void)App_NPU_Poll(); }
}
}
jcrc = ~jcrc;
uint32_t u2b = cap_cyc();
if (nrc >= 0 && !serial) { nrc = App_NPU_Finish(&dog, &tc, &tp, &nms); }The JPEG is also encoded and checksummed in a 64 KB stage in on-chip memory, then copied to its send slot once the network has finished. That keeps the external memory free for the network’s weights while the NPU reads them.
The network runs as 32 blocks of layers. Across a 3,018-capture run, the CPU spent a median of 16.3 ms per capture inside the runtime’s step calls, and the NPU sat idle between blocks for about 2 ms per run. After the CRC, the loop waited a median of 7.3 ms for the network to finish.
The sensor now runs at 30 fps, with a line length of 3.0x, and the capture step takes every second frame. In the final bench sample, the network took 51 ms, the CRC 5.4 ms and the whole capture 65.7 ms, for a period of 66.5 ms, which is 15.0 fps. A longer run of the same firmware logged 3,018 captures with a median period of 66.6 ms, 0 overwritten frames and 0 mismatched pipe pairs.
Stage timings at each step
Every number below was measured on the board with the CPU’s cycle counter. All values are in milliseconds. “Per capture” is the median work inside one capture, with all stages added up. “Start to start” is the time from one capture’s start to the next.

• Starting loop: wait and pause 88 · network 47.4 · JPEG 20.6 · CRC 21.3 · send 125.2 · per capture 300 · start to start 1,000 (fixed once a second) · 1 fps
• Step 1, table CRC: CRC 3.7 · per capture 279.8 · start to start about 333 (180 in 60 s) · 3.0 fps
• Step 2, DMA send queue: send 0.002 · per capture 186.2 · start to start 199.9 · 5.0 fps
• Step 3, pipes never stop: wait 3.1 · JPEG 21.7 · per capture 82.7 · start to start 83.2 · 12.0 fps
• Step 4, network overlapped: network 51 · CRC 5.4 · per capture 65.7 · start to start 66.5 · 15.0 fps
The starting loop captured once a second by design, so its 300 ms of work per capture was the limit if it had run back to back. In the first three steps the wait includes pausing the pipes on a frame boundary. The Step 4 wait and JPEG values come from the 3,018-capture run, where the JPEG stage stretches because it also drives the network.

What this lets EverBowl do
EverBowl™ learns who visits the bowl from what its cameras see, and a dog rarely holds still for the camera. Scoring 15 frames per second instead of 3 gives the camera module five times as many chances per visit to recognize the dog in a clear frame. Every frame also carries its own checksum and its network score, so the record shows exactly what was seen and how the module understood it. We share how this plays out in homes in dog identification results from EverBowl cameras.
The honest limit is that these numbers come from our evaluation board and its 3 Mbaud bench link. That link carries about 11 JPEGs per second, so extra frames are dropped and counted, and the module is designed to send only frames its network scores as a dog. EverBowl does not diagnose; the value is the record.
Conclusion
A camera loop on a microcontroller gets fast by doing less in sequence, not by doing each stage faster. Time every stage with the cycle counter first, move sending onto DMA, keep the image pipes running on rotating buffers, and give the NPU work to do while the CPU encodes. Check every claimed frame for overwrites, and count every dropped frame instead of stalling. Our firmware category has more of this work, including on-device audio classification on the same chip. For how we fit a vision model into the same tight memory and int8 limits, read building vision models under hardware constraints.