HAL库学习——中断嵌套及中断优先级
⼀、介绍
⼀般使⽤多个中断时,就会考虑中断的重要性及其之间的优先级关系。HAL库中可以通过HAL_NVIC_SetPriority函数来设置中断的优先级,决定中断是否能够被抢占。
开发环境:
MCU:STM32L071CBT6
IDE:KEIL5、STM32CubeMX
⼆、函数的讲解
HAL_NVIC_SetPriority函数的定义如下:
/**
* @brief  Sets the priority of an interrupt.
* @param  IRQn External interrupt number .
*        This parameter can be an enumerator of  IRQn_Type enumeration
*        (For the complete STM32 Devices IRQ Channels list, please refer to stm32l0xx.h file)
* @param  PreemptPriority The pre-emption priority for the IRQn channel.
*        This parameter can be a value between 0 and 3.
*        A lower priority value indicates a higher priority
* @param  SubPriority the subpriority level for the IRQ channel.
*        with stm32l0xx devices, this parameter is a dummy value and it is ignored, because
*        no subpriority supported in Cortex M0+ based products.
* @retval None
*/
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
{
/* Check the parameters */
parameter是什么意思啊
assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
NVIC_SetPriority(IRQn,PreemptPriority);
}
第⼀个参数为要设置的中断号,第⼆个参数为抢占优先级,有着0~3四个等级,值越⼩表⽰的优先级越⾼。即抢占优先级0的中断的优先级⾼于抢占优先级1的中断。第三个参数为响应优先级,从底层代码注释可以看出对于Cortex M0+的产品不⽀持该参数,该参数不⽤设置。
三、配置
这⾥有两种⽅法修改抢占优先级。
1)通过CubeMx配置,如下图:
2)在代码初始化函数⾥直接修改
两种⽅法最终都是在这边修改优先级。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。