Stefano
Stefano

Reputation: 23

HAL_RCC_OscConfig returns HAL_TIMEOUT

I'm trying to configure a development board with STM32F411CEU6. This board have two crystals (25Mhz and 32,768KHz). I'm trying to compile code generated from CubeMX with different configurations, but HAL_RCC_OscConfig returns always HAL_TIMEOUT. I tried to:

but is everything useless.

This is the SystemClock_Config function:

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 25;
  RCC_OscInitStruct.PLL.PLLN = 200;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 9;
  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_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  {
    Error_Handler();
  }
}

Upvotes: 1

Views: 1961

Answers (1)

Bedouin_man
Bedouin_man

Reputation: 11

For this development board (and others) HAL_Timeout in HAL_RCC_OscConfig would be caused if HSE is selected as the clock source in the Clock Configuration tab of the CubeIDE Configuration Tool (CubeMX) and then mis-configuring HSE clock mode in RCC settings of the tool.

Check the following in the config tool (double-click <projectname>.ioc in IDE Project Explorer window to launch the tool). Under Pinout & Configuration tab select Categories > System Core > RCC then check that Crystal/Ceramic Resonator is selected in the High Speed Clock (HSE) dropdown of the RCC Mode window. The other two options Disable and BYPASS Clock Source would cause the HSE clock source to not select the on-board crystal and hence cause the HAL timeout.

PS: BYPASS Clock Source would be the option to choose if you are supplying your own clock into the RCC_OSC_IN pin of the MCU.

Upvotes: 1

Related Questions