Skip to main content
JBlaz.1
Associate
March 17, 2020
Question

STM32F407 fails on HAL_RCC_OscConfig

  • March 17, 2020
  • 5 replies
  • 10157 views

Hello guys,

I got a "STM32F407-DISC1" board and if I configure the external oscillator, it goes into "error_handling:

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_DIV2;
 
 RCC_OscInitStruct.PLL.PLLQ = 7;
 
 
 
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 
 {
 
 
 
 Error_Handler();
 
 }
 

Afterwards program stops and does not continue. What do I need to change in my code? or is it due to a hardware failure?

Cheers

This topic has been closed for replies.

5 replies

Khouloud ZEMMELI
ST Employee
March 17, 2020

​Hello @JBlaz.1​ 

Could you please share your ioc file ?

Thanks,

Khouloud

JBlaz.1
JBlaz.1Author
Associate
March 17, 2020

Hello @Khouloud ZEMMELI​ ,

I use platformio with HAL. Can you guide me to this file?

[env:disco_f407vg]
platform = ststm32
board = disco_f407vg
framework = arduino

Cheers

Khouloud ZEMMELI
ST Employee
March 18, 2020

​You have created a project from CubeMX , after the save, the CubeMX project is saved as .ioc file,  you can share you project .zip

Best Regards,

Khouloud

Tesla DeLorean
Guru
March 17, 2020

RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; // external clock source rather than crystal

Make sure the 8 MHz is present from ST-LINK, not sure if any jumpers or solder bridges involved.

Make sure HSE_VALUE define is 8000000

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
JBlaz.1
JBlaz.1Author
Associate
March 18, 2020

Thanks for your input. I changed as you suggested but still goes into "Error_Handler()"

HSE_VALUE is already set to 8000000U

TDK
March 18, 2020

You can either use the MCO output from ST-Link like clive1 says, or you can use the HSE crystal. In either case, consult UM1472 for the jumpers/components that need fitted/removed.

• MCO from ST-LINK. From MCO of the STM32F103. This frequency cannot be
changed, it is fixed at 8 MHz and connected to PH0-OSC_IN of the STM32F407VG.
Configuration needed:
– SB13, SB14 OPEN
– R25(b) removed
– R68(b) soldered
• Oscillator on board. From X2 crystal. For typical frequencies and its capacitors and
resistors, refer to the STM32F407VG Datasheet at www.st.com. Configuration needed:
– SB13, SB14 OPEN
– R25(b) soldered
– R68(b) removed

"If you feel a post has answered your question, please click ""Accept as Solution""."
JBlaz.1
JBlaz.1Author
Associate
March 18, 2020

also from the manual:

b) As the frequency supplied by X2 is the same as MCO (8 MHz), R25 and R68 are soldered.

So, I didnt change anything.

Nevertheless, I removed R68 now and the result is the same - goes straight into "Error_Handler"

Piranha
Principal III
March 19, 2020

You have the HAL source code and a board with a debugger - step through the code and look for where and why it fails!

waclawek.jan
Super User
March 20, 2020

+1

...or ditch Cube altogether and write the clock setup yourself.

JW

PS If you don't have a crystal but using the STLink MCO output, do you set HSE Bypass?

TDK
March 20, 2020

Maybe you're trying to change the PLL while it's already enabled. Who knows. You're not providing much info.

"If you feel a post has answered your question, please click ""Accept as Solution""."