Skip to content

Commit 0b53f87

Browse files
committed
[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 <diego@thalo.com>
1 parent 97806cd commit 0b53f87

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

boot/zephyr/nrf_cleanup.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
#include <hal/nrf_vpr.h>
2727
#include <softperipheral_regif.h>
2828
#endif
29-
29+
#if defined(SPIM_PRESENT)
30+
#include <hal/nrf_spim.h>
31+
#endif
3032

3133
#include <string.h>
3234

@@ -200,6 +202,33 @@ void nrf_cleanup_peripheral(void)
200202
}
201203
#endif
202204

205+
#if defined(SPIM_PRESENT)
206+
/* Stop SPIM EasyDMA and disable all instances to prevent stale DMA
207+
* from causing RAMACCERR when TF-M reconfigures SPU permissions. */
208+
{
209+
NRF_SPIM_Type *spim_inst[] = {
210+
#if defined(NRF_SPIM0)
211+
NRF_SPIM0,
212+
#endif
213+
#if defined(NRF_SPIM1)
214+
NRF_SPIM1,
215+
#endif
216+
#if defined(NRF_SPIM2)
217+
NRF_SPIM2,
218+
#endif
219+
#if defined(NRF_SPIM3)
220+
NRF_SPIM3,
221+
#endif
222+
};
223+
224+
for (int i = 0; i < sizeof(spim_inst) / sizeof(spim_inst[0]); ++i) {
225+
nrf_spim_task_trigger(spim_inst[i], NRF_SPIM_TASK_STOP);
226+
nrf_spim_disable(spim_inst[i]);
227+
nrf_spim_int_disable(spim_inst[i], 0xFFFFFFFF);
228+
}
229+
}
230+
#endif
231+
203232
#if defined(NRF_PPI)
204233
nrf_ppi_channels_disable_all(NRF_PPI);
205234
#endif

0 commit comments

Comments
 (0)