Expand description
Cache maintenance for NPU inference.
Two caches sit between the memories and the compute:
- CACHEAXI (“NPU cache”): a write-back cache on the NPU’s AXI masters,
used for weights/activations in external memory. The peripheral base is
exposed by
stm32-metapac(aspac::CACHEAXI, an opaque*mut ()), but its register block is not currently modelled instm32-data— so the individual registers are still accessed here through a minimal hand-written map (offsets from RM0486 / the STM32N6 CMSIS device header). Clock and reset still go throughpac::RCC. - The Cortex-M55 data cache: when input/output buffers live in
MCU-cacheable memory, the CPU cache must be cleaned before the NPU reads
and invalidated before the CPU reads back results. The generated network
code calls these operations
LL_ATON_Cache_MCU_*— the equivalents here aremcu_clean_range/mcu_invalidate_range.
The functions mirror npu_cache.c + stm32n6xx_hal_cacheaxi.c from the
ST examples.
Functions§
- mcu_
clean_ invalidate_ range - Clean and invalidate the CPU data cache for
[start, start + len). Equivalent ofLL_ATON_Cache_MCU_Clean_Invalidate_Range. - mcu_
clean_ range - Clean (write back) the CPU data cache for
[start, start + len). Equivalent ofLL_ATON_Cache_MCU_Clean_Range. Call after the CPU writes an input buffer and before the NPU reads it. - mcu_
invalidate_ range - Invalidate the CPU data cache for
[start, start + len). Equivalent ofLL_ATON_Cache_MCU_Invalidate_Range. Call after the NPU writes an output buffer and before the CPU reads it. - npu_
cache_ clean_ invalidate_ range - Write back and invalidate an address range in the NPU cache.
Equivalent of
LL_ATON_Cache_NPU_Clean_Invalidate_Range. - npu_
cache_ clean_ range - Write back (clean) an address range from the NPU cache to memory.
Equivalent of
LL_ATON_Cache_NPU_Clean_Range. - npu_
cache_ debug_ state - Raw
(CR1, SR)state for one-time bring-up diagnostics. - npu_
cache_ disable - Disable the NPU cache and gate its clock.
- npu_
cache_ enable - Enable the NPU cache (CACHEAXI): switches on its RCC clock, pulses its
reset and sets the enable bit. The parent NPU clock domain must already
be enabled and released from reset (for example by
super::Npu::new), matching ST’sNPU_Config()ordering. Call once before running inferences that touch cacheable memory pools (external flash / PSRAM). - npu_
cache_ invalidate - Invalidate the entire NPU cache. Blocks until done.
- npu_
cache_ monitor_ reset - Reset and start the CACHEAXI read hit/miss monitors.
- npu_
cache_ read_ counters - Return cumulative CACHEAXI
(read_hits, read_misses)monitor values.