aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32/stm32f1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stm32/stm32f1.c')
-rw-r--r--src/stm32/stm32f1.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/stm32/stm32f1.c b/src/stm32/stm32f1.c
index e5defd96..e1ef56aa 100644
--- a/src/stm32/stm32f1.c
+++ b/src/stm32/stm32f1.c
@@ -5,6 +5,8 @@
// This file may be distributed under the terms of the GNU GPLv3 license.
#include "autoconf.h" // CONFIG_CLOCK_REF_8M
+#include "board/irq.h" // irq_disable
+#include "board/usb_cdc.h" // usb_request_bootloader
#include "internal.h" // enable_pclock
#define FREQ_PERIPH (CONFIG_CLOCK_FREQ / 2)
@@ -104,6 +106,21 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup)
AFIO->MAPR = AFIO_MAPR_SWJ_CFG_DISABLE;
}
+// Handle USB reboot requests
+void
+usb_request_bootloader(void)
+{
+ if (!CONFIG_STM32_FLASH_START_2000)
+ return;
+ // Enter "stm32duino" bootloader
+ irq_disable();
+ RCC->APB1ENR |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
+ PWR->CR |= PWR_CR_DBP;
+ BKP->DR10 = 0x01;
+ PWR->CR &=~ PWR_CR_DBP;
+ NVIC_SystemReset();
+}
+
// Main clock setup called at chip startup
void
clock_setup(void)