Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions boot/zephyr/include/nrf_cleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
31 changes: 30 additions & 1 deletion boot/zephyr/nrf_cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include <hal/nrf_vpr.h>
#include <softperipheral_regif.h>
#endif

#if defined(SPIM_PRESENT)
#include <hal/nrf_spim.h>
#endif

#include <string.h>

Expand Down Expand Up @@ -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. */
Comment on lines +206 to +207
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nrf_cleanup_peripheral() now also stops/disables SPIM, but the public API comment in boot/zephyr/include/nrf_cleanup.h still says it only disables RTC and UARTE. Please update that header comment so the documented behavior matches what the function actually does (and so future additions don’t get missed).

Suggested change
/* Stop SPIM EasyDMA and disable all instances to prevent stale DMA
* from causing RAMACCERR when TF-M reconfigures SPU permissions. */
/* nrf_cleanup_peripheral() also stops SPIM EasyDMA and disables all
* SPIM instances to prevent stale DMA from causing RAMACCERR when
* TF-M reconfigures SPU permissions.
*
* NOTE: Keep the public API comment in boot/zephyr/include/nrf_cleanup.h
* in sync with this function's behavior (RTC, UARTE, SPIM, and any
* future peripherals handled here). */

Copilot uses AI. Check for mistakes.
{
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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in theory code should wait for STOPPED event. Same goes for existing UARTE code. Reference:

The STOP task may not be always needed (the peripheral might already be stopped), but if it is sent, software shall wait until the STOPPED event was received as a response before disabling the peripheral through the ENABLE register.

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
Expand Down
2 changes: 2 additions & 0 deletions docs/release-notes.d/spim-cleanup.md
Original file line number Diff line number Diff line change
@@ -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.
Loading