From 9f9b9c3112c5cc47b9376e008e6a8fe5e642d5b4 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Wed, 2 Aug 2023 21:32:46 +0100 Subject: [PATCH] stm32f1/platform: Added a short delay after bringing up the GPIOB controller to get the pin state read to be reliable --- firmware/stm32f1/platform.cxx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firmware/stm32f1/platform.cxx b/firmware/stm32f1/platform.cxx index aca9bb2..2aa1120 100644 --- a/firmware/stm32f1/platform.cxx +++ b/firmware/stm32f1/platform.cxx @@ -3,6 +3,7 @@ #include #include #include +#include #include "platform.hxx" #include "stm32f1.hxx" @@ -87,6 +88,9 @@ bool mustEnterBootloader() noexcept { #if BOOTLOADER_TARGET == BMP rcc.apb2PeriphClockEn |= vals::rcc::apb2PeriphClockEnGPIOPortB; + // Delay a little after powering up the GPIO controller to allow the pin value to stabilise + for ([[maybe_unused]] volatile size_t i : substrate::indexSequence_t{10}) + continue; // If PB12 is low, then either the button is pressed, or the firmware set it low if (!vals::gpio::value(gpioB, vals::gpio_t::pin12)) return true;