Insights
Ultrasound DMA Buffers: Verify CPU Visibility After Transfer Completion
Separate DMA completion from CPU visibility in ultrasound acquisition, with an educational cache-state model, platform-specific ownership rules and a proposed OEM verification workflow.
By ALEVA · Orange County, California, USA
An ultrasound acquisition reports DMA completion, yet software occasionally processes samples from the previous capture. Before changing the beamformer, ask a more basic question: does completion mean the processor can see the new bytes? In an embedded acquisition path with a non-coherent DMA engine and a data cache, transport completion and CPU visibility are separate conditions.
Two views of one buffer
A December 2025 STMicroelectronics technical article describes both directions of this problem. CPU writes can remain in a write-back cache while a DMA engine reads older SRAM contents. Conversely, a DMA engine can update SRAM while the CPU retains an older cached copy [1]. This is vendor engineering guidance, not a peer-reviewed ultrasound study or evidence that any particular ALEVA product uses that processor family.
Consider a deliberately small educational model. Shared memory and a CPU cache initially contain capture A: [10, 11, 12, 13]. DMA replaces shared memory with capture B: [20, 21, 22, 23], but the model leaves the cache unchanged. A CPU read through that valid cached copy still returns A. After invalidation and a subsequent refill from memory, the read returns B. There is no modeled packet loss or arithmetic error: the mismatch comes entirely from which copy is read. The accompanying diagram is a conceptual state model, not a hardware timing trace.
Define the handover for each direction
Zephyr's cache guide distinguishes flushing modified cache lines to shared memory from invalidating cached lines before reading peripheral-written data. It also discusses uncached regions and the danger of unrelated objects sharing a line [2]. For an ultrasound integration, specify the producer, consumer, memory region and ownership transition for every payload and descriptor. Do not assume that choosing a DMA driver settles these requirements: Zephyr explicitly leaves cache coherency to the developer in general [3].
For CPU-produced data that a device will read, make the completed writes visible through the platform's documented synchronization procedure before handing over ownership. For device-produced receive data, prepare the destination using that platform's required pre-transfer procedure, prevent conflicting CPU access while the device owns it, establish transfer completion, then perform the required synchronization for CPU access. In a manually maintained non-coherent cache, this may include pre-transfer maintenance as well as invalidation before CPU consumption. A single invalidate call after an interrupt is not a complete portable receive protocol.
The handover also covers metadata. A descriptor with a fresh completion flag does not prove that its payload is visible, and a new payload does not establish that its length, channel identity or generation counter is current. Keep the contract explicit at both boundaries.
Keep cache lines out of the ownership dispute
ST's 2025 discussion compares non-cacheable regions, write-through policy and software-managed write-back caching. Write-through can simplify the CPU-write direction, but it does not remove stale CPU reads of DMA-written data [1]. Select a policy for the actual memory and bus path rather than copying another board's configuration.
The Linux DMA guide documents a related hazard: CPU-written fields and device-written buffers sharing a cache line can corrupt one another on non-coherent systems. It also distinguishes CPU addresses from DMA addresses and provides mapping and synchronization interfaces for drivers [4]. Linux driver code should use those supported interfaces rather than transplanting a microcontroller cache-maintenance sequence. Hardware-coherent mappings reduce some visibility work, but they do not eliminate ownership, ordering or premature-reuse errors.
For a concrete layout exercise, assume a hypothetical 32-byte cache line. A 48-byte payload beginning on a line boundary occupies two lines, covering 64 bytes of line storage. The remaining 16 bytes must not become independently modified metadata that conflicts with maintenance of the payload. This is allocation arithmetic, not a recommendation that every processor has a 32-byte line. Record the target's actual line size, allocation span and alignment requirements.
Test data identity, not only image plausibility
We propose a focused OEM verification exercise. Drive the acquisition transport with a deterministic sequence that changes on every buffer generation, and make each channel distinguishable. Compare the bytes seen by the intended CPU consumer against the expected generation before reconstruction. Use buffers with known alignment and separately allocated guard regions; record any mismatch rather than allowing the display to conceal it.
Repeat the exercise with cold and warm caches, permitted buffer lengths around line boundaries, delayed consumers and repeated buffer reuse. Include completion, cancellation and restart paths. Exercise production memory attributes and build settings, and record the processor, board, firmware, driver and DMA configuration. These are proposed tests; passing them is evidence for the tested paths and conditions, not proof that every concurrency interleaving has been covered.
Distinguish stale data from dropped data. A correct checksum over the wrong buffer generation can still pass. Use capture identity and byte-level expectations together, and retain enough event information to locate the ownership transition that failed. This complements observable capture-loss accounting and the separate problem of GPU buffer lifetime; those mechanisms do not automatically establish CPU–DMA cache visibility.
The OEM decision
An uncached receive region may simplify reasoning but increase CPU access cost. Explicit cache maintenance preserves caching opportunities while adding implementation and verification work [2]. Benchmark the complete acquisition-to-consumer path under the selected policy, including synchronization and copying. A fast DMA transfer in isolation is not the acceptance criterion.
For an ultrasound engine integration, the useful deliverable is a documented memory-ownership contract with reproducible tests: who can access each region, when ownership changes, how visibility is established, and what the system does when a generation is incomplete. That contract helps separate a transport integration fault from an apparent imaging-algorithm defect.
Sources and scope
This article applies public embedded-software guidance to a proposed ultrasound OEM verification workflow. No directly applicable new 2026 peer-reviewed ultrasound experiment was established in the source search. The state model and layout arithmetic are educational examples.
STMicroelectronics, Ruchit N. How to use the memory protection unit to manage cache coherency on high-performance MCUs, December 15, 2025. Vendor technical guidance.
Zephyr Project. Caching Basics, rolling latest documentation, accessed November 22, 2026; not a version-pinned product requirement.
Zephyr Project. Direct Memory Access (DMA), rolling latest documentation, accessed November 22, 2026.
Linux Kernel documentation. Dynamic DMA mapping Guide, rolling documentation, accessed November 22, 2026. Applicable APIs depend on the actual kernel and platform.