diff --git a/README.md b/README.md index f860799..b0b61c6 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ The bootloader can be built to look for arbitrary patterns, but the default for The bootloader currently looks for `0x544F` in RTC backup register 1 and `0x4F42` in RTC backup register 0 (together they spell "BOOT" in ASCII). +You can also use a button to stay in bootloader while booting. It's configured using `HAVE_BUTTON` define. If your button has a debounce capacitor, you can use `BUTTON_SAMPLE_DELAY_CYCLES` define to specify how many cycles to wait before sampling the I/O pin, by default it is approximately 20ms in a 72Mhz MCU. + ### WebUSB This bootloader implements the draft [WebUSB](https://wicg.github.io/webusb/) specification, which allows web pages to access the bootloader (after presenting the user with a device picker dialog). diff --git a/src/stm32f103/generic/config.h b/src/stm32f103/generic/config.h index 9588a6f..960d852 100644 --- a/src/stm32f103/generic/config.h +++ b/src/stm32f103/generic/config.h @@ -33,6 +33,10 @@ #define HAVE_BUTTON 0 #endif +#ifndef BUTTON_SAMPLE_DELAY_CYCLES +#define BUTTON_SAMPLE_DELAY_CYCLES 1440000 +#endif + #ifndef HAVE_USB_PULLUP_CONTROL #define HAVE_USB_PULLUP_CONTROL 0 #endif diff --git a/src/stm32f103/target_stm32f103.c b/src/stm32f103/target_stm32f103.c index 10b07d9..281f1cb 100644 --- a/src/stm32f103/target_stm32f103.c +++ b/src/stm32f103/target_stm32f103.c @@ -161,6 +161,11 @@ bool target_get_force_bootloader(void) { backup_write(BKP0, 0); #if HAVE_BUTTON + /* Wait sometime in case the button has some debounce capacitor */ + int i; + for (i = 0; i < BUTTON_SAMPLE_DELAY_CYCLES; i++) { + __asm__("nop"); + } /* Check if the user button is held down */ if (BUTTON_ACTIVE_HIGH) { if (gpio_get(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN)) {