几分钟后Uart dma接收中断将停止接收数据 [英] Uart dma receive interrupt stops receiving data after several minutes
问题描述
我有一个使用过stm32f746g发现板的项目.它顺序地从Uart接收具有固定大小的数据,并通知应用程序每个接收到的数据已完成,并使用dma回调(HAL_UART_RxCpltCallback函数).它在一开始就可以正常工作,但是在运行了几分钟后,dma回调停止被调用,结果,指定的参数值没有得到更新.因为该参数也在另一个线程中使用(实际上是rtos定义的计时器),所以我认为此问题是由于缺乏线程安全性引起的.但是我的问题是ISR不支持互斥锁和信号量,我需要在dma回调(这是一个中断例程)中保护我的变量.我正在使用keil rtx处理多线程,而我使用的计时器是rtx中定义的osTimer.我该如何处理该问题?
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?
推荐答案
通常,只有一个线程应该与ISR通信.如果多个线程正在访问与ISR共享的变量,则您的设计是错误的,需要修复.如果是DMA,则只有一个线程可以访问该缓冲区.
Generally, only one thread should communicate with the ISR. If multiple threads are accessing a variable shared with an ISR, your design is wrong and needs to be fixed. In case of DMA, only one thread should access the buffer.
您需要保护该线程与ISR之间共享的变量-不一定要使用互斥锁/信号量,而可能需要使用诸如保证原子访问(如果可能的话,最好的解决方案)之类的更简单方法,或者通过使用不间断的能力来保护许多ISR都有. 简单的单线程MCU应用示例.或者,只是在访问期间暂时禁用中断,但这可能是不可能的,具体取决于实时要求.
You'll need to protect the variables shared between that thread and the ISR - not necessarily with a mutex/semaphore but perhaps with something simpler like guaranteeing atomic access (best solution if possible), or by using the non-interrruptable abilitiy that many ISRs have. Example for simple, single-threaded MCU applications. Alternatively just temporarily disable interrupts during access, but that may not be possible, depending on real-time requirements.
这篇关于几分钟后Uart dma接收中断将停止接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!