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.