Skip to main content
Associate II
April 26, 2025
Solved

HSE is not working on STM32F411E-Discovery

  • April 26, 2025
  • 3 replies
  • 758 views

I’ve just started learning STM32 and I’m currently using the STM32F411E-Discovery board. I loaded the default code provided by the Board Selector in STM32CubeIDE and was trying to get a simple LED blink working. It works fine when using the internal HSI clock, but it doesn’t seem to work when I switch to the external HSE clock. The only different is:
HSI:

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 16;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;


HSE:

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 = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;


 

Best answer by Duc_Tran

I ask Claude3.7 to fix it and now it both work - i dont know why. Here the system_clock_config function
HSE:

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 = 4;
 RCC_OscInitStruct.PLL.PLLN = 192;
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
 RCC_OscInitStruct.PLL.PLLQ = 8;
 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_DIV4;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

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

/**
 * @brief Peripherals Common Clock Configuration
 * @retval None
 */
void PeriphCommonClock_Config(void)
{
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};

 /** Initializes the peripherals clock
 */
 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S;
 PeriphClkInitStruct.PLLI2S.PLLI2SN = 200;
 PeriphClkInitStruct.PLLI2S.PLLI2SM = 5;
 PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
}

HSI:

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_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL.PLLM = 8; // 16 MHz / 8 = 2 MHz
 RCC_OscInitStruct.PLL.PLLN = 192; // 2 MHz * 192 = 384 MHz
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; // 384 MHz / 4 = 96 MHz 
 RCC_OscInitStruct.PLL.PLLQ = 8; // For USB, SDIO, etc.
 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_DIV4;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
 {
 Error_Handler();
 }
 }

3 replies

Andrew Neil
Super User
April 26, 2025

Welcome to the forum.

 


@Duc_Tran wrote:

it doesn’t seem to work when I switch to the external HSE clock.  


What do you mean by, "doesn’t seem to work"? Please describe the symptoms you see.

Have you used the debugger to see what's happening?

 

Does that board have a crystal for HSE, or is it clocked  from the ST-Link?

Details should be in the User Manual ...

 

I've edited you post to apply the proper source code formatting - please see How to insert source code for future reference.

See also: How to write your question to maximize your chances to find a solution.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Duc_TranAuthor
Associate II
April 26, 2025

There are 4 LEDs connected to PD12,13,14,15 in STM32F411E-Discovery board, i tried this with HSI, work completely fine. However, when i use HSE it not turning the LEDs on neither blinking, there is no error in debugger. I read the manual and STM32F411E-Discovery does have an 8Mhz crystal connected to PH0 of the STM32F411VE

 HAL_GPIO_WritePin(GPIOD, LD3_Pin, GPIO_PIN_SET); // Set LD3 pin high
 HAL_GPIO_WritePin(GPIOD, LD4_Pin, GPIO_PIN_SET); // Set LD4 pin high
 HAL_GPIO_WritePin(GPIOD, LD5_Pin, GPIO_PIN_SET); // Set LD5 pin high
 HAL_GPIO_WritePin(GPIOD, LD6_Pin, GPIO_PIN_SET); // Set LD6 pin high
 HAL_Delay(500); // Delay 
 HAL_GPIO_WritePin(GPIOD, LD4_Pin, GPIO_PIN_RESET); // Set LD4 pin low
 HAL_GPIO_WritePin(GPIOD, LD3_Pin, GPIO_PIN_RESET); // Set LD3 pin low
 HAL_GPIO_WritePin(GPIOD, LD6_Pin, GPIO_PIN_RESET); // Set LD4 pin low
 HAL_GPIO_WritePin(GPIOD, LD5_Pin, GPIO_PIN_RESET); // Set LD5 pin low
 HAL_Delay(500); // Delay 

  

mƎALLEm
Technical Moderator
April 26, 2025

Hello @Duc_Tran and welcome to the ST community,

Make sure all these components in the RED recatngle are available on your board:

mALLEm_0-1745690337838.png

If you are using CubeMx or CubeIDE could you please attach your ico file?

 

"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."
Tesla DeLorean
Guru
April 27, 2025

If the DISCO board is taking it's HSE clock from the ST-LINK PBA/MCO pin then HSE needs to be configured in BYPASS mode on the F4.

Check what's failing. Are you getting a TIMEOUT on the initialization?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Visitor II
August 24, 2025

I think this is a bug in the example for this board. The default generated RCC's configuration uses [BYPASS Clock Source], but according to the schematic, it should actually be [Crystal/Ceramic Resonator].

So, when using the default configuration, make sure to double-check the RCC configuration.