10 串口频繁热插拔,会导致msg queue收不到消息

发布于 2021-07-21 21:29:07    浏览:112

串口频繁热插拔,会导致msg queue收不到消息。上代码如下
串口回调函数
static rt_err_t uart_rx_ind(rt_device_t dev, rt_size_t size)
{

rt_uint16_t data_size = size;

rt_mq_send(s_uart_queue,&data_size, 2);
return RT_EOK;

}
串口使用DMA RX 和 DMA TX
rt_device_open(s_uart_device, RT_DEVICE_OFLAG_RDWR |RT_DEVICE_FLAG_DMA_RX | RT_DEVICE_FLAG_DMA_TX); //
rt_device_set_rx_indicate(s_uart_device, uart_rx_ind);
s_uart_queue = rt_mq_create("uart3_Q",2,20,0);

串口数据读取

    while (1)
    {
        /* wait receive */
        if (RT_EOK == rt_mq_recv(s_uart_queue,&recv_len,2,RT_WAITING_FOREVER))
        {
            recv_len = rt_device_read(s_uart_device, 0, s_recv_buf, recv_len);
            if ( recv_len > 0 && recv_len <= BUF_LEN)
            {
                recv_data_process(s_recv_buf,recv_len,s_send_buf + 2,&send_len, RT_TRUE);
                *(rt_uint16_t *)s_send_buf = send_len;
                rt_device_write(s_uart_device, 0, s_send_buf, send_len + 2);
            }
            else
            {
                LOG_D("uart3 server: receive len error,len=%d\n",recv_len);
            }
        }
    }

正常情况下
1.png
热插拔几次后
2.png
线程中rt_mq_recv再也收不到消息,回调函数是一直有执行的,也就是串口是能接收到数据的, 似乎rt_mq_send无法激活线程了,把线程优先级调高也无效。把串口改为中断接收也一样,但是似乎出问题没那么频繁了

查看更多

3 个回答
123
123 认证专家 2 days ago
This guy hasn't written anything yet

怀疑和这个有关,楼主可以试下这个:
https://club.rt-thread.org/ask/question/432055.html

出出啊
出出啊 1 day ago
This guy hasn't written anything yet

你好,你试试把里面的大段内容先修饰掉,里面只留一个打印 rt_mq_recv 返回后,只打印一下 recv_len 的值。

cris8259
cris8259 1 day ago
This guy hasn't written anything yet

https://club.rt-thread.org/ask/question/432055.html
这个帖子跟我的现象是一样的,说明不是个例

撰写答案

请登录后再发布答案,点击登录
关注者
0
被浏览
112

发布
问题

分享
好友

手机
浏览

扫码手机浏览