@@ -449,15 +449,18 @@ extern uint32_t *_fw_isr_vector_src;
449449
450450// Called from assembly code in startup.s
451451void SystemInit (void ) {
452- RCC_OscInitTypeDef osc_init = { 0 };
453- RCC_ClkInitTypeDef clk_init = { 0 };
454- GPIO_InitTypeDef gpio_init = { 0 };
455-
456452 #if (__FPU_PRESENT == 1 ) && (__FPU_USED == 1 )
457453 SCB -> CPACR |= ((3UL << 10 * 2 ) | (3UL << 11 * 2 )); /* set CP10 and CP11 Full Access */
458454 #endif
459455
456+ // enable 8-byte stack alignment for IRQ handlers, in accord with EABI
457+ SCB -> CCR |= SCB_CCR_STKALIGN_Msk ;
458+
459+ // since the firmware starts at 0x08008000, we need to set the vector table offset
460+ SCB -> VTOR = (uint32_t )& _fw_isr_vector_src ;
461+
460462 // Using external 16Mhz oscillator
463+ RCC_OscInitTypeDef osc_init = { 0 };
461464 osc_init .OscillatorType = RCC_OSCILLATORTYPE_MSI ;
462465 osc_init .MSIState = RCC_MSI_ON ;
463466 osc_init .MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT ;
@@ -472,6 +475,7 @@ void SystemInit(void) {
472475
473476 HAL_RCC_OscConfig (& osc_init );
474477
478+ RCC_ClkInitTypeDef clk_init = { 0 };
475479 clk_init .ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 ;
476480 clk_init .SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK ;
477481 clk_init .AHBCLKDivider = RCC_SYSCLK_DIV1 ; // HCLK 80MHz
@@ -481,9 +485,6 @@ void SystemInit(void) {
481485
482486 HAL_RCC_ClockConfig (& clk_init , FLASH_LATENCY_4 );
483487
484- // enable 8-byte stack alignment for IRQ handlers, in accord with EABI
485- SCB -> CCR |= SCB_CCR_STKALIGN_Msk ;
486-
487488 // enable clocks
488489 RCC -> AHB1ENR |= RCC_AHB1ENR_DMA1EN | RCC_AHB1ENR_DMA2EN | RCC_AHB1ENR_FLASHEN |
489490 RCC_AHB1ENR_CRCEN ;
@@ -495,8 +496,8 @@ void SystemInit(void) {
495496 RCC -> APB2ENR |= RCC_APB2ENR_SYSCFGEN | RCC_APB2ENR_TIM1EN | RCC_APB2ENR_SPI1EN |
496497 RCC_APB2ENR_USART1EN | RCC_APB2ENR_TIM15EN | RCC_APB2ENR_TIM16EN ;
497498
498-
499499 // Keep main power on (PC12)
500+ GPIO_InitTypeDef gpio_init = { 0 };
500501 gpio_init .Pin = GPIO_PIN_12 ;
501502 gpio_init .Mode = GPIO_MODE_OUTPUT_PP ;
502503 HAL_GPIO_WritePin (GPIOC , GPIO_PIN_12 , GPIO_PIN_SET );
@@ -505,7 +506,4 @@ void SystemInit(void) {
505506 // Turn VCC_PORT on (PB12)
506507 HAL_GPIO_WritePin (GPIOB , GPIO_PIN_12 , GPIO_PIN_SET );
507508 HAL_GPIO_Init (GPIOB , & gpio_init );
508-
509- // since the firmware starts at 0x08008000, we need to set the vector table offset
510- SCB -> VTOR = (uint32_t )& _fw_isr_vector_src ;
511509}
0 commit comments