2023-04-28 05:25 AM
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 here
where 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.
Solved! Go to Solution.
2023-04-28 06:04 AM
OK, it seems it works now I have just reenabled global IRQ before jumping to the application...
2023-04-28 06:04 AM
OK, it seems it works now I have just reenabled global IRQ before jumping to the application...
2023-04-28 01:35 PM
> I do not understand why after launch application debug I get immediatelly to the first line in main.c of app.
The startup address in the debug config is probably set to "default". This tells the debugger to guess the start address based on the app. vector table, and move there as soon as it can. It won't let the bootloader run at all.
If you want to always start from the bootloader, change the vectors address on the startup tab to 0x08000000
2023-05-04 07:26 AM
Thank you, and when I am in application and want to reset MCU via NVIC_SystemReset - it will probably jumps to first line on main in Application, or does it really resets the whole MCU and the bootloader will run?
Eventually how to reset the MCU completely?