cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4R9 HAL_TIMEOUT in HAL_RCC_OscConfig

lukin
Associate III

Hello,

At code start-up, the function HAL_RCC_OscConfig return error HAL_TIMEOUT. I configured code with STM32CubeIDE. I am attaching clock configuration and code. Error is not repeatable, so it does not happen any time. Does anyone have an idea on how to solve it? Thank you.0693W00000Nre2jQAB.pngvoid SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Configure the main internal regulator output voltage

 */

 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure LSE Drive Capability

 */

 HAL_PWR_EnableBkUpAccess();

 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);

 /** Initializes the RCC Oscillators according to the specified parameters

 * in the RCC_OscInitTypeDef structure.

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;

 RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 RCC_OscInitStruct.LSEState = RCC_LSE_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

 RCC_OscInitStruct.PLL.PLLM = 2;

 RCC_OscInitStruct.PLL.PLLN = 12;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;

 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

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

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

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

 {

  Error_Handler();

 }

}

4 REPLIES 4

>>Does anyone have an idea on how to solve it?

Have your external clocks start more promptly?

Increase the timeout to something 10% longer than your worse-case bench testing of your design performance?

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

It happens even with board already powered up, for example while I am programming with st-link during normal development. Do you mean to add a HAL_Delay before run SystemClock_Config?

lukin
Associate III

I noticed this behaviour once I set optimization to -og (for debug). It does not appear using -o0 (none optimization)

Well you do have ALL the source code, and the devices.

It's spinning on something coming ready, which doesn't, and perhaps the loop is poorly bounded, or its duration depends on optimization or code placement.

At the very least get the time it spins/dwells to be uniform and agnostic to the code optimization. Perhaps use a free running TIM2 or TIM5, or use the DWT's CYCCNT to count machine cycles.

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