Associate
September 6, 2022
Question
External STM32 flash loader fails initialization on calling LL_SetSystemCoreClock()
- September 6, 2022
- 2 replies
- 1542 views
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?
