arch/arm/nrf53: enable the application core CACHE peripheral - #20005
Open
AlmAck wants to merge 1 commit into
Open
arch/arm/nrf53: enable the application core CACHE peripheral#20005AlmAck wants to merge 1 commit into
AlmAck wants to merge 1 commit into
Conversation
AlmAck
requested review from
jerpelea,
raiden00pl,
simbit18 and
xiaoxiang781216
as code owners
August 29, 2026 19:08
xiaoxiang781216
approved these changes
Aug 30, 2026
Contributor
|
Hi @AlmAck, please rebase |
The nRF5340 application core comes out of reset with its flash cache disabled and nothing in the tree turns it on. nrf53_start() does call nrf53_enable_icache(), but that drives NVMC ICACHECNF and is gated on NRF53_FLASH_PREFETCH, which depends on NRF53_NETCORE -- so it is not even compiled for an application core build. The nRF5340 places the application core cache in a separate CACHE peripheral at 0x50001000. NRF53_CACHE_BASE is already defined in hardware/nrf53_memorymap_cpuapp.h, but there was no register header and no enable. Add both, behind a new NRF53_CACHE option. The option defaults to n, matching ARMV7M_ICACHE and ARMV8M_ICACHE/DCACHE, so that upgrading does not silently change the behaviour of an existing configuration. Measured on nrf5340-dk at 64 MHz with apps/benchmarks/scbench: protected-build syscall round trip 64.1 us -> 29.6 us userspace sem wait + post pair 4.75 us -> 1.95 us Flat builds benefit equally; the gain is on any flash-resident code path. Per the nRF5340 Product Specification, 'CACHE - Instruction and data cache', 'both instruction and data accesses towards flash memory or XIP code regions are cached'. The cache does not observe NVMC programming, so nrf53_flash.c has to account for it: both up_progmem_eraseblock() and up_progmem_write() read back what they just programmed to verify it, and up_progmem_ispageerased() reads a whole page, so lines covering the region being programmed are commonly resident. Bypass the cache for the duration of an erase or a write and invalidate it before re-enabling, so the verify reads the array and later readers do too. That file is built only when NRF53_PROGMEM is selected, which is not the default. Signed-off-by: AlmAck <gluca86@gmail.com>
AlmAck
force-pushed
the
fix/nrf53-enable-appcore-cache
branch
from
August 30, 2026 18:07
34f4aa3 to
49e0fe1
Compare
xiaoxiang781216
approved these changes
Aug 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The nRF5340 application core comes out of reset with its flash cache
disabled and nothing in the tree turns it on.
nrf53_start()does callnrf53_enable_icache(), but that drives NVMCICACHECNFand is gated onNRF53_FLASH_PREFETCH, whichdepends on NRF53_NETCOREso it is noteven compiled for an application core build.
The nRF5340 places the application core cache in a separate CACHE
peripheral at
0x50001000.NRF53_CACHE_BASEis already defined inhardware/nrf53_memorymap_cpuapp.h, but there was no register header andno enable. This adds both, behind a new
NRF53_CACHEoption(
depends on NRF53_APPCORE,default y).New Kconfig option, a new register header, one write at startup, and a
bypass/invalidate around the two progmem operations. The option defaults to n, matching ARMV7M_ICACHE and ARMV8M_ICACHE/DCACHE, so that upgrading does not silently change the behaviour of an existing configuration.
Cache coherency with the progmem driver
Per the nRF5340 Product Specification, CACHE Instruction and data
cache:
The cache does not observe NVMC programming, so enabling it has a
consequence for
arch/arm/src/nrf53/nrf53_flash.c:up_progmem_eraseblock()verifies viaup_progmem_ispageerased(),which reads the whole page, populating cache lines over exactly the
region being programmed.
up_progmem_write()reads back every word it writes to verify it.A line held from before the operation would satisfy those read-backs, so
the verify could pass or fail on stale data. This patch therefore
bypasses the cache for the duration of an erase or a write and
invalidates it before re-enabling, so the verify sees the array and
later readers do too.
nrf53_flash.cis built only whenNRF53_PROGMEMis selected, which isnot the default.
Testing
Host: Linux x86_64, arm-none-eabi GCC 14.
Board: nrf5340-dk, cpuapp, at 64 MHz.
Measured with
apps/benchmarks/scbenchbefore and after the patch, samebinary otherwise:
Both a flat build and a
CONFIG_BUILD_PROTECTEDbuild were exercised.The application (LVGL rendering to an SPI display, LittleFS on QSPI NOR,
BLE active) behaves identically apart from being faster; flash is not
written during normal operation, so no coherency issue arises.