首页 > 解决方案 > Uart dma receive interrupt stops receiving data after several minutes

问题描述

I have a project that I have used stm32f746g discovery board. It receives data with fixed size from Uart sequentially and to inform application about each data receive completed, dma callback is used (HAL_UART_RxCpltCallback function). It works fine at the beginning but after several minutes of running, the dma callback stops to be called, and as a result, the specified parameter value doesn't get updated. Because the parameter is used in another thread too (actually a rtos defined timer), I believe this problem is caused by lacking of thread safety. But my problem is that mutex and semaphore don't be supported in ISRs and I need to protect my variable in dma callback which is an interrupt routine. I am using keil rtx to handle multithreading and the timer I use is osTimer that is defined in rtx. How can I handle the issue?

标签: mutexsemaphoreuartdmastm32f7

解决方案


通常,只有一个线程应该与 ISR 通信。如果多个线程正在访问与 ISR 共享的变量,则您的设计是错误的,需要修复。在 DMA 的情况下,只有一个线程应该访问缓冲区。

您需要保护该线程和 ISR 之间共享的变量 - 不一定使用互斥锁/信号量,但可能使用更简单的方法,例如保证原子访问(如果可能,最好的解决方案),或者使用许多 ISR 的不可中断能力有。简单的单线程 MCU 应用示例。或者只是在访问期间暂时禁用中断,但这可能是不可能的,具体取决于实时要求。


推荐阅读