Skip to content

Commit 83ca6ee

Browse files
committed
Moved bootloader entry earlier from Reset handler
Make sure system clocks or anything else is not yet initialized before calling ROM bootloader
1 parent fe2e243 commit 83ca6ee

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

Diff for: cores/arduino/Reset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C" {
2525

2626
#define RESET_TO_BOOTLOADER_MAGIC_CODE 0xDEADBEEF
2727

28-
uint32_t reset_to_bootloader_magic __attribute__ ((section (".noinit")));
28+
uint32_t reset_to_bootloader_magic;
2929

3030
void checkBoot()
3131
{

Diff for: cores/arduino/stm32/clock.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ void SysTick_Handler(void)
8484
{
8585
HAL_IncTick();
8686
HAL_SYSTICK_IRQHandler();
87-
osSystickHandler();
8887
tickReset();
88+
osSystickHandler();
8989
}
9090

9191
/**

Diff for: cores/arduino/stm32/hw_config.c

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
*/
5151
void hw_config_init(void)
5252
{
53-
checkBoot();
54-
5553
//Initialize the HAL
5654
HAL_Init();
5755

Diff for: cores/arduino/stm32/startup_stm32yyxx.S

+13
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,16 @@
22

33
#include CMSIS_STARTUP_FILE
44

5+
/* Bootloader entry check done early at reset (then jump into original entry point) */
6+
7+
.section .text.Boot_Reset_Handler
8+
.type Boot_Reset_Handler, %function
9+
.thumb_set Reset_Handler,Boot_Reset_Handler
10+
Boot_Reset_Handler:
11+
ldr sp, =_estack /* Atollic update: set stack pointer */
12+
bl checkBoot
13+
/* Copy the data segment initializers from flash to SRAM */
14+
movs r1, #0
15+
b LoopCopyDataInit /* Jump to original Reset_Handler */
16+
17+
.size Boot_Reset_Handler, .-Boot_Reset_Handler

0 commit comments

Comments
 (0)