cancel
Showing results for 
Search instead for 
Did you mean: 

How to change clock source from bootloader to application STM32F439?

AFara.2
Associate II

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

6 REPLIES 6
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
AFara.2
Associate II

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?

TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
AFara.2
Associate II

Ok, I will check HAL drivers from STMCubeMX to ensure they do what RM says about clock source changing.

Thank you.

Regards,

Antonio

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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