8000 stm32/modmachine: In bootloader() disable caches before reset of periphs · devmonkZA/micropython@66bcb55 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66bcb55

Browse files
pi-anldpgeorge
authored andcommitted
stm32/modmachine: In bootloader() disable caches before reset of periphs
Otherwise flushing and disabling the D-cache will give a hard-fault when SDRAM is used. Fixes micropython#4818.
1 parent 019dd84 commit 66bcb55

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

ports/stm32/modmachine.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args)
265265
storage_flush();
266266
#endif
267267

268+
#if __DCACHE_PRESENT == 1
269+
// Flush and disable caches before turning off peripherals (eg SDRAM)
270+
SCB_DisableICache();
271+
SCB_DisableDCache();
272+
#endif
273+
268274
HAL_RCC_DeInit();
269275
HAL_DeInit();
270276

@@ -276,10 +282,6 @@ STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args)
276282
#if MICROPY_HW_USES_BOOTLOADER
277283
if (n_args == 0 || !mp_obj_is_true(args[0])) {
278284
// By default, with no args given, we enter the custom bootloader (mboot)
279-
#if __DCACHE_PRESENT == 1
280-
SCB_DisableICache();
281-
SCB_DisableDCache();
282-
#endif
283285
branch_to_bootloader(0x70ad0000, 0x08000000);
284286
}
285287

@@ -289,10 +291,6 @@ STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args)
289291
const char *data = mp_obj_str_get_data(args[0], &len);
290292
void *mboot_region = (void*)*((volatile uint32_t*)0x08000000);
291293
memmove(mboot_region, data, len);
292-
#if __DCACHE_PRESENT == 1
293-
SCB_DisableICache();
294-
SCB_DisableDCache();
295-
#endif
296294
branch_to_bootloader(0x70ad0080, 0x08000000);
297295
}
298296
#endif

0 commit comments

Comments
 (0)
0