boot.c 495 B

12345678910111213141516171819
  1. #include "boot.h"
  2. #include "stm32l4xx_ll_bus.h"
  3. #include "stm32l4xx_ll_rcc.h"
  4. #include "stm32l4xx_ll_rtc.h"
  5. #include "stm32l4xx_ll_pwr.h"
  6. #define BOOT_REQUEST_DFU 0xDF00B000
  7. void boot_restart_in_dfu() {
  8. // Request DFU on boot
  9. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
  10. LL_PWR_EnableBkUpAccess();
  11. // Enable RTC
  12. LL_RCC_EnableRTC();
  13. // Write backup registry
  14. LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_DFU);
  15. // Reset
  16. NVIC_SystemReset();
  17. }