HSE_RDY is accidentally set when there is no external high speed clock

Foreword

The problem was raised by the customer and the user was found on the STM32F103 device. The user enabled IWDG in the product. During use, it was found that when the MCU was reset, sometimes the program could not run ; the tracking code found that the program died at the polling PLL_RDY . User feedback says that the sample code in the ST library is used, and the STM32F103 is suspected of having design problems.

Research

There is no problem in troubleshooting hardware supply. NRST is used to measure the reset signal. The STM32CubeMX generates the minimum system code (clock configuration + IWDG) for repeated verification. This problem is not found and the user code is suspected.

The customer claims that the development is based on the demo provided in the SPL library provided by ST. Using the sample code in SPL plus the IWDG reset, this problem can be reproduced: the debugger trace code finds that the HSE_RDY bit is abnormally set when the problem occurs ( The user platform has no external high-speed clock source).

By analyzing the code, it is found that the SPL library [Standard Peripheral Firmware Library] will directly enable HSE and detect the HSE_RDY bit when configuring the clock. The HSE_RDY bit may be set after resetting the MCU several times, causing the clock configuration program to perform the next configuration in accordance with the HSE-based state. The demo in SPL runs on the STM32F1 evaluation board, and the evaluation board comes with a high-speed clock source, so there is no such problem.

in conclusion

After the MCU is reset, HSE_ON is invalid by default, but repeatedly enabling it will cause noise accumulation inside the MCU, causing the clock detection circuit to misjudge and reflect it from the register.

- For STM32F103, once HSE_RDY is set, as long as the power is off, HSE_RDY will not be cleared (even if HSE_ON is disabled) no matter how the MCU is reset.

- Similar problems can be found with the STM32F030 microcontroller. The difference is that the HSE_RDY bit is cleared after HSE_RDY is set, but once HSE_ON is set, HSE_RDY may also be set.

deal with

Since the user does not use the external HSE, it is not necessary to judge whether there is an external high-speed crystal oscillator, so the HSE is no longer enabled by modifying the user code. The problem does not recur after repeated tests.

Suggest

1. It is important to understand that the HSE_RDY bit is a necessary condition for detecting the presence of an external clock, rather than a sufficient condition.

2, when using STM32, try to modify the software according to the actual design, do not save the trouble and bring problems.


Mini Safety Breaker MCB

Breaker Mcb,Mcb Circuit Breaker,32A Circuit Breaker,Miniature Circuit Breaker

ZHEJIANG QIANNA ELECTRIC CO.,LTD , https://www.traner-elec.com