HAL_StatusTypeDef HAL_Init(void) { /* Configure Flash prefetch */ #if (PREFETCH_ENABLE != 0) #if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || \ defined(STM32F102x6) || defined(STM32F102xB) || \ defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || \ defined(STM32F105xC) || defined(STM32F107xC) /* Prefetch buffer is not available on value line devices */ __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); #endif #endif /* PREFETCH_ENABLE */ /* Set Interrupt Group Priority */ HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */ HAL_InitTick(TICK_INT_PRIORITY); /* Init the low level hardware */ HAL_MspInit(); /* Return function status */ return HAL_OK; }
时间: 2024-01-14 08:34:15 浏览: 43
HAL_Init函数是用来初始化HAL库的。它执行了以下操作:
1. 配置Flash预取:如果宏PREFETCH_ENABLE不为0,并且芯片型号符合条件,开启Flash预取缓冲区。
2. 设置中断组优先级:调用HAL_NVIC_SetPriorityGrouping函数设置中断组优先级为NVIC_PRIORITYGROUP_4。
3. 使用SysTick作为时间基准源,并配置为1ms的滴答(默认复位后的时钟是HSI):调用HAL_InitTick函数对SysTick进行初始化,设置滴答中断的优先级。
4. 初始化低层硬件:调用HAL_MspInit函数,用于初始化底层硬件。
5. 返回函数状态:返回HAL_OK,表示初始化成功。
这个函数的作用是初始化HAL库所需的各种配置,确保其正常工作。
相关推荐
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)