Skip to content

Commit f5dc201

Browse files
matthijskooijmanfpistm
authored andcommitted
Override Reset_Handler to jump to bootloader
1 parent 618bfaa commit f5dc201

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

cores/arduino/stm32/startup_stm32yyxx.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
#if defined(CMSIS_STARTUP_FILE)
44
#include CMSIS_STARTUP_FILE
55
#endif
6+
7+
# Expose Reset_Handler under a different name, to allow overriding it
8+
# with a strong symbol and then calling the original.
9+
.global Original_Reset_Handler
10+
.thumb_set Original_Reset_Handler,Reset_Handler

libraries/SrcWrapper/src/stm32/bootloader.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/* Private definitions to manage system memory address */
1414
#define SYSMEM_ADDR_COMMON 0xFFF
1515

16-
static bool BootIntoBootloaderAfterReset __attribute__((__section__(".noinit")));
16+
static bool BootIntoBootloaderAfterReset;
1717

1818
typedef struct {
1919
uint32_t devID;
@@ -87,6 +87,18 @@ WEAK void jumpToBootloaderRequested(void)
8787
NVIC_SystemReset();
8888
}
8989

90+
// This overrides the Reset_Handler that is run on reset before
91+
// *anything* else (including memory initialization). Only the stack
92+
// pointer is set up by this time.
93+
void Reset_Handler()
94+
{
95+
// Jump to the bootloader if needed.
96+
jumpToBootloader();
97+
98+
// Continue with regular startup by calling the original reset handler
99+
Original_Reset_Handler();
100+
}
101+
90102
/* Jump to system memory boot from user application */
91103
WEAK void jumpToBootloader(void)
92104
{

libraries/SrcWrapper/src/stm32/hw_config.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ void hw_config_init(void)
6060
/* Initialize the HAL */
6161
HAL_Init();
6262

63-
/* Check if a jump to system memory boot requested */
64-
jumpToBootloader();
65-
6663
/* Configure the system clock */
6764
SystemClock_Config();
6865

0 commit comments

Comments
 (0)