Skip to content

Instantly share code, notes, and snippets.

View t-moe's full-sized avatar
🦀

Timo t-moe

🦀
  • Bern, Switzerland
View GitHub Profile
@t-moe
t-moe / bootloader.c
Created February 25, 2019 14:36
Jump to DFU bootloader from a stm32f042c6 application that uses usb cdc
#include "stm32f0xx.h"
#include "stm32f0xx_hal_flash.h"
#include "usb_device.h"
// Idea: We want to be able to jump to the bootloader from application
// Problems:
// 1. Once usb is initialized in application mode you cannot reinitialize it from bootloader. Thats why we do a system reset as first step
// 2. The bootloader will immediately jump back to application unless the first page of the flash has been cleared. That's why we erase the first page of the flash before jumping
// 3. Clock and other stuff must be reset before jumping into bootloader. We copied that from the example. See JumpToBootloader code below