cancel
Showing results for 
Search instead for 
Did you mean: 

External STM32 flash loader fails initialization on calling LL_SetSystemCoreClock()

SFlac.1
Associate

I implemented a STM32 flash loader for an external spi flash. As you can see in the STM32CubeProgrammer log (appendix), the write sequence always fails.

After long time debugging i tracked the issue down to the function call:

LL_SetSystemCoreClock(64000000);

My whole init code:

int Init (void)
{  
    
    // Clear the reset flags
    LL_RCC_ClearResetFlags();
    
    // Enable SYSCFG and PWR Peripheral Clock
    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
    
    /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral */
    LL_SYSCFG_DisableDBATT(LL_SYSCFG_UCPD1_STROBE | LL_SYSCFG_UCPD2_STROBE);
    
    // -------------------------------------------------------------------------------
    
    LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
    while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1) {}       
    
    
    /* HSI configuration and activation */
    LL_RCC_HSI_Enable();
    while(LL_RCC_HSI_IsReady() != 1) {}
 
    /* LSI configuration and activation */
    LL_RCC_LSI_Enable();
    while(LL_RCC_LSI_IsReady() != 1) {}   
        
    /* Set HSI Clock as PLL Source and set SYSCLK to 64 MHz */
    LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 8, LL_RCC_PLLR_DIV_2);
    LL_RCC_PLL_Enable();
    LL_RCC_PLL_EnableDomain_SYS();
    while(LL_RCC_PLL_IsReady() != 1) {}
    
    /* HCLK = 64 MHz */
    LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
 
    /* Sysclk activation on the main PLL */
    LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
    while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {}    
    
    /* PCLK = 100 MHz */
    LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
        
    /* Setup Sys Tick */
//    LL_Init1msTick(64000000);
//    LL_SetSystemCoreClock(64000000);    /* ISSUE HERE!!! */
  
    HAL_InitializeFlashSPI();
    
    return 1;
}

Without calling the function, everything works fine.

Any explanation for this?

2 REPLIES 2

You can output diagnostic information via UART, or whatever other GPIO, LED or interfaces your board provides.

Don't code endless while() loops.

Don't use interrupts or system timers.

If you want to account for time, use a TIM in maximal mode.

Watch for entry conditions, if the HSE/PLL are already running don't tear down what's working/running.

ST calls Init() frequently / repetitively

STM32 Cube Programmer has it's own timeouts when it get fed-up waiting for you.

Avoid use of Hubs and Docking Stations for ST-LINK connections.

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

I have a problem with init function timeout.

My observation is that when I first connect CubeProgrammer to the device and choose a valid flash address(M1), CubeProgrammer reads the memory properly; however, when I try a second time with a different memory address(M2) CubeProgrammer informs me that there is a "init function time" out.

 

However, if I try to memory address M2 after CubeProgrammer connects the device there is no problem, I can read the memory properly. The problem is when I want to read second time. 

 

Could anyone help me on this issue? Or give me a clue to proceed.

Best regards,

Ersin