From 488e045e8427110d811b89e118910a9c03c61f4c Mon Sep 17 00:00:00 2001 From: Diego Solano Date: Wed, 18 Feb 2026 01:59:52 -0800 Subject: [PATCH] [nrf noup] boot: zephyr: cleanup of SPIM for nRF91 Stop SPIM EasyDMA and disable all instances in nrf_cleanup_peripheral() before chain-loading the application. On nRF91 with TF-M and external SPI flash, MCUboot leaves SPIM active after reading the secondary slot. When TF-M reconfigures SPU SRAM permissions the stale DMA triggers RAMACCERR. This follows the same pattern used for UARTE, RTC, and SQSPI cleanup. Signed-off-by: Diego Solano --- boot/zephyr/include/nrf_cleanup.h | 4 ++-- boot/zephyr/nrf_cleanup.c | 31 +++++++++++++++++++++++++++- docs/release-notes.d/spim-cleanup.md | 2 ++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 docs/release-notes.d/spim-cleanup.md diff --git a/boot/zephyr/include/nrf_cleanup.h b/boot/zephyr/include/nrf_cleanup.h index 8cd8fe3774..dfd9249ffc 100644 --- a/boot/zephyr/include/nrf_cleanup.h +++ b/boot/zephyr/include/nrf_cleanup.h @@ -11,8 +11,8 @@ * Perform cleanup on some peripheral resources used by MCUBoot prior chainload * the application. * - * This function disables all RTC instances and UARTE instances. - * It Disables their interrupts signals as well. + * This function disables all RTC, UARTE, and SPIM instances. + * It disables their interrupts signals as well. */ void nrf_cleanup_peripheral(void); diff --git a/boot/zephyr/nrf_cleanup.c b/boot/zephyr/nrf_cleanup.c index 0177f58371..56c4550f38 100644 --- a/boot/zephyr/nrf_cleanup.c +++ b/boot/zephyr/nrf_cleanup.c @@ -26,7 +26,9 @@ #include #include #endif - +#if defined(SPIM_PRESENT) + #include +#endif #include @@ -200,6 +202,33 @@ void nrf_cleanup_peripheral(void) } #endif +#if defined(SPIM_PRESENT) + /* Stop SPIM EasyDMA and disable all instances to prevent stale DMA + * from causing RAMACCERR when TF-M reconfigures SPU permissions. */ + { + NRF_SPIM_Type *spim_inst[] = { +#if defined(NRF_SPIM0) + NRF_SPIM0, +#endif +#if defined(NRF_SPIM1) + NRF_SPIM1, +#endif +#if defined(NRF_SPIM2) + NRF_SPIM2, +#endif +#if defined(NRF_SPIM3) + NRF_SPIM3, +#endif + }; + + for (int i = 0; i < sizeof(spim_inst) / sizeof(spim_inst[0]); ++i) { + nrf_spim_task_trigger(spim_inst[i], NRF_SPIM_TASK_STOP); + nrf_spim_disable(spim_inst[i]); + nrf_spim_int_disable(spim_inst[i], 0xFFFFFFFF); + } + } +#endif + #if defined(NRF_PPI) nrf_ppi_channels_disable_all(NRF_PPI); #endif diff --git a/docs/release-notes.d/spim-cleanup.md b/docs/release-notes.d/spim-cleanup.md new file mode 100644 index 0000000000..2de2f588fd --- /dev/null +++ b/docs/release-notes.d/spim-cleanup.md @@ -0,0 +1,2 @@ + - Added SPIM peripheral cleanup in nrf_cleanup to prevent RAMACCERR when + TF-M reconfigures SPU SRAM permissions after MCUboot uses SPI flash.