8 years, 3 months ago.

Program hangs at SetSysClock() on a custom STM32F411 PCB


I found a weird problem. When I download my program to my STM32F411 on my own PCB using the st-link on NUCLEO board, the program will go into a infinite loop and never jump to my main(). After a while, I found that I have to comment out "SetSysClock();" inside


Then I have no problem running my own main(). The LED shines and UART is OK.

After looking into SetSysClock(), I found a while(1), and that should be the reason why my my program hangs.

void SetSysClock(void)
  /* 1- Try to start with HSE and external clock */
  if (SetSysClock_PLL_HSE(1) == 0)
    /* 2- If fail try to start with HSE and external xtal */
    #if USE_PLL_HSE_XTAL != 0
    if (SetSysClock_PLL_HSE(0) == 0)
      /* 3- If fail start with HSI clock */
      if (SetSysClock_PLL_HSI() == 0)
          // [TODO] Put something here to tell the user that a problem occured...

The question is, what went wrong if my program entered this while(1) loop? And how to fix this? It seems like neither the external crystal nor the internal RC oscillator can be used to successfully configure the system clock. But why can I use GPIO and UART as normal after commenting out SetSysClock()?

On my PCB, I used an external 8.0MHz crystal with two 20pf capacitors. Now I doubt either the crystal I have was bad or the value of capacitor was wrong. Another possible reason may be that I placed the crystal very far away from MCU (about 2.5cm away), could this be the reason?

Thank you for your help!

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F411RET6 microcontroller.

Does some one know the answer??

posted by Zach Wang 23 Mar 2016
Be the first to answer this question.