STM32/GD32 Study Guide - Stepping on the Pit (1) External crystal oscillator configuration, initialization failed, no vibration

 GD32 uses external active crystal oscillator and passive crystal oscillator, the model is GD32 F450

1. GD32 configuration uses an external crystal oscillator

1. Use an external passive crystal oscillator

Find the startup_gd32f450_470.s assembly file, find the SystemInit() function and jump into it

Find the system_clock_config() function at the bottom and jump in again

Select the macro definition: __SYSTEM_CLOCK_200M_PLL_IRC16M, jump, as shown in the figure

Comment out the definition of the internal clock and open the definition of the corresponding external clock: __SYSTEM_CLOCK_200M_PLL_25M_HXTAL

Open the corresponding system clock configuration definition according to your own needs. For example, I use an external 25MHZ crystal oscillator, and the system clock configuration is 200MHZ. If there is no clock conversion relationship you want in the definition, you need to write the corresponding clock configuration function yourself. Select Appropriate frequency division and multiplication coefficients, etc.

 The HXTAL_VALUE macro definition needs to be modified and changed to the actual frequency of the external clock. I use 25M, which is changed to 25000000

At the same time, the __SYS_OSC_CLK macro definition is changed to: __HXTAL

 Jump to the system clock configuration function corresponding to __SYSTEM_CLOCK_200M_PLL_25M_HXTAL: system_clock_200m_25m_hxtal(void)

This function is the code for configuring various bus clocks of the system, which can be modified according to your own needs.

2. Use an external active crystal oscillator

If you use an active crystal oscillator, you need to add a sentence to the above system_clock_200m_25m_hxtal(void), and add it before RCU_CTL |= RCU_CTL_HXTALEN;:

rcu_osci_bypass_mode_enable(RCU_HXTAL);

That is, enable bypass mode - that is, active external crystal oscillator

Note: If you add this sentence to the passive external crystal oscillator, it will always be stuck in this function, causing the clock initialization to fail.

2. The process of stepping on the pit

        During the development process, the GD32 initialization clock has been stuck in the system_clock_200m_25m_hxtal(void) function, and stuck in the detection of the RCU_CTL_HXTALSTB flag. This flag indicates whether the crystal oscillator initialization is stable, it is set by hardware, and cannot be operated by software. At the beginning, I tried various software solutions on the Internet to solve it, but it was useless. I also modified some hardware circuits, and finally found that there was a problem with the model of the GD32 chip used. It does not support external crystal oscillators at all. Active and passive They don’t support it. It’s really a scam and a lot of time wasted. The specific model is GD32 F450 VGH6. I hope you don’t step on it in the future.

I hope you like, favorite, and follow! ! ! ヾ(o◕∀◕)ノ

Guess you like

Origin blog.csdn.net/qq_38584212/article/details/131170657