From 941538351c37cdb522662df24d0928171dcca3d6 Mon Sep 17 00:00:00 2001 From: Daniel Serpell Date: Thu, 16 Apr 2020 23:43:24 -0400 Subject: [PATCH 1/2] Allow configuring button pull-ups in each target. --- src/stm32f103/target_stm32f103.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/stm32f103/target_stm32f103.c b/src/stm32f103/target_stm32f103.c index d03f2c2..7c25942 100644 --- a/src/stm32f103/target_stm32f103.c +++ b/src/stm32f103/target_stm32f103.c @@ -45,6 +45,10 @@ #define USES_GPIOC 0 #endif +#ifndef BUTTON_USES_PULL +#define BUTTON_USES_PULL 1 +#endif + #ifdef FLASH_SIZE_OVERRIDE _Static_assert((FLASH_BASE + FLASH_SIZE_OVERRIDE >= APP_BASE_ADDRESS), "Incompatible flash size"); @@ -95,12 +99,15 @@ void target_gpio_setup(void) { #if HAVE_BUTTON { const uint8_t mode = GPIO_MODE_INPUT; - const uint8_t conf = GPIO_CNF_INPUT_PULL_UPDOWN; + const uint8_t conf = (BUTTON_USES_PULL ? GPIO_CNF_INPUT_PULL_UPDOWN + : GPIO_CNF_INPUT_FLOAT); gpio_set_mode(BUTTON_GPIO_PORT, mode, conf, BUTTON_GPIO_PIN); - if (BUTTON_ACTIVE_HIGH) { - gpio_clear(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN); - } else { - gpio_set(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN); + if (BUTTON_USES_PULL) { + if (BUTTON_ACTIVE_HIGH) { + gpio_clear(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN); + } else { + gpio_set(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN); + } } } #endif From 7595c1520ccd7942b26b3a34665e08ef6e3db4bb Mon Sep 17 00:00:00 2001 From: Daniel Serpell Date: Thu, 16 Apr 2020 23:44:57 -0400 Subject: [PATCH 2/2] bluepill: Use the BOOT1 input in to enter the bootloader. The bluepill board has a dip-switch connected to BOOT1 (PB2) via a 100k resistor. Enter the bootloader when connecting this to "1". --- src/stm32f103/bluepill/config.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/stm32f103/bluepill/config.h b/src/stm32f103/bluepill/config.h index 28677e2..c0df9e0 100644 --- a/src/stm32f103/bluepill/config.h +++ b/src/stm32f103/bluepill/config.h @@ -49,7 +49,20 @@ #endif #ifndef HAVE_BUTTON -#define HAVE_BUTTON 0 +#define HAVE_BUTTON 1 +#endif +#ifndef BUTTON_ACTIVE_HIGH +#define BUTTON_ACTIVE_HIGH 1 +#endif +#ifndef BUTTON_GPIO_PORT +#define BUTTON_GPIO_PORT GPIOB +#endif +#ifndef BUTTON_GPIO_PIN +#define BUTTON_GPIO_PIN GPIO2 +#endif +// Blue-Pull has 100k resistors on PB2, so we can't use weak pulls to read it. +#ifndef BUTTON_USES_PULL +#define BUTTON_USES_PULL 0 #endif #ifndef BUTTON_SAMPLE_DELAY_CYCLES @@ -60,6 +73,10 @@ #define HAVE_USB_PULLUP_CONTROL 0 #endif +#ifndef USES_GPIOB +#define USES_GPIOB 1 +#endif + #ifndef USES_GPIOC #define USES_GPIOC 1 #endif