55 *
66 * Change Logs:
77 * Date Author Notes
8- * 2021-08-20 BruceOu first implementation
9- * 2024-03-19 Evlers add serial supports
8+ * 2026-01-08 ShiHongChao first implementation
109 */
1110#include <stdint.h>
1211#include <rthw.h>
@@ -69,13 +68,13 @@ void rt_hw_board_init()
6968 system_clock_8M_200M ();
7069
7170 /* NVIC Configuration */
72- #define NVIC_VTOR_MASK 0x3FFFFF80
73- #ifdef VECT_TAB_RAM
71+ #define NVIC_VTOR_MASK 0x3FFFFF80
72+ #ifdef VECT_TAB_RAM
7473 /* Set the Vector Table base location at 0x10000000 */
75- SCB -> VTOR = (0x10000000 & NVIC_VTOR_MASK );
74+ SCB -> VTOR = (0x10000000 & NVIC_VTOR_MASK );
7675#else /* VECT_TAB_FLASH */
7776 /* Set the Vector Table base location at 0x08000000 */
78- SCB -> VTOR = (0x08000000 & NVIC_VTOR_MASK );
77+ SCB -> VTOR = (0x08000000 & NVIC_VTOR_MASK );
7978#endif
8079
8180 SystemClock_Config ();
@@ -107,25 +106,28 @@ static void system_clock_8M_200M(void)
107106{
108107 uint32_t timeout = 0U ;
109108 uint32_t stab_flag = 0U ;
110-
109+
111110 /* reset RCU */
112111 rcu_deinit ();
113112
114113 /* enable HXTAL */
115114 RCU_CTL |= RCU_CTL_HXTALEN ;
116115
117116 /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
118- do {
117+ do
118+ {
119119 timeout ++ ;
120120 stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB );
121- }while ((0U == stab_flag ) && (HXTAL_STARTUP_TIMEOUT != timeout ));
121+ } while ((0U == stab_flag ) && (HXTAL_STARTUP_TIMEOUT != timeout ));
122122
123123 /* if fail */
124- if (0U == (RCU_CTL & RCU_CTL_HXTALSTB )){
125- while (1 ){
124+ if (0U == (RCU_CTL & RCU_CTL_HXTALSTB ))
125+ {
126+ while (1 )
127+ {
126128 }
127129 }
128-
130+
129131 RCU_APB1EN |= RCU_APB1EN_PMUEN ;
130132 PMU_CTL |= PMU_CTL_LDOVS ;
131133
@@ -137,35 +139,39 @@ static void system_clock_8M_200M(void)
137139 /* APB1 = AHB/4 */
138140 RCU_CFG0 |= RCU_APB1_CKAHB_DIV4 ;
139141
140- /* Configure the main PLL, PSC = 8, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
142+ /* Configure the main PLL, PSC = 8, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
141143 RCU_PLL = (8U | (400U << 6U ) | (((2U >> 1U ) - 1U ) << 16U ) |
142- (RCU_PLLSRC_HXTAL ) | (9U << 24U ));
144+ (RCU_PLLSRC_HXTAL ) | (9U << 24U ));
143145
144146 /* enable PLL */
145147 RCU_CTL |= RCU_CTL_PLLEN ;
146148
147149 /* wait until PLL is stable */
148- while (0U == (RCU_CTL & RCU_CTL_PLLSTB )){
150+ while (0U == (RCU_CTL & RCU_CTL_PLLSTB ))
151+ {
149152 }
150-
153+
151154 /* Enable the high-drive to extend the clock frequency to 200 Mhz */
152155 PMU_CTL |= PMU_CTL_HDEN ;
153- while (0U == (PMU_CS & PMU_CS_HDRF )){
156+ while (0U == (PMU_CS & PMU_CS_HDRF ))
157+ {
154158 }
155-
159+
156160 /* select the high-drive mode */
157161 PMU_CTL |= PMU_CTL_HDS ;
158- while (0U == (PMU_CS & PMU_CS_HDSRF )){
159- }
160-
162+ while (0U == (PMU_CS & PMU_CS_HDSRF ))
163+ {
164+ }
165+
161166 /* select PLL as system clock */
162167 RCU_CFG0 &= ~RCU_CFG0_SCS ;
163168 RCU_CFG0 |= RCU_CKSYSSRC_PLLP ;
164169
165170 /* wait until PLL is selected as system clock */
166- while (0U == (RCU_CFG0 & RCU_SCSS_PLLP )){
171+ while (0U == (RCU_CFG0 & RCU_SCSS_PLLP ))
172+ {
167173 }
168-
174+
169175 /* Update SystemCoreClock variable */
170176 SystemCoreClock = 200000000U ; // 200MHz
171177}
0 commit comments