Skip to main content
Visitor II
August 24, 2021
Question

How to change clock source from bootloader to application STM32F439?

  • August 24, 2021
  • 4 replies
  • 1832 views

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

    This topic has been closed for replies.

    4 replies

    Super User
    August 24, 2021

    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.

    AFara.2Author
    Visitor II
    August 24, 2021

    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?

    Graduate II
    August 24, 2021

    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.

    AFara.2Author
    Visitor II
    August 25, 2021

    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

    Super User
    August 24, 2021

    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.

    AFara.2Author
    Visitor II
    August 24, 2021

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

    Thank you.

    Regards,

    Antonio