1

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:

  • stretch the timeout of 1000ms
  • lower the clock from 100Mhz to 96, 72 and 50MHz.
  • disable the LSE crystal

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();
  }
}
Stefano
  • 23
  • 4
  • Debug into the call to `HAL_RCC_OscConfig`. Which bit specifically is timing out? – canton7 Jan 28 '23 at 11:54
  • During HSE initialization, this is the incriminated code: while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) { if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE) { return HAL_TIMEOUT; } } – Stefano Jan 28 '23 at 12:26
  • Check the reference manual for what that flag means, but from memory maybe the crystal isn't starting? Is this a PCB you've designed in-house? – canton7 Jan 29 '23 at 14:09
  • 1
    The board was purchased online and I discovered that the HSE oscillator is defective :( – Stefano Jan 30 '23 at 19:53
  • Ah, that would explain it! – canton7 Feb 01 '23 at 10:10
  • @Stefano, thanks for your comment. I've a similar board (stm32f411e-disc) with the same defective crystal (must be from the same batch) and didn't think of trying the internal oscillator until I saw your comment. Thanks! – Sridhar Jul 31 '23 at 16:34

1 Answers1

1

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.

  • 1. Elaborate the question and use proper formatting for the code 2. Share your initial research and effort to fix the issue, and if anything worked or not? – Rupendra Mar 19 '23 at 03:54