函數定義:
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();