mutex - 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?
解决方案
通常,只有一个线程应该与 ISR 通信。如果多个线程正在访问与 ISR 共享的变量,则您的设计是错误的,需要修复。在 DMA 的情况下,只有一个线程应该访问缓冲区。
您需要保护该线程和 ISR 之间共享的变量 - 不一定使用互斥锁/信号量,但可能使用更简单的方法,例如保证原子访问(如果可能,最好的解决方案),或者使用许多 ISR 的不可中断能力有。简单的单线程 MCU 应用示例。或者只是在访问期间暂时禁用中断,但这可能是不可能的,具体取决于实时要求。
推荐阅读
- bash - 如何使这个 bash prime 生成器更快 [SPOJ]
- java - Java Collections.sort() 比较器
- c# - “时间戳中位置 20 的语法错误” Azure 表存储查询问题
- ios - Swift 4 · 数据转换
- python - 获取火花数据帧写入的文件名
- c# - 没有端点监听
可以接受消息的 - r - 如何仅从整数值中减去中位数
- ios - “查找调用层次结构”在 Xcode 中不起作用(带有 cocoapods 的大项目)
- ubuntu - 在 ubuntu 18.04 上安装 nginx 会出现 502 Connection timed out 错误
- asp.net - Angular 5 - POST 请求引发解析 JSON 错误但成功插入数据