]> mj.ucw.cz Git - home-hw.git/commitdiff
Boot-loader: Proper reset of all peripherals
authorMartin Mares <mj@ucw.cz>
Mon, 24 Feb 2020 18:24:40 +0000 (19:24 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 24 Feb 2020 18:24:53 +0000 (19:24 +0100)
Otherwise, setting of USB clock prescaler can fail if the clock
is already running.

lib/dfu-bootloader.c

index 637db2eb15540fd5edb45c40a04b1bbffaa3e9e7..bec2c33d0ffeca957809474c9e59748616ffbd83 100644 (file)
@@ -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);