前言
- 测试环境为rt-thread 5.0 版本使用serial_v2版本+ota组件包,使用的芯片为stm32f407zgt6
- 测试发现数据升级过程中出现升级包发送完成,程序却卡在打印输出位置.
- 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;
}