Skip to main content
JTse.1
Associate II
September 2, 2022
Question

using stm32f401rct6, two question, (1) system clock configured with a external 16Mhz crystal can work if it is set to 42Mhz but not at 84Mhz and (2) even if working will stuck at HAL_GetTick

  • September 2, 2022
  • 10 replies
  • 2352 views

(1) cannot run at 84Mhz, it will stuck at Error Handler

 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 = 16;

 RCC_OscInitStruct.PLL.PLLN = 336;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV8;

 RCC_OscInitStruct.PLL.PLLQ = 4;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

(2) can run at 42Mhz but will keep looping inside the loop forever and cannot timeout

    /* Wait till HSE is ready */

    while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)

    {

     if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)

     {

      return HAL_TIMEOUT;

     }

    }

   }

   else

This topic has been closed for replies.

10 replies

waclawek.jan
Super User
September 2, 2022

What is your hardware? Is there a crystal connected to HSE pins?

JW

JTse.1
JTse.1Author
Associate II
September 5, 2022
Dear JW

Yes, I have a 16Mhz crystal connected

Part number: CRYSTAL, SMD, 16MHz, 2.5X2.0 CX2520SB27120D0FLJZZ

See attached

Noticed that in the circuits is a 1M resistor in series
This resistor was indicated in the generic design document , but it was not
Indicated in the reference manual. Could it be the problem?

The crystal used has been proven working in several board but using NXP ARM
The circuit there has the resistor in parallel with values from 33R to 10M
And some boards do not even have it installed

I am in the process of converting all my NXP boards to using ST CPU

I have another ST board with the same resistor but using only 33R and it worked

I suspect this 1M resistor value is too high, I am going to change to 33R since my other ST board is working.

I was mistaken, with HSE on, the code got stuck because the HSE rdy never got set

With only the internal 16Mhz, I can run the code

Still, I have some strange problems

But no matter what setting I did in stmcudeidse, I can turn on the PLL but the PLL rdy bit do not lock

The good news is that I can run the board using the default low speed setting but will need to get the HSE working in order to do
Mass production soon

john
Javier1
Principal
September 2, 2022

@JTse.1​ 

  1. show us your pcb(detail on the XTAL)
  2. are you using cubeMX? , attach your cubeMX ".ioc" file
hit me up in https://www.linkedin.com/in/javiermuñoz/
JTse.1
JTse.1Author
Associate II
September 5, 2022
Dear Javier

I am using stmcubeide

I have a 16Mhz crystal connected

Part number: CRYSTAL, SMD, 16MHz, 2.5X2.0 CX2520SB27120D0FLJZZ

See attached

Noticed that in the circuits is a 1M resistor in series
This resistor was indicated in the generic design document , but it was not
Indicated in the reference manual. Could it be the problem?

The crystal used has been proven working in several board but using NXP ARM
The circuit there has the resistor in parallel with values from 33R to 10M
And some boards do not even have it installed

I am in the process of converting all my NXP boards to using ST CPU

I have another ST board with the same resistor but using only 33R and it worked

I suspect this 1M resistor value is too high, I am going to change to 33R since my other ST board is working.

I was mistaken, with HSE on, the code got stuck because the HSE rdy never got set

With only the internal 16Mhz, I can run the code

Still, I have some strange problems

But no matter what setting I did in stmcudeidse, I can turn on the PLL but the PLL rdy bit do not lock

The good news is that I can run the board using the default low speed setting but will need to get the HSE working in order to do
Mass production soon

john
AScha.3
Super User
September 5, 2022

your osc circuit should look like this:

0693W00000SuTY6QAN.png 

show your circuit, if you expect any useful help.

If you feel a post has answered your question, please click on " Best Answer ".
JTse.1
JTse.1Author
Associate II
September 5, 2022
Dear AsCha

I am using stmcubeide

I have a 16Mhz crystal connected

Part number: CRYSTAL, SMD, 16MHz, 2.5X2.0 CX2520SB27120D0FLJZZ

See attached

Noticed that in the circuits is a 1M resistor in series
This resistor was indicated in the generic design document , but it was not
Indicated in the reference manual. Could it be the problem?

The crystal used has been proven working in several board but using NXP ARM
The circuit there has the resistor in parallel with values from 33R to 10M
And some boards do not even have it installed

I am in the process of converting all my NXP boards to using ST CPU

I have another ST board with the same resistor but using only 33R and it worked

I suspect this 1M resistor value is too high, I am going to change to 33R since my other ST board is working.

I was mistaken, with HSE on, the code got stuck because the HSE rdy never got set

With only the internal 16Mhz, I can run the code

Still, I have some strange problems

But no matter what setting I did in stmcudeidse, I can turn on the PLL but the PLL rdy bit do not lock

The good news is that I can run the board using the default low speed setting but will need to get the HSE working in order to do
Mass production soon
Piranha
Principal III
September 5, 2022

You posted the same post 3 times, each sentence is on a separate line and the space between lines consists of 3 empty lines. It's worse than spam! Edit those posts so that the topic is readable.

JTse.1
JTse.1Author
Associate II
September 6, 2022
Dear PiranhA
I do not understand where I posted 3 times?
I was just answering different people
I remember posting it once initially
And as for space and lines, it looks normal on my side
Even your reply shows my post looks normal
Pls help me to understand where did I go wrong?
john
Tesla DeLorean
Guru
September 5, 2022

Please don't repetitively post the same material, post it once, everyone can see it.

Here's the App Note https://www.st.com/resource/en/application_note/cd00221665-oscillator-design-guide-for-stm8afals-stm32-mcus-and-mpus-stmicroelectronics.pdf

Show your circuit as constructed.

The HAL Tick requires SysTick to be up and running.

The crystal has to start. The output can be probed if you enable it's output on PA8/MCO pin.

The MCU can crash if the PLL and FLASH wait states are wrong.

Make sure HSE_VALUE define in stm32f4xx_hal_conf.h reflects the speed of your external crystal.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
JTse.1
JTse.1Author
Associate II
September 6, 2022
Dear Tesla
Yes, I understand now, first time doing this, I did an all reply while answering individuals
My mistake, sorry,
john