Skip to main content
Visitor II
January 31, 2022
Solved

RCC stuck!

  • January 31, 2022
  • 1 reply
  • 2918 views

hey there

I have a customized board with STM32F030K6T6 on it and a 11.0592MHz crystal for HSE. the thing is my code does not run through and when I try to debug it, I can see it sticks in SystemClock_Config(), more specifically, in HAL_RCC_OscConfig() and when I trace it even more I get to __HAL_RCC_HSE_CONFIG() which seems like is responsible for bit setting and stuff...

any ways I have no Idea why this happens and though I think crystal is just fine(the reason is that I have tested my code in other boards and it was OK! therefore I dont think the problem is my code, it should be hardware somehow but I dont know what it could be?)

HELP!

    This topic has been closed for replies.
    Best answer by Peter BENSCH

    The current version of STM32CubeMX generates a while trap in USER CODE NonMaskableInt_IRQn 1:

    void NMI_Handler(void)
    {
     /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
     
     /* USER CODE END NonMaskableInt_IRQn 0 */
     HAL_RCC_NMI_IRQHandler();
     /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
     while (1)
     {
     }
     /* USER CODE END NonMaskableInt_IRQn 1 */
    }
    1. The changeover to HSI is automatic, as the RM0360 says: If the HSE oscillator is used [...] as the system clock [...], a detected failure causes a switch of the system clock to the HSI oscillator and the disabling of the HSE oscillator.
    2. Everything after switching to HSI must of course be done by the user. The custom code should be inserted either before or after the call to NMIHandler, depending on the requirement. In your case, it seems to make sense to insert it instead of the while trap, because the RCC CSS pending bit has already been cleared. For UART, about 3% accuracy of the clock is sufficient because of oversampling. HSI, however, typically has 5%, but can also reach the required accuracy with user calibration (HSITRIM).

    Good luck!

    Regards

    /Peter

    1 reply

    AlaAuthor
    Visitor II
    January 31, 2022

    I guess that crystal is not properly soldered to the board, as I push it to the board, my code runs, and as soon as I leave it, it stops

    Technical Moderator
    January 31, 2022

    Yes, that could well be a problem.

    There are, however, ways to catch the issue, because it could also occur during operation (e.g. broken internal bond wires of the crystal): the CSS (Clock Security System) is designed to switch over to the HSI in the event of a failure of the HSE and also to report it via NMI. Details can be found in RM0360, section 7.2.7.

    Regards

    /Peter

    AlaAuthor
    Visitor II
    February 1, 2022

    thanks @Peter BENSCH​ 

    is there a way to enable CSS in CubeMX? I mean I have enable it in Clock configuration panel, but I dont think this helped... it still has problem sticking in RCC... should I do something in void NMI_Handler(void) interrupt?

    regards