From a6ff6505fecbc954bb41c72aa5a3377063b31b89 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 24 Feb 2020 19:24:40 +0100 Subject: [PATCH] Boot-loader: Proper reset of all peripherals Otherwise, setting of USB clock prescaler can fail if the clock is already running. --- lib/dfu-bootloader.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/dfu-bootloader.c b/lib/dfu-bootloader.c index 637db2e..bec2c33 100644 --- a/lib/dfu-bootloader.c +++ b/lib/dfu-bootloader.c @@ -339,6 +339,15 @@ int main(void) { usbd_device *usbd_dev; + // Turn off clock to all peripherals and reset them + RCC_AHBENR = 0x00000014; + RCC_APB1ENR = 0; + RCC_APB2ENR = 0; + RCC_APB1RSTR = 0x22fec9ff; + RCC_APB2RSTR = 0x0038fffd; + RCC_APB1RSTR = 0; + RCC_APB2RSTR = 0; + // Flash programming requires running on the internal oscillator my_rcc_clock_setup_in_hsi_out_48mhz(); @@ -346,10 +355,6 @@ int main(void) rcc_periph_clock_enable(RCC_GPIOC); rcc_periph_clock_enable(RCC_USB); - rcc_periph_reset_pulse(RST_GPIOA); - rcc_periph_reset_pulse(RST_GPIOC); - rcc_periph_reset_pulse(RST_USB); - #ifdef DEBUG_USART // Currently, only USART1 is supported rcc_periph_clock_enable(RCC_USART1); -- 2.39.2