From fe968ed75a29130ff50e26b1a65839465aa0904f Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Mon, 16 Nov 2026 16:01:10 +0000 Subject: [PATCH] Align STM32F103 init hooks (#26579) --- builddefs/common_rules.mk | 2 +- .../boards/STM32_F103_STM32DUINO/board/board.c | 12 ++++-------- .../boards/STM32_F103_STM32DUINO/configs/config.h | 4 ++++ platforms/chibios/bootloaders/stm32duino.c | 3 +++ .../protocol => platforms}/chibios/init_hooks.h | 3 +++ 5 files changed, 15 insertions(+), 9 deletions(-) rename {tmk_core/protocol => platforms}/chibios/init_hooks.h (73%) diff --git a/builddefs/common_rules.mk b/builddefs/common_rules.mk index 282cc6c6566..0962073379d 100644 --- a/builddefs/common_rules.mk +++ b/builddefs/common_rules.mk @@ -175,7 +175,7 @@ MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@) # For a ChibiOS build, ensure that the board files have the hook overrides injected define BOARDSRC_INJECT_HOOKS -$(INTERMEDIATE_OUTPUT)/$(patsubst %.c,%.o,$(patsubst ./%,%,$1)): FILE_SPECIFIC_CFLAGS += -include $(TOP_DIR)/tmk_core/protocol/chibios/init_hooks.h +$(INTERMEDIATE_OUTPUT)/$(patsubst %.c,%.o,$(patsubst ./%,%,$1)): FILE_SPECIFIC_CFLAGS += -include $(TOP_DIR)/platforms/chibios/init_hooks.h endef $(foreach LOBJ, $(BOARDSRC), $(eval $(call BOARDSRC_INJECT_HOOKS,$(LOBJ)))) diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c b/platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c index e82e1d37cec..c1c07a8313f 100644 --- a/platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c +++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c @@ -34,16 +34,12 @@ const PALConfig pal_default_config = }; #endif -__attribute__((weak)) void enter_bootloader_mode_if_requested(void) {} - /* * Early initialization code. * This initialization must be performed just after stack setup and before * any other initialization. */ void __early_init(void) { - enter_bootloader_mode_if_requested(); - stm32_clock_init(); } @@ -51,8 +47,8 @@ void __early_init(void) { * Board-specific initialization code. */ void boardInit(void) { - //JTAG-DP Disabled and SW-DP Enabled - AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE; - //Set backup register DR10 to enter bootloader on reset - BKP->DR10 = RTC_BOOTLOADER_FLAG; + //JTAG-DP Disabled and SW-DP Enabled + AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE; + //Set backup register DR10 to enter bootloader on reset + BKP->DR10 = RTC_BOOTLOADER_FLAG; } diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/configs/config.h b/platforms/chibios/boards/STM32_F103_STM32DUINO/configs/config.h index d8b852cab7e..0667ecfa471 100644 --- a/platforms/chibios/boards/STM32_F103_STM32DUINO/configs/config.h +++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/configs/config.h @@ -2,6 +2,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once +#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP +# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE +#endif + // Value to place in RTC backup register 10 for persistent bootloader mode #define RTC_BOOTLOADER_FLAG 0x424C diff --git a/platforms/chibios/bootloaders/stm32duino.c b/platforms/chibios/bootloaders/stm32duino.c index cc3f6be2dfd..b489f532140 100644 --- a/platforms/chibios/bootloaders/stm32duino.c +++ b/platforms/chibios/bootloaders/stm32duino.c @@ -26,3 +26,6 @@ __attribute__((weak)) void mcu_reset(void) { BKP->DR10 = RTC_BOOTLOADER_JUST_UPLOADED; NVIC_SystemReset(); } + +/* not needed by default, no two-stage reset */ +__attribute__((weak)) void enter_bootloader_mode_if_requested(void) {} diff --git a/tmk_core/protocol/chibios/init_hooks.h b/platforms/chibios/init_hooks.h similarity index 73% rename from tmk_core/protocol/chibios/init_hooks.h rename to platforms/chibios/init_hooks.h index fffced913a6..a39e975f0ac 100644 --- a/tmk_core/protocol/chibios/init_hooks.h +++ b/platforms/chibios/init_hooks.h @@ -1,3 +1,6 @@ +// Copyright 2020 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once // Override the initialisation functions inside the ChibiOS board.c files