Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[serial] 增加serial_v2版本的框架和基于stm32的串口驱动 #4764

Merged
merged 4 commits into from
Jun 21, 2021
Merged

[serial] 增加serial_v2版本的框架和基于stm32的串口驱动 #4764

merged 4 commits into from
Jun 21, 2021

Conversation

KyleChenjh
Copy link

拉取/合并请求描述:(PR description)

[
该PR增加了串口框架V2版本,定义了 serial_v2.[c/h] 以及基于stm32的 drv_usart.[c/h] ,解决了当前串口的一些问题:

  1. 中断发送存在问题:中断发送对接的是轮询接口,导致性能不足,且有概率出现线程无法让出,造成看门狗复位等问题。
  2. 模式(POLL、INT和DMA)不同会影响API接口的行为不同:当用户选择使用非DMA模式时是阻塞发送,即数据发送完毕才正常返回。而选择DMA模式发送时,属于非阻塞发送,即发送的buffer是栈指针,会随着函数返回而被释放,由于发送接口是立即返回的,这个时候数据并未真正发送出去,因此当这段内存被修改的话就会造成丢包的问题。

本次版本的串口框架,有以下特点:

  1. 用户层使用方式与之前的兼容,接口完全一致
  2. 增加中断发送模式
  3. 串口打开时,不再明确指出打开模式(RT_DEVICE_FLAG_INT_xxRT_DEVICE_FLAG_DMA_xx, xx代表RX或者TX),而是通过静态配置的方式选择具体工作模式,工作模式按照如下优先级进行选择:DMA>INT>POLL ,即能使用DMA的话就配置串口为DMA工作方式,接收发送均按照这个优先级规则。
  4. 承接第3点,串口打开时候的打开模式改变为阻塞非阻塞的方式,即( RT_DEVICE_FLAG_xx_BLOCKINGRT_DEVICE_FLAG_xx_NON_BLOCKING ),用户一般的应用场景是阻塞发送,非阻塞接收。即 RT_DEVICE_FLAG_TX_BLOCKINGRT_DEVICE_FLAG_RX_NON_BLOCKING 这也是两个版本的串口使用上的唯一差别。举例说明:
// 早期版本:
    rt_device_open(serial, RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_TX);
// 现在版本:
    rt_device_open(serial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);

目前新版本的串口框架已经在STM32L475-Pandora平台进行了全部的适配(适配上包括Kconfig和SConscript等文件的修改),用户也可先对比这些修改的内容,适配到自己的STM32平台上进行测试使用。另外针对本版本的串口,也一直在ART-PI平台上进行测试和迭代,用户也可在ART-PI的仓库进行测试。

]

以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 本拉取/合并请求代码是高质量的 Code in this PR is of high quality
  • 本拉取/合并符合RT-Thread代码规范 This PR complies with RT-Thread code specification

rt_uint32_t tx_flag);
};

rt_size_t rt_serial_get_linear_buffer(struct rt_ringbuffer *rb,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要导出的函数,放到框架内部吧

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经提交修改。

}

uart->dma_rx.remaining_cnt = index;
rt_serial_update_write_index(&(rx_fifo->rb), recv_len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分的操作不能放到框架内部吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经修改了,这部分按照框架内部函数使用,与底层驱动解耦了。

@BernardXiong
Copy link
Member

为什么命名成_v2.c?老的还需要保留?

@Guozhanxin
Copy link
Member

为什么命名成_v2.c?老的还需要保留?

是的,虽然应用层接口都兼容,但是底层还是有些区别的。不能简单的替换掉之前的。

@KyleChenjh
Copy link
Author

为什么命名成_v2.c?老的还需要保留?

是的,虽然应用层接口都兼容,但是底层还是有些区别的。不能简单的替换掉之前的。
所以目前是在stm平台上提交了一份drv_usart_v2,后续也会在其它用新版本串口框架的平台上全部刷一遍底层驱动。等过渡完毕老版本的就可以废弃掉了。

@Guozhanxin
Copy link
Member

跟满老师他们讨论了下,说可以先合并内测

@BernardXiong BernardXiong merged commit bccdf91 into RT-Thread:master Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants