// Set GPIO for bootloader Pin status detection
GPIOD->DDR &= ~0x04; // PD2 as Input
GPIOD->CR1 |= 0x04; // PD2 as Pull Up
GPIOD->CR2 &= ~0x04; // no external interrupt
// Detect if bootloader is enabled (pin in high state)
if( (GPIOD->IDR & 0x04) == 0x04 )
{
//if user application is not virgin - valid reset vector jump
if((*((u8 FAR*)MainUserApplication)==0x82) || (*((u8 FAR*)MainUserApplication)==0xAC))
{
//De-init PortD bootloader detection
GPIOD->ODR=0x00;
GPIOD->DDR=0x00;
GPIOD->CR1=0x00;
GPIOD->CR2=0x00;
//reset stack pointer (lower byte - because compiler decreases SP with some bytes)