Skip to main content
Associate II
November 5, 2025
Question

OSC_IN and OSC_EN wrong initialization order

  • November 5, 2025
  • 1 reply
  • 165 views

Hi!

I have a board with an external oscillator. The oscillator would not start, and I spent a few hours debugging the issue only to find out the automatically generated code initialized the clock and the OSC_EN pin in the wrong order!

relevant ioc lines:

PC14-OSC32_IN\ (PC14).Mode=HSE-External-Clock-Source
PC14-OSC32_IN\ (PC14).Signal=RCC_OSC_IN
PC15-OSC32_OUT\ (PC15).Mode=OSC enable
PC15-OSC32_OUT\ (PC15).Signal=RCC_OSC_EN

the generated code:

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */

...

void SystemClock_Config(void)
{
...
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
...

static void MX_GPIO_Init(void)
{
...
 /*Configure GPIO pin : PC15 */
 GPIO_InitStruct.Pin = GPIO_PIN_15;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.Alternate = GPIO_AF1_OSC;
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

Note `HAL_RCC_OscConfig` will wait until HSERDY but it will be never ready if since PC15 is not configured as OSC_EN yet.

1 reply

Ghofrane GSOURI
Technical Moderator
November 5, 2025

Hello @cyber_v1 

Thank you for your valuable contribution.

The issue has been escalated to our development team under internal ticket number 221262 for further investigation and resolution.

 

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.