cancel
Showing results for 
Search instead for 
Did you mean: 

SystemClock_Config code generated using HAL is working fine but using LL API it is failing for STM32F072xb. is that something missed in code generation. Attached the code generated by both LL and HAL.

MAnna
Associate

Code generated using LL : (Issue)

------------------------------------------

void SystemClock_Config(void)

{

 LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);

 if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_0)

 {

 Error_Handler(); 

 }

 LL_RCC_HSI_Enable();

  /* Wait till HSI is ready */

 while(LL_RCC_HSI_IsReady() != 1)

 {

   

 }

 LL_RCC_HSI_SetCalibTrimming(16);

 LL_RCC_HSI48_Enable();

  /* Wait till HSI48 is ready */

 while(LL_RCC_HSI48_IsReady() != 1)

 {

   

 }

 LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLL_MUL_6, LL_RCC_PREDIV_DIV_1);

 LL_RCC_PLL_Enable();

  /* Wait till PLL is ready */

 while(LL_RCC_PLL_IsReady() != 1)

 {

   

 }

 LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);

 LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_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)

 {

  

 }

 LL_Init1msTick(24000000);

 LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK);

 LL_SetSystemCoreClock(24000000);

 LL_RCC_SetUSARTClockSource(LL_RCC_USART2_CLKSOURCE_SYSCLK);

 LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_HSI48);

}

Code generated using HAL (Working Fine)

--------------------------------------

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /**Initializes the CPU, AHB and APB busses clocks 

 */

//__HAL_RCC_PWR_CLK_ENABLE();

//__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

//__HAL_RCC_PWR_CLK_DISABLE();

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;

 RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

 /**Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_USART2;

 PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_SYSCLK;

 PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

 /**Configure the Systick interrupt time

  */

 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  /**Configure the Systick

  */

 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

 /* SysTick_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

#endif

1 REPLY 1
seren
Associate II

This could be the same issue as described in

https://community.st.com/s/question/0D50X0000B41tlASQQ/stm32h743-hsi-frequency-waaaayyy-off

So in

LL_RCC_HSI_SetCalibTrimming(16);

16 is wrong and should be 64 (or maybe different for STM32F072xb).