2021-08-24 04:27 AM
Hi,
I'm pretty sure it can be done but I would like confirmation.
I would like to start with my own bootloader that runs wit HSI clock. It have to properly configure an external PLL source (by I2C peripheral). Only when that chip is locked, I would like to jump into another internal flash branch to run my own application. First of all the application will select the nwe HSE as main clock source. Is it possible?
Thank you,
Antonio
2021-08-24 11:09 AM
The clock source can be changed at will.
There are restrictions for how to change the clock source discussed in the RM. Wait states need to be increased prior to increasing clock speed, PLL needs to not be used before changing it, etc.
2021-08-24 01:24 PM
Ok, I read in RM what you said. Both in bootloader and in application I start with a STMCubeMX code. Does it ensure me to automatically respect those restrictions?
2021-08-24 01:47 PM
HAL does what it can to ensure the transition is done correctly. There may be issues that you will need to debug if/when they are encountered.
2021-08-24 02:35 PM
Ok, I will check HAL drivers from STMCubeMX to ensure they do what RM says about clock source changing.
Thank you.
Regards,
Antonio
2021-08-24 02:38 PM
Many of us write code without CubeMX. The App should be configured to use HSE. For the Loader you're going to want to select HSI, and clean up all the code to deal with you specific/unique configuration.
The transitional code should perhaps be handled in SystemInit() via startup.s, but ST typically does it at an application level these days in SystemClock_Config()
When building separate stages, ie loader / application, you need to watch the base address each is linked at, and the vector table via SCB->VTOR usually set in SystemInit() points at the appropriate address.
2021-08-25 01:06 AM
Hi,
yes my app is configured to use HSE after jump from my own bootloader (that uses HSI clock). Both in boot and in app the clock configuration is made by SystemClock_Config() immediately after HAL_Init(). I make the jump as shown below, is it correct?
void Bootloader_JumpToApplication(void){
uint32_t JumpAddress = *(__IO uint32_t*)(APP_ADDRESS + 4);
pFunction Jump = (pFunction)JumpAddress;
HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
#if(SET_VECTOR_TABLE)
SCB->VTOR = APP_ADDRESS;
#endif
__set_MSP(*(__IO uint32_t*)APP_ADDRESS);
Jump();
}
APP_ADDRESS is my app internal flash address. Obviously my bootloader starts from internal flash start point.
Thank you.
Antonio