Skip to content

Commit 79c474e

Browse files
committed
replaced standard SystemInit()
1 parent 00744f3 commit 79c474e

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

bootloader_F1/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ VECTOR_TABLE_OFFSET = 0x0000
66

77
C_SRCS = Src/main.c Src/usb.c Src/hid.c Src/led.c Src/flash.c
88

9-
DEVICE_C_SRCS += CMSIS/Device/ST/STM32F10x/Source/Templates/system_stm32f10x.c
9+
#DEVICE_C_SRCS += CMSIS/Device/ST/STM32F10x/Source/Templates/system_stm32f10x.c
1010

1111
# Be silent per default, but 'make V=1' will show all compiler calls.
1212
# If you're insane, V=99 will print out all sorts of things.
@@ -20,7 +20,7 @@ INCLUDE_DIRS += -I Inc
2020
INCLUDE_DIRS += -I CMSIS/Device/ST/STM32F10x/Include
2121
INCLUDE_DIRS += -I CMSIS/Include
2222

23-
C_SRCS += $(DEVICE_C_SRCS)
23+
#C_SRCS += $(DEVICE_C_SRCS)
2424
SRCS += $(C_SRCS)
2525
vpath %.c $(sort $(dir $(C_SRCS)))
2626
OBJS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SRCS:.c=.o)))

bootloader_F1/Src/main.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,51 @@ static uint16_t get_and_clear_magic_word(void) {
118118
return value;
119119
}
120120

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+
121160
void Reset_Handler(void) {
122161

123162
/* Setup the system clock (System clock source, PLL Multiplier
124163
* factors, AHB/APBx prescalers and Flash settings)
125164
*/
126-
SystemInit();
165+
SetSysClockTo72();
127166

128167
/* Setup to vector table in SRAM, so we can handle USB IRQs */
129168
RamVectors[0] = SRAM_END;
@@ -143,7 +182,7 @@ void Reset_Handler(void) {
143182
#if defined HAS_LED2_PIN
144183
led2_off();
145184
#endif
146-
185+
147186
UploadStarted = false;
148187
UploadFinished = false;
149188
funct_ptr UserProgram = (funct_ptr) *(volatile uint32_t *) (USER_PROGRAM + 0x04);
@@ -159,7 +198,7 @@ void Reset_Handler(void) {
159198
(GPIOB->IDR & GPIO_IDR_IDR2) ||
160199
(check_user_code(USER_PROGRAM) == false)) {
161200
if (magic_word == 0x424C) {
162-
201+
163202
/* If a magic word was stored in the
164203
* battery-backed RAM registers from the
165204
* Arduino IDE, exit from USB Serial mode and
@@ -186,7 +225,7 @@ void Reset_Handler(void) {
186225
;
187226
}
188227
}
189-
228+
190229
#if defined HAS_LED2_PIN
191230
led2_on();
192231
#endif

0 commit comments

Comments
 (0)