From fbc8bbf02706a6118e0d120584140808017ebf4c Mon Sep 17 00:00:00 2001 From: Richard Lin Date: Wed, 14 Jun 2023 02:52:53 -0700 Subject: [PATCH 1/2] use in pullup instead of od --- source/hic_hal/stm32/stm32f103xb/DAP_config.h | 11 +++++++---- source/hic_hal/stm32/stm32f103xb/gpio.c | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/hic_hal/stm32/stm32f103xb/DAP_config.h b/source/hic_hal/stm32/stm32f103xb/DAP_config.h index 34013e77d7..331d60b7fc 100644 --- a/source/hic_hal/stm32/stm32f103xb/DAP_config.h +++ b/source/hic_hal/stm32/stm32f103xb/DAP_config.h @@ -260,7 +260,7 @@ __STATIC_INLINE void PORT_SWD_SETUP(void) pin_in_init(SWDIO_IN_PIN_PORT, SWDIO_IN_PIN_Bit, 1); // Set RESET HIGH - pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit);//TODO - fix reset logic + pin_in_init(nRESET_PIN_PORT, nRESET_PIN_Bit, 1); // input with pullup nRESET_PIN_PORT->BSRR = nRESET_PIN; } @@ -436,10 +436,13 @@ __STATIC_FORCEINLINE uint32_t PIN_nRESET_IN(void) __STATIC_FORCEINLINE void PIN_nRESET_OUT(uint32_t bit) { - if (bit & 1) + if (bit & 1) { // set to input pullup mode, since open-drain doesn't support pullup + pin_in_init(nRESET_PIN_PORT, nRESET_PIN_Bit, 1); nRESET_PIN_PORT->BSRR = nRESET_PIN; - else + } else { // set to open-drain mode + pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit); nRESET_PIN_PORT->BRR = nRESET_PIN; + } } //************************************************************************************************** @@ -536,7 +539,7 @@ __STATIC_INLINE void DAP_SETUP(void) pin_in_init(SWDIO_IN_PIN_PORT, SWDIO_IN_PIN_Bit, 1); - pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit); + pin_in_init(nRESET_PIN_PORT, nRESET_PIN_Bit, 1); // input with pullup nRESET_PIN_PORT->BSRR = nRESET_PIN; pin_out_init(CONNECTED_LED_PORT, CONNECTED_LED_PIN_Bit); diff --git a/source/hic_hal/stm32/stm32f103xb/gpio.c b/source/hic_hal/stm32/stm32f103xb/gpio.c index 376cf35817..81358abfcf 100644 --- a/source/hic_hal/stm32/stm32f103xb/gpio.c +++ b/source/hic_hal/stm32/stm32f103xb/gpio.c @@ -157,10 +157,10 @@ void gpio_init(void) GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; HAL_GPIO_Init(PIN_MSC_LED_PORT, &GPIO_InitStructure); - // reset button configured as gpio open drain output with a pullup + // reset button configured as input for pullup, since pullup is not supported with open drain HAL_GPIO_WritePin(nRESET_PIN_PORT, nRESET_PIN, GPIO_PIN_SET); GPIO_InitStructure.Pin = nRESET_PIN; - GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStructure.Mode = GPIO_MODE_INPUT; GPIO_InitStructure.Pull = GPIO_PULLUP; HAL_GPIO_Init(nRESET_PIN_PORT, &GPIO_InitStructure); From 935b431cab54b03ed328298fe71283f630ed8a52 Mon Sep 17 00:00:00 2001 From: Richard Lin Date: Sun, 27 Jul 2025 22:23:25 -0700 Subject: [PATCH 2/2] Update with requested changes --- source/hic_hal/stm32/stm32f103xb/DAP_config.h | 11 ++++------ source/hic_hal/stm32/stm32f103xb/gpio.c | 20 +++++++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/source/hic_hal/stm32/stm32f103xb/DAP_config.h b/source/hic_hal/stm32/stm32f103xb/DAP_config.h index 331d60b7fc..5e54ed1421 100644 --- a/source/hic_hal/stm32/stm32f103xb/DAP_config.h +++ b/source/hic_hal/stm32/stm32f103xb/DAP_config.h @@ -260,7 +260,7 @@ __STATIC_INLINE void PORT_SWD_SETUP(void) pin_in_init(SWDIO_IN_PIN_PORT, SWDIO_IN_PIN_Bit, 1); // Set RESET HIGH - pin_in_init(nRESET_PIN_PORT, nRESET_PIN_Bit, 1); // input with pullup + pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit); nRESET_PIN_PORT->BSRR = nRESET_PIN; } @@ -436,13 +436,10 @@ __STATIC_FORCEINLINE uint32_t PIN_nRESET_IN(void) __STATIC_FORCEINLINE void PIN_nRESET_OUT(uint32_t bit) { - if (bit & 1) { // set to input pullup mode, since open-drain doesn't support pullup - pin_in_init(nRESET_PIN_PORT, nRESET_PIN_Bit, 1); + if (bit & 1) nRESET_PIN_PORT->BSRR = nRESET_PIN; - } else { // set to open-drain mode - pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit); + else nRESET_PIN_PORT->BRR = nRESET_PIN; - } } //************************************************************************************************** @@ -539,7 +536,7 @@ __STATIC_INLINE void DAP_SETUP(void) pin_in_init(SWDIO_IN_PIN_PORT, SWDIO_IN_PIN_Bit, 1); - pin_in_init(nRESET_PIN_PORT, nRESET_PIN_Bit, 1); // input with pullup + pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit); nRESET_PIN_PORT->BSRR = nRESET_PIN; pin_out_init(CONNECTED_LED_PORT, CONNECTED_LED_PIN_Bit); diff --git a/source/hic_hal/stm32/stm32f103xb/gpio.c b/source/hic_hal/stm32/stm32f103xb/gpio.c index 81358abfcf..3c82b4ba15 100644 --- a/source/hic_hal/stm32/stm32f103xb/gpio.c +++ b/source/hic_hal/stm32/stm32f103xb/gpio.c @@ -157,12 +157,20 @@ void gpio_init(void) GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; HAL_GPIO_Init(PIN_MSC_LED_PORT, &GPIO_InitStructure); - // reset button configured as input for pullup, since pullup is not supported with open drain - HAL_GPIO_WritePin(nRESET_PIN_PORT, nRESET_PIN, GPIO_PIN_SET); - GPIO_InitStructure.Pin = nRESET_PIN; - GPIO_InitStructure.Mode = GPIO_MODE_INPUT; - GPIO_InitStructure.Pull = GPIO_PULLUP; - HAL_GPIO_Init(nRESET_PIN_PORT, &GPIO_InitStructure); + #ifdef DAPLINK_BL + // since bootloader checks nRESET_PIN for boot mode, use the pull-up resistor to avoid bootlooping + GPIO_InitStructure.Pin = nRESET_PIN; + GPIO_InitStructure.Mode = GPIO_MODE_INPUT; + GPIO_InitStructure.Pull = GPIO_PULLUP; + HAL_GPIO_Init(nRESET_PIN_PORT, &GPIO_InitStructure); + #else + // reset button configured as gpio open drain output without pullup + HAL_GPIO_WritePin(nRESET_PIN_PORT, nRESET_PIN, GPIO_PIN_SET); + GPIO_InitStructure.Pin = nRESET_PIN; + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStructure.Pull = GPIO_PULLUP; + HAL_GPIO_Init(nRESET_PIN_PORT, &GPIO_InitStructure); + #endif // Turn on power to the board. When the target is unpowered // it holds the reset line low.