nRF5340: SPSC ring buffers across the application and the network core (2026-11-17)
Plan item 2a (lab/plans/2026-11-16-mp-bundle-and-open-areas.md). The
second dual-core case after the RP2350's SMP mode, and an asymmetric one:
the application core (Cortex-M33, 64 MHz) and the network core (Cortex-M33,
64 MHz, no DSP extension) share the application core's RAM, each running
the library's code from its own flash.
The chip, first (firmware/nrf5340-net-probe/)
- The network core runs once the application firmware gives it secure access to application RAM (SPU EXTDOMAIN[0].PERM) and releases it (RESET.NETWORK.FORCEOFF); it sees application RAM at the same addresses.
- LDREX/STREX is not atomic between the two cores. Both cores adding 1
to the same word a million times with
__atomic_fetch_add: 1515613 to 1572657 instead of 2000000 in four runs. So a library that needs a read-modify-write atomic on a word both cores change cannot work across the two cores of an nRF5340; that is the chip, not the library. (It fits the nRF5340 having a MUTEX peripheral for locks between its cores; to be checked against the product specification.) - The network core has no DSP extension: code built for the application core's M33 used UXTAH in pxq and Zephyr and faulted there. This test builds everything without DSP and fails the build if a DSP instruction is in the network core's image.
- The network core is locked to the debugger after every reset of the application core (hardened APPROTECT): writing it needs an erase of both cores' flash, so its image is written only when it changes.
Test (firmware/rb-xcore-stress/)
Producer on one core, consumer on the other, both directions; the library object at the same address in both images (checked at build time, 32 symbols); random pauses on both sides, fast and slow phases. One library per reset over the serial port. Libraries: those documented for several cores or threads (the RP2350 SMP set), pxq for information (a single-core design), and the ISR test's broken buffer with its SMP window as the control. Firmware commit 7a3d248.
Result: 300000 bytes per library and direction
| Single bytes | Blocks (1-16 / 1-4) | |
|---|---|---|
| 15 libraries documented for several cores (lwrb, jnk0le, ETL atomic, QP LFRB, micoring, kostyk348 lf_spsc, diffstorm, rigtorp, polycratia, rt-spsc, Zephyr CONFIG_SMP, DNedic lockfree spsc, moodycamel, heapless spsc, bbqueue) | 0 errors, both directions | 0 errors, both directions |
| pxq RingBuffer_PackedState ⚠ (not counted) | 0 errors | 0 errors |
| control (broken, SMP window) | 274 / 68708 errors | 329 / 14918 errors |
- No library documented for several cores lost, repeated or reordered a byte, in either direction, with single bytes or blocks.
- bbqueue's atomic flavour uses read-modify-write atomics, which are not atomic across these cores; in SPSC use no word is changed by both cores at once, so it is not affected here (it would be in a use where both cores modify the same word).
- pxq passed too, but it is a single-core design (interrupt masking) and does not promise to work across cores; its result is reported, not counted. ⚠ pxq is the project owner's library.
Not covered yet
- Longer runs and campaigns; code in RAM; the application core at 128 MHz (different speeds of the two cores).
- MPMC/MPSC libraries across the cores: expected to fail where they need compare-and-swap on a word both cores change (the chip's limit above); not run as library results.
- A bundle: the application image is one image with all libraries (the shared layout must match the network core's single image).
Records: ~/lab-runs/xcore-20261117/ (lib-lab1).