RT-Thread之ota组件和serial_v2组件结合使用出现的问题记录

前言

  1. 测试环境为rt-thread 5.0 版本使用serial_v2版本+ota组件包,使用的芯片为stm32f407zgt6
  2. 测试发现数据升级过程中出现升级包发送完成,程序却卡在打印输出位置.
  3. serial_v2和ota的兼容性问题

问题现象

调试截图

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

出现的原因

在这里插入图片描述

排查问题原因

串口V2版本

在这里插入图片描述

解决思路

在这里插入图片描述

修改后代码

rt_err_t rym_recv_on_device(
    struct rym_ctx *ctx,
    rt_device_t dev,
    rt_uint16_t oflag,
    rym_callback on_begin,
    rym_callback on_data,
    rym_callback on_end,
    int handshake_timeout)
{
    rt_err_t res = 0;
    rt_err_t (*odev_rx_ind)(rt_device_t dev, rt_size_t size);
    rt_uint16_t odev_flag;
    rt_base_t level;

    RT_ASSERT(_rym_the_ctx == 0);
    _rym_the_ctx = ctx;

    ctx->on_begin = on_begin;
    ctx->on_data  = on_data;
    ctx->on_end   = on_end;
    ctx->dev      = dev;
    rt_sem_init(&ctx->sem, "rymsem", 0, RT_IPC_FLAG_FIFO);

    odev_rx_ind = dev->rx_indicate;
    /* no data should be received before the device has been fully setted up.
     */
    level = rt_hw_interrupt_disable();
    rt_device_set_rx_indicate(dev, _rym_rx_ind);

    odev_flag = dev->open_flag;
    /* make sure the device don't change the content. */
    dev->open_flag &= ~RT_DEVICE_FLAG_STREAM;

    rt_hw_interrupt_enable(level);
#ifdef RT_USING_SERIAL_V2
    static rt_err_t odev_stat; /*用于判断上一次使用的设备后面是否需要打开*/
    odev_stat = rt_device_close(dev);
    if (odev_stat != RT_EOK)
        goto __exit;
#endif
    res = rt_device_open(dev, oflag);
    if (res != RT_EOK)
        goto __exit;

    res = _rym_do_recv(ctx, handshake_timeout);

    rt_device_close(dev);

__exit:
    /* no rx_ind should be called before the callback has been fully detached.
     */
    level = rt_hw_interrupt_disable();
    rt_sem_detach(&ctx->sem);
    rt_device_set_rx_indicate(dev, odev_rx_ind);
#ifdef RT_USING_SERIAL_V2
    if (odev_stat == RT_EOK) {
        rt_device_open(dev, odev_flag);
    }else{
        dev->open_flag=odev_flag;
    }
#else
    dev->open_flag=odev_flag;
#endif
    rt_hw_interrupt_enable(level);

    _rym_the_ctx = RT_NULL;

    return res;
}

测试结果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

詩不诉卿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值