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

[bsp][stm32] 增加uart的DMA发送功能 #2645

Merged
merged 11 commits into from
May 23, 2019

Conversation

zhouchuanfu
Copy link
Contributor

@zhouchuanfu zhouchuanfu commented May 3, 2019

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

[
增加uart的DMA发送功能。
此次修改会影响stm32目录下的其他bsp,需要修改
“rt-thread/bsp/stm32/libraries/HAL_Drivers/config/芯片类型目录/”
目录下的uart_config.h和dma_config.h,具体可参照 f4 芯片类型修改。
]

以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use 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 style
  • 没有垃圾代码,代码尽量精简,不包含#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

@zhouchuanfu zhouchuanfu changed the title [bsp][stm32] 增加串口DMA发送功能 [bsp][stm32] 增加uart的DMA发送功能 May 3, 2019
Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 87.50%
Passed: 14/16

点击查看详情

@zhouchuanfu
Copy link
Contributor Author

这个有两项检查没有成功,看了一下都是stm32F103的开发板,在检查的时候发现uart的dma定义变了所以检查不通过,这个要怎么处理呀!

@BernardXiong
Copy link
Member

需要对编译失败的两个BSP都进行修改,以确保无错。

Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 87.50%
Passed: 14/16

点击查看详情

@BernardXiong BernardXiong requested a review from misonyo May 4, 2019 14:33
Copy link
Member

@SummerGift SummerGift left a comment

Choose a reason for hiding this comment

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

先解决一下冲突吧,正在看这个 PR,最近 serial.c 有一点修改。

components/drivers/serial/serial.c Outdated Show resolved Hide resolved
Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 100.00%
Passed: 16/16

点击查看详情

@SummerGift
Copy link
Member

看上面你的回复,只添加 f4 系列的 DMA 发送的话在 ci 的时候 F1 系列会报错,所以你添加了 F1 系列的DMA 发送的配置是吗?

@zhouchuanfu
Copy link
Contributor Author

是的,就是因为这个原因。

添加部分空行
Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 100.00%
Passed: 16/16

点击查看详情

Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 93.75%
Passed: 15/16

点击查看详情

Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 43.75%
Passed: 7/16

点击查看详情

@SummerGift
Copy link
Member

@zhouchuanfu 有很多测试用例没有通过,可以瞧瞧是哪里逻辑改的不太对了

@zhouchuanfu
Copy link
Contributor Author

好的

Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 43.75%
Passed: 7/16

点击查看详情

Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 43.75%
Passed: 7/16

点击查看详情

Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 93.75%
Passed: 15/16

点击查看详情

@SummerGift
Copy link
Member

SummerGift commented May 21, 2019

我测试进行 DMA 发送时,程序会卡在 stm32_dma_config() 函数的这一句,不太清楚是怎么回事

        __HAL_UART_CLEAR_FLAG(&(uart->handle), UART_FLAG_TC);
        while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET)
        {
            ;
        }

@zhouchuanfu

上面那一句代码清除中断标志,后面这几句就一直等下去了。

Copy link
Member

@SummerGift SummerGift left a comment

Choose a reason for hiding this comment

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

另外现在 shell 的 DMA 方式还支持流模式,在 _serial_dma_tx 函数中实现,此时如果以 DMA 发送方式打开 shell 设备,就会出现只有换行没有回车的情况出现,如果有兴趣后面也可以为 shell DMA 发送添加流模式 RT_DEVICE_FLAG_STREAM

在该模式下,在 serial.c 文件中,shell 以轮询方式进行输出,会对 /n 字符进行处理,自动添加 /r,代码如下:

        if (*data == '\n' && (serial->parent.open_flag & RT_DEVICE_FLAG_STREAM))
        {
            serial->ops->putc(serial, '\r');
        }

不过话说回来,DMA 发送的流模式也没有太大意义,毕竟使用 DMA 是为了效率为先,所以这个还是不要加了,我只是提一下,有这个问题。以什么符号为换行符,可以在终端里面配置吧。

@zhouchuanfu
Copy link
Contributor Author

是的 可能单字节使用dma有点浪费

@SummerGift
Copy link
Member

是的 可能单字节使用dma有点浪费

这里的问题是,要将发送的数据中的所有 \n 前面添加 \r ,这样其实就多了一遍的遍历操作,大大降低了 DMA 的发送效率。

修复dma_config里面rcc的bug。
Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 100.00%
Passed: 16/16

点击查看详情

@zhouchuanfu
Copy link
Contributor Author

大概理解你的意思了,如果要改的话可以有两种思路,一种是在缓存+算法添加修改\r,理论上在控制台缓存定义位置需要添加一定大小用于扩展, 一种是通过调度+算法来解决,提前计算出\n的位置以及到这个位置的数据长度,并启动dma发送,然后再发送\r\n,之后再计算再发送,直到发送完毕。

@SummerGift
Copy link
Member

大概理解你的意思了,如果要改的话可以有两种思路,一种是在缓存+算法添加修改\r,理论上在控制台缓存定义位置需要添加一定大小用于扩展, 一种是通过调度+算法来解决,提前计算出\n的位置以及到这个位置的数据长度,并启动dma发送,然后再发送\r\n,之后再计算再发送,直到发送完毕。

嗯,这个可以修改解决,先把驱动弄好可以后面再考虑这个问题,

Copy link
Contributor

@rtthread-bot rtthread-bot left a comment

Choose a reason for hiding this comment

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

AutoTest Result

Rate: 100.00%
Passed: 16/16

点击查看详情

@zhouchuanfu
Copy link
Contributor Author

这个已经修复过了,可以进行测试了

@SummerGift
Copy link
Member

这个已经修复过了,可以进行测试了

好的,等会儿我看一下。

@SummerGift
Copy link
Member

SummerGift commented May 23, 2019

这个已经修复过了,可以进行测试了

经过测试,功能上没有问题了,我再检查一下关于 DMA 的配置相关的。

Copy link
Member

@SummerGift SummerGift left a comment

Choose a reason for hiding this comment

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

经过测试,串口 DMA 发送功能正常。

@SummerGift
Copy link
Member

@misonyo 我这边已经 review 过了,你可以进一步试试了。

@BernardXiong BernardXiong merged commit e8a10c4 into RT-Thread:master May 23, 2019
@zhouchuanfu zhouchuanfu deleted the stm32_uart_tx_dma branch June 5, 2019 13:41
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.

None yet

4 participants