STM32与FreeRTOS学习备忘,xSemaphoreGiveFromISR

在学习FreeRTOS的时候,使用中断释放信号量时,出现了问题。

中断函数卡在xSemaphoreGiveFromISR();函数里了,具体是卡在portASSERT_IF_INTERRUPT_PRIORITY_INVALID();里。


根据注释查看http://www.freertos.org/RTOS-Cortex-M3-M4.html,里面有两点点出关键。

1.

Most systems default to the wanted configuration, with the noticeable exception of the STM32 driver library. If you are using an STM32 with the STM32 driver library then ensure all the priority bits are assigned to be preempt priority bits by calling NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); before the RTOS is started.

意味着选中断分组时只能选preempt为4bit,sub为0bit,即preemption范围0~15,sub priority范围为0


2.

Relevance when using the RTOS

FreeRTOS functions that end in "FromISR" are interrupt safe, but even these functions cannot be called from interrupts that have a logical priority above the priority defined by configMAX_SYSCALL_INTERRUPT_PRIORITY ( configMAX_SYSCALL_INTERRUPT_PRIORITY is defined in the FreeRTOSConfig.h header file ). Therefore, any interrupt service routine that uses an RTOS API function must have its priority manually set to a value that is numerically equal to or  greater than  the configMAX_SYSCALL_INTERRUPT_PRIORITY setting. This ensures the interrupt's logical priority is equal to or less than the configMAX_SYSCALL_INTERRUPT_PRIORITY setting.

Cortex-M interrupts default to having a priority value of zero. Zero is the highest possible priority value. Therefore, never leave the priority of an interrupt that uses the interrupt safe RTOS API at its default value.

意味着不能让中断优先号分配不能小于 configMAX_SYSCALL_INTERRUPT_PRIORITY!!!最好的分配方法当然是 尾部15分配起,而不是从头部0开始分配。



让GPIO的中断优先号大于configMAX_SYSCALL_INTERRUPT_PRIORITY,即中断优先号不优先于(logic above)你定义的最优中断优先号就行,xSemaphoreGiveFromISR();就可以用了。

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值