‎2021-08-01 11:10 AM
Hi
I have my own board, with STM32L053C8T6TR. And I set clock and program failed here: while (LL_RCC_HSE_IsReady ()! = 1) {};
void SystemClock_Config(void) {
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); // clock pro PWR controller
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); // 1.8V pro core
while (LL_PWR_IsActiveFlag_VOS())
; // wait on supply change
// PLLCLK = 8MHz * 12 / 2 = 32MHz
LL_RCC_HSE_EnableBypass();
LL_RCC_HSE_Enable();
while(LL_RCC_HSE_IsReady() != 1){};
LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLL_MUL_12, LL_RCC_PLL_DIV_3);
LL_RCC_PLL_Enable();
while(LL_RCC_PLL_IsReady() != 1){};
/* Sysclk activation on the main PLL */
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL){};
/* Set APB1 & APB2 prescaler */
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
SysTick_Config(32000000 / 1000);
SystemCoreClock = 32000000;
NVIC_SetPriorityGrouping(0x300);
LL_Init1msTick(32000000);
LL_SetSystemCoreClock(32000000);
// Enable USB clock
LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLL);
// Start timer TIM2
CLOCK__StartMasterMSECtimer();
}
Does anyone see a problem here?
‎2021-08-01 11:28 AM
> I have my own board, with STM32L053C8T6TR
> LL_RCC_HSE_EnableBypass();
Do you have a clock signal coming in to HSE or are you using a crystal?
‎2021-08-02 12:41 AM
I use a crystal. This will probably be my problem. To be sure, I'll try to check it with an oscilloscope, but I have it at work.
So I'll try to rewrite my code and remove this line.
> LL_RCC_HSE_EnableBypass();
‎2021-08-02 06:43 AM
‎2021-08-02 10:39 AM
Yes. It is true. I have my own board, but I'm testing the application on NUCLEO-L053. And I forgot about this. Here is function clock settings for nucleo or my own board.
Thank you for your advice. 😊
void SystemClock_Config(void) {
#ifdef NUCLEO-L053R8
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); // clock pro PWR controller
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); // 1.8V pro core
while (LL_PWR_IsActiveFlag_VOS())
; // wait on change
// PLLCLK = 8MHz * 12 / 2 = 32MHz
LL_RCC_HSE_EnableBypass();
LL_RCC_HSE_Enable();
while(LL_RCC_HSE_IsReady() != 1){};
LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLL_MUL_12, LL_RCC_PLL_DIV_3);
LL_RCC_PLL_Enable();
while(LL_RCC_PLL_IsReady() != 1){};
/* Sysclk activation on the main PLL */
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL){};
/* Set APB1 & APB2 prescaler */
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
SysTick_Config(32000000 / 1000);
SystemCoreClock = 32000000;
NVIC_SetPriorityGrouping(0x300);
LL_Init1msTick(32000000);
LL_SetSystemCoreClock(32000000);
LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLL);
#else
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); // clock pro PWR kontrolér
LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1) {
}
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
LL_RCC_HSE_Enable();
/* Wait till HSE is ready */
while (LL_RCC_HSE_IsReady() != 1) {
}
LL_RCC_LSI_Enable();
/* Wait till LSI is ready */
while (LL_RCC_LSI_IsReady() != 1) {
}
LL_PWR_EnableBkUpAccess();
if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSI) {
LL_RCC_ForceBackupDomainReset();
LL_RCC_ReleaseBackupDomainReset();
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
}
LL_RCC_EnableRTC();
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLL_MUL_12, LL_RCC_PLL_DIV_3);
LL_RCC_PLL_Enable();
/* Wait till PLL is ready */
while (LL_RCC_PLL_IsReady() != 1) {
}
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
/* Wait till System clock is ready */
while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {
}
SysTick_Config(32000000 / 1000);
SystemCoreClock = 32000000;
NVIC_SetPriorityGrouping(0x300);
LL_Init1msTick(32000000);
LL_SetSystemCoreClock(32000000);
#endif
CLOCK__StartMasterMSECtimer();
}