Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BOOT_LED_SWITCH_TO_BOOT
- //#define BOOT_LED_AFTER_UPLOAD
- #ifdef BOOT_LED_SWITCH_TO_BOOT
- // Программа моргает светодиодом подключенным к PD2 5 сек, затем переключатся на апгрейд через загрузчик
- uint32_t counter;
- //*************************************************************************************************
- void SysTick_Init(void){
- SysTick->SR = 0;
- SysTick->CMP = SystemCoreClock-1;
- SysTick->CNT = 0;
- SysTick->CTLR = 0x0F;
- NVIC_EnableIRQ(SysTicK_IRQn);
- }
- //*************************************************************************************************
- void __attribute__((interrupt("WCH-Interrupt-fast")))SysTick_Handler(void){
- SysTick->SR = 0;
- GPIOD->OUTDR ^= GPIO_OUTDR_ODR2;
- counter++;
- }
- //*************************************************************************************************
- void Switch_on_Boot(void){
- // Unlock the ability to write to the MODE flag of STATR register.
- FLASH->BOOT_MODEKEYR = 0x45670123; // KEY1
- FLASH->BOOT_MODEKEYR = 0xCDEF89AB; // KEY2
- // Set to run BOOT flash at next reset (MODE = 1).
- FLASH->STATR = 0x4000;
- // Clear all reset status flags (RMVF = 1).
- RCC->RSTSCKR |= 0x1000000;
- // Perform software reset (KEYCODE = 0xBEEF, RESETSYS = 1).
- PFIC->CFGR = 0xBEEF0080;
- }
- //*************************************************************************************************
- void GPIO_Initialize(void){
- RCC->APB2PCENR |= RCC_APB2Periph_GPIOD;
- //PD2 (GPIO_Mode_OUT_PP)
- GPIOD->CFGLR = (GPIOD->CFGLR & ~(GPIO_CFGLR_CNF2_0 | GPIO_CFGLR_CNF2_1));
- GPIOD->CFGLR |= GPIO_CFGLR_MODE2;
- GPIOD->BSHR = GPIO_BSHR_BS2;
- }
- //*************************************************************************************************
- void main (void){
- GPIO_Initialize();
- SysTick_Init();
- while(1){
- if(counter > 10){
- Switch_on_Boot();
- }
- }
- }
- #endif
- #ifdef BOOT_LED_AFTER_UPLOAD
- // Программа быстро моргает светодиодом подключенным к PD2 в подтверждение того, что произошло обновление прошивки
- uint32_t counter;
- void SysTick_Init(void){
- SysTick->SR = 0;
- SysTick->CMP = SystemCoreClock/20-1;
- SysTick->CNT = 0;
- SysTick->CTLR = 0x0F;
- NVIC_EnableIRQ(SysTicK_IRQn);
- }
- //*************************************************************************************************
- void GPIO_Initialize(void){
- RCC->APB2PCENR |= RCC_APB2Periph_GPIOD;
- //PD2 (GPIO_Mode_OUT_PP)
- GPIOD->CFGLR = (GPIOD->CFGLR & ~(GPIO_CFGLR_CNF2_0 | GPIO_CFGLR_CNF2_1));
- GPIOD->CFGLR |= GPIO_CFGLR_MODE2;
- GPIOD->BSHR = GPIO_BSHR_BS2;
- }
- //*************************************************************************************************
- void __attribute__((interrupt("WCH-Interrupt-fast")))SysTick_Handler(void){
- SysTick->SR = 0;
- GPIOD->OUTDR ^= GPIO_OUTDR_ODR2;
- counter++;
- }
- //*************************************************************************************************
- void main (void){
- GPIO_Initialize();
- SysTick_Init();
- while(1);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement