@@ -118,12 +118,51 @@ static uint16_t get_and_clear_magic_word(void) {
118
118
return value ;
119
119
}
120
120
121
+ static void SetSysClockTo72 (void )
122
+ {
123
+
124
+ /* Enable HSE */
125
+ SET_BIT (RCC -> CR , RCC_CR_HSEON );
126
+
127
+ /* Wait until HSE is ready */
128
+ //while ((RCC->CR & RCC_CR_HSERDY) == 0) {
129
+ while (READ_BIT (RCC -> CR , RCC_CR_HSERDY ) == 0 ) {
130
+ ;
131
+ }
132
+
133
+ /* Enable Prefetch Buffer & set Flash access to 2 wait states */
134
+ SET_BIT (FLASH -> ACR , FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_2 );
135
+
136
+ /* SYSCLK = PCLK2 = HCLK */
137
+ /* PCLK1 = HCLK / 2 */
138
+ /* PLLCLK = HSE * 9 = 72 MHz */
139
+ SET_BIT (RCC -> CFGR , RCC_CFGR_HPRE_DIV1 | RCC_CFGR_PPRE2_DIV1 | RCC_CFGR_PPRE1_DIV2 |
140
+ RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9 );
141
+
142
+ /* Enable PLL */
143
+ SET_BIT (RCC -> CR , RCC_CR_PLLON );
144
+
145
+ /* Wait until PLL is ready */
146
+ //while ((RCC->CR & RCC_CR_PLLRDY) == 0) {
147
+ while (READ_BIT (RCC -> CR , RCC_CR_PLLRDY ) == 0 ) {
148
+ ;
149
+ }
150
+
151
+ /* Select PLL as system clock source */
152
+ SET_BIT (RCC -> CFGR , RCC_CFGR_SW_PLL );
153
+
154
+ /* Wait until PLL is used as system clock source */
155
+ while (READ_BIT (RCC -> CFGR , RCC_CFGR_SWS_1 ) == 0 ) {
156
+ ;
157
+ }
158
+ }
159
+
121
160
void Reset_Handler (void ) {
122
161
123
162
/* Setup the system clock (System clock source, PLL Multiplier
124
163
* factors, AHB/APBx prescalers and Flash settings)
125
164
*/
126
- SystemInit ();
165
+ SetSysClockTo72 ();
127
166
128
167
/* Setup to vector table in SRAM, so we can handle USB IRQs */
129
168
RamVectors [0 ] = SRAM_END ;
@@ -143,7 +182,7 @@ void Reset_Handler(void) {
143
182
#if defined HAS_LED2_PIN
144
183
led2_off ();
145
184
#endif
146
-
185
+
147
186
UploadStarted = false;
148
187
UploadFinished = false;
149
188
funct_ptr UserProgram = (funct_ptr ) * (volatile uint32_t * ) (USER_PROGRAM + 0x04 );
@@ -159,7 +198,7 @@ void Reset_Handler(void) {
159
198
(GPIOB -> IDR & GPIO_IDR_IDR2 ) ||
160
199
(check_user_code (USER_PROGRAM ) == false)) {
161
200
if (magic_word == 0x424C ) {
162
-
201
+
163
202
/* If a magic word was stored in the
164
203
* battery-backed RAM registers from the
165
204
* Arduino IDE, exit from USB Serial mode and
@@ -186,7 +225,7 @@ void Reset_Handler(void) {
186
225
;
187
226
}
188
227
}
189
-
228
+
190
229
#if defined HAS_LED2_PIN
191
230
led2_on ();
192
231
#endif
0 commit comments