From: Martin Mares Date: Mon, 24 Feb 2020 18:24:40 +0000 (+0100) Subject: Boot-loader: Proper reset of all peripherals X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=a6ff6505fecbc954bb41c72aa5a3377063b31b89;p=home-hw.git Boot-loader: Proper reset of all peripherals Otherwise, setting of USB clock prescaler can fail if the clock is already running. --- 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);