#include "system.h"
#include "usb.h"
#include "usb_util.h"

void System_EnterBootloader(void)
{
    USB_Disable();
    USB_Delay(100000);

    // Set bootloader magic value in RTC backup register
    RCC->APB1ENR |= RCC_APB1ENR_BKPEN | RCC_APB1ENR_PWREN;
    PWR->CR = PWR_CR_DBP;
    BKP->DR1 = 0xb007;

    // Initiate software reset
    NVIC_SystemReset();
}
