[问题解决]HAL_UART_RxCpltCallback串口接收中断回调不正常

更新时间:2023-05-12 13:34:40 阅读: 评论:0

[问题解决]HAL_UART_RxCpltCallback串⼝接收中断回调不正
背景:【MXCube+FreeRTOS+STM32F407】
为了将串⼝数据上下⽂分离。在回调函数中,使⽤消息队列将接收的字符发⾄队列。在任务线程中进⾏处理数据。
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
//taskENTER_CRITICAL();
/* Prevent unud argument(s) compilation warning */
//UNUSED(huart);
if (huart->Instance == USART2) {
osMessageQueuePut(remoteQueueHandle, (uint8_t*)&remoteTmpBuffer[0], 0, 0);
} el if(huart->Instance == USART6) {
osMessageQueuePut(ledQueueHandle, (uint8_t*)&ledTmpBuffer[0], 0, 0);
} el if(huart->Instance == USART3) {
osMessageQueuePut(lockQueueHandle, (uint8_t*)&lockTmpBuffer[0], 0, 0);
}
//taskEXIT_CRITICAL();
}
Step1分析:
osMessageQueuePut 使⽤在中断,需要设置 timeout 参数为0;
Step2分析:
osMessageQueuePut 在中断中使⽤最终调⽤为:xQueueGenericSendFromISR
在单步追踪中:void vPortValidateInterruptPriority( void ),最终在此函数ASSERT断⾔
void vPortValidateInterruptPriority( void )
{
uint32_t ulCurrentInterrupt;
uint8_t ucCurrentPriority;
/* Obtain the number of the currently executing interrupt. */
ulCurrentInterrupt = vPortGetIPSR();
/* Is the interrupt number a ur defined interrupt? */
if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER )
{
/* Look up the interrupt's priority. */
ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ];
/* The following asrtion will fail if a rvice routine (ISR) for
an interrupt that has been assigned a priority above
configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
function.  ISR safe FreeRTOS API functions must *only* be called
from interrupts that have been assigned a priority at or below
configMAX_SYSCALL_INTERRUPT_PRIORITY.
Numerically low interrupt priority numbers reprent logically high
interrupt priorities, therefore the priority of the interrupt must
be t to a value equal to or numerically *higher* than
configMAX_SYSCALL_INTERRUPT_PRIORITY.
Interrupts that u the FreeRTOS API must not be left at their
default priority of zero as that is the highest possible priority,
which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY,
and therefore also guaranteed to be invalid.
FreeRTOS maintains parate thread and ISR API functions to ensure
interrupt entry is as fast and simple as possible.
The following links provide detailed information:
/RTOS-Cortex-M3-M4.html
/FAQHelp.html */
configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
}
/* Priority grouping:  The interrupt controller (NVIC) allows the bits
that define each interrupt's priority to be split between bits that
define the interrupt's pre-emption priority bits and bits that define
the interrupt's sub-priority.  For simplicity all bits must be defined
to be pre-emption priority bits.  The following asrtion will fail if
this is not the ca (if some bits reprent a sub-priority).
If the application only us CMSIS libraries for interrupt
configuration then the correct tting can be achieved on all Cortex-M
devices by calling NVIC_SetPriorityGrouping( 0 ); before starting the
scheduler.  Note however that some vendor specific peripheral libraries
assume a non-zero priority group tting, in which cas using a value
of zero will result in unpredictable behaviour. */
configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue );
}
configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
注释明⽩的讲明, 当前中断优先级⼤于等于FREERTOS系统能调⽤的最⼤优先级,起初以为FreeRTOS配置没对,将Timer、Systick等按MXCube⽣成的优先级进⾏调整,⽆作⽤。
FreeRTOS 控制的优先级范围:5~15
Timer:2 -> 5
Systick :0 -> 5
Step3分析:
既然⽹上搜到优先级不对,会不会是串⼝优先级 ⾼于 FreeRTOS的控制范围?
MXCube⾥将USART相关中断优先级降低⾄6,问题解决
总结:
MXCude好东西,解耦了需要对底层寄存器的理解,但对原理不稍微掌握,还是会出些难以预测的问题,在⽹上还不⼀定有答案。

本文发布于:2023-05-12 13:34:40,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/888148.html

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

标签:中断   队列   需要   接收
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图