Custom bootloader STM32G051
Hi,
I want to make custom bootloader on STM32G051. I did something, but it does not work well. After jump to the application it get stucked on some address which correspond HAL_Delay function in my application - it looks like the Systick in my app can not geneate interrupt.
A) Bootloader:
The code when I want to jump to the application:
SysTick->CTRL = 0x0;
HAL_DeInit();
__disable_irq();
RCC->CIER = 0x00000000; // Disable all interrupts related to clock
__set_MSP(*((volatile uint32_t*) APP_START_ADDRESS));
__DMB();
SCB->VTOR = APP_START_ADDRESS;
__DSB(); //ARM says to use a DSB instruction just after relocating VTOR *
/* jump to App */
uint32_t JumpAddress = *((volatile uint32_t*) (APP_START_ADDRESS + 4 ));
void (*reset_handler)(void) = (void*)JumpAddress;
reset_handler(); //We start the execution from he Reset_Handler of the main firmware
//Never coming herewhere APP_START_ADDRESS == 0x8005000
also I edited STM32G051C8TX_FLASH.ld :
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 18K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 20K
}Just set Length of Flash to 20K - Because it is the place for bootloader.
B) Application:
I changed also .ld script: I shifted start address of Flash (I tell him that app begins there)
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 18K
FLASH (rx) : ORIGIN = 0x8005000, LENGTH = 64K - 20K /* 20 K id for bootloader */
}When I look at SCB->VTOR in application, the value SCB->VTOR = 0, and the code is stucked on HAL_Delay - Systick does not generate IRQ. When I set in app manually/ or in code SCB->VTOR = APP_START_ADDRESS - then After flashing/debugging, the app Systick start works, but if disconnect it from debug and I reset whole MCU - the Bootloader runs and when occurs condition for jump to App - the bootloader stop runs, but application does not work (probably get again stucked in HAL_Delay)
So please is there any advice what I am doing wrong?
BTW: I do not understand why after launch application debug I get immediatelly to the first line in main.c of app. Because I should be at bootloader earlier (fo 3 seconds ) and after that the bootloader try to jump to the application.
