I'd like to do a jump to bootloader from application on STM32 Blue Pill STM32F103C8T6. My approach looks that: - Write to BKP->DR1 any value; - Do a reset (NVIC_SystemReset()); - A the beginning of main, check if BKP->DR1 != 0, than set it to 0 and jump to boot;
Dubugging shows, that core jumps far away (0xfffffffe) and nothing happens. My code:
/*
* bootloader.c
*
* Created on: 28.03.2020
* Author: Admin
*/
#include "stm32f10x.h"
#include "../Logger/logger.h"
#include "core_cm3.h"
#define ADDR 0x1FFFF000
void (*f_boot_jump)();
void boot_jump_to_boot ()
{
f_boot_jump = (void (*)(void)) (*((uint32_t *)(ADDR + 4)));
__disable_irq();
__DSB();
SCB->VTOR = (uint32_t) ADDR;
__DSB();
__ISB();
__set_MSP(*(__IO uint32_t*) ADDR);
f_boot_jump();
}
void boot_init()
{
RCC->APB1ENR |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
PWR->CR |= PWR_CR_DBP;
if (BKP->DR1 != 0) //DR != 0 means, that boot request has been sent
{
BKP->DR1 = 0;
RCC->APB1ENR &= ~RCC_APB1ENR_PWREN;
RCC->APB1ENR &= ~RCC_APB1ENR_BKPEN;
PWR->CR &= ~PWR_CR_DBP;
RCC->CFGR &= ~RCC_CFGR_SW;
RCC->CR &= ~RCC_CR_PLLON;
RCC->CR &= ~RCC_CR_HSEON;
boot_jump_to_boot();
}
}
void boot_write_boot_request()
{
BKP->DR1 = 0x1;
NVIC_SystemReset();
}
I have no idea why it does not work. More over, before jump memory in the area of 0x1FFFF000 looks ok: Before jump
and here is after failing jump to boot: after jump Maybe my chip is fake? ST Utility shows correct values (Device ID, flash size, MediumDensity), but it can means nothing. When I'm using the BOOT pins, the bootloader is loaded properly and STM flashloader recognize it. Even if my chip is a fake, the embedded bootloader works so I can't figure out the reason, why jump from application does not work.