在“startup_stm32f429xx.s”文件中,系统复位后会首先调用SystemInit函数
1; Reset handler 2Reset_Handler PROC 3 EXPORT Reset_Handler [WEAK] 4 IMPORT SystemInit 5 IMPORT __main 6 7 LDR R0, =SystemInit 8 BLX R0 9 LDR R0, =__main 10 BX R0 11 ENDP
SystemInit函数定义:
1void SystemInit(void) 2{ 3/* FPU settings ------------------------------------------------------------*/ 4#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) 5 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ 6#endif 7/* Reset the RCC clock configuration to the default reset state ------------*/ 8/* Set HSION bit */ 9 RCC->CR |= (uint32_t)0x00000001; 1011/* Reset CFGR register */12 RCC->CFGR = 0x00000000; 1314/* Reset HSEON, CSSON and PLLON bits */15 RCC->CR &= (uint32_t)0xFEF6FFFF; 1617/* Reset PLLCFGR register */18 RCC->PLLCFGR = 0x24003010; 1920/* Reset HSEBYP bit */21 RCC->CR &= (uint32_t)0xFFFBFFFF; 2223/* Disable all interrupts */24 RCC->CIR = 0x00000000; 2526/* Configure the Vector Table location add offset address ------------------*/27#ifdef VECT_TAB_SRAM 28 SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */29#else30 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */31#endif32 }
1. FPU设置
1/* FPU settings ------------------------------------------------------------*/2#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) 3 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */4#endif
__FPU_PRESENT 用来确定处理器是否带 FPU 功能
__FPU_USED 用来确定是否开启 FPU 功能
如果处理器带有FPU功能且确定开启FPU功能,则设置“SCB->CPACR”(协处理器访问控制)寄存器的 20~23 位为 1 。
利用CPACR寄存器,可以使能或禁止FPU。可通过SCB->CPACR来访问。第0~19位及第24~31位未实现,为保留位,如图:
对于Cortex-M4处理器,FPU被定义为协处理器10和11。由于其他协处理器不存在,只有CP10和CP11可用且都用于FPU。在设置这个寄存器时,CP10和CP11的设置必须相同。
CP10和CP11在复位后为0。在这种配置下,FPU禁止且允许低功耗,在使用之前,需要使能FPU,本步骤一般在SystemInit函数内执行。
2. RCC时钟配置复位
1/* Reset the RCC clock configuration to the default reset state ------------*/ 2/* Set HSION bit */ 3 RCC->CR |= (uint32_t)0x00000001; 4 5/* Reset CFGR register */ 6 RCC->CFGR = 0x00000000; 7 8/* Reset HSEON, CSSON and PLLON bits */ 9 RCC->CR &= (uint32_t)0xFEF6FFFF; 1011/* Reset PLLCFGR register */12 RCC->PLLCFGR = 0x24003010; 1314/* Reset HSEBYP bit */15 RCC->CR &= (uint32_t)0xFFFBFFFF; 1617/* Disable all interrupts */18 RCC->CIR = 0x00000000;
2.1 将RCC->CR(RCC 时钟控制寄存器)的HSION置位,使能内部高速时钟
2.2 将RCC->CFGR(RCC 时钟配置寄存器 )清零
2.3 复位RCC->CR(RCC 时钟控制寄存器)的HSEON, CSSON 和 PLLON位
2.4 复位RCC->PLLCFGR(RCC PLL 配置寄存器 )
2.5 将RCC->CR(RCC 时钟控制寄存器)的HSEBYP复位
2.6 禁用所有中断
3. 配置中断向量表地址
1/* Configure the Vector Table location add offset address ------------------*/2#ifdef VECT_TAB_SRAM 3 SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */4#else5 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */6#endif