函数定义:
1 HAL_StatusTypeDef HAL_Init(void) 2 { 3 /* Configure Flash prefetch, Instruction cache, Data cache */ 4 #if (INSTRUCTION_CACHE_ENABLE != 0U) 5 __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); 6 #endif /* INSTRUCTION_CACHE_ENABLE */ 7 8 #if (DATA_CACHE_ENABLE != 0U) 9 __HAL_FLASH_DATA_CACHE_ENABLE(); 10 #endif /* DATA_CACHE_ENABLE */ 11 12 #if (PREFETCH_ENABLE != 0U) 13 __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); 14 #endif /* PREFETCH_ENABLE */ 15 16 /* Set Interrupt Group Priority */ 17 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); 18 19 /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */ 20 HAL_InitTick(TICK_INT_PRIORITY); 21 22 /* Init the low level hardware */ 23 HAL_MspInit(); 24 25 /* Return function status */ 26 return HAL_OK; 27 }
1. 配置Flash预取,指令缓存,数据缓存
1 /* Configure Flash prefetch, Instruction cache, Data cache */ 2 #if (INSTRUCTION_CACHE_ENABLE != 0U) 3 __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); 4 #endif /* INSTRUCTION_CACHE_ENABLE */ 5 6 #if (DATA_CACHE_ENABLE != 0U) 7 __HAL_FLASH_DATA_CACHE_ENABLE(); 8 #endif /* DATA_CACHE_ENABLE */ 9 10 #if (PREFETCH_ENABLE != 0U) 11 __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); 12 #endif /* PREFETCH_ENABLE */
2. 设置中断优先级分组
1 /* Set Interrupt Group Priority */ 2 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
STM32F429 将中断分为 5 个组,组 0~4。该分组的设置是由 SCB->AIRCR 寄存器的 bit10~8 来定义 。中断优先级分组为4,表示4位抢占优先级,0位响应优先级。
3. 设置Systick中断优先级,TICK_INT_PRIORITY参数在“stm32f4xx_hal_conf.h”文件中定义,默认值为0x0F,优先级最低
1 /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */ 2 HAL_InitTick(TICK_INT_PRIORITY);
4. 执行Msp回调函数,其定义是一个weak函数,可在用户文件中实现
1 /* Init the low level hardware */ 2 HAL_MspInit();