Skip to content

Conversation

@DannyRay019
Copy link
Contributor

Added pdma support for uart driver and a test file test_uart.c. The test uses pdma to improve uart send speed,
to check if the driver works correctly.

Signed-off-by: XU HU 1337858472@qq.com

@github-actions github-actions bot added the BSP label Aug 21, 2025
@github-actions
Copy link

github-actions bot commented Aug 21, 2025

📌 Code Review Assignment

🏷️ Tag: bsp_k230

Reviewers: unicornx

Changed Files (Click to expand)
  • bsp/k230/.config
  • bsp/k230/board/Kconfig
  • bsp/k230/drivers/interdrv/uart/drv_uart.c
  • bsp/k230/drivers/interdrv/uart/drv_uart.h
  • bsp/k230/drivers/utest/SConscript
  • bsp/k230/drivers/utest/test_pdma.c
  • bsp/k230/drivers/utest/test_uart.c
  • bsp/k230/rtconfig.h

📊 Current Review Status (Last Updated: 2025-08-27 10:59 CST)

  • unicornx Pending Review

📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@DannyRay019
Copy link
Contributor Author

麻烦 @unicornx 帮忙review一下

@unicornx unicornx self-requested a review August 24, 2025 08:41
Copy link
Contributor

@unicornx unicornx left a comment

Choose a reason for hiding this comment

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

第一次 review

看得比较粗糙。提了些 genernal 的问题请看一下。比较大的问题是有关 uart 这里如何使用 dma 的方式,是否每次 write 时都要怎么操作一遍?还是一开始就申请好?这个操作方式上有些疑问。

btw:commit 的 title 上请加些空格,不要挤在一起:譬如写成:"bsp: k230: add ....."

if BSP_USING_UART
config BSP_USING_UART0
bool "Enable UART0"
default n
Copy link
Contributor

Choose a reason for hiding this comment

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

这个 default y 吧

rt_uint32_t irqno;
};

/* 支持的 UART 设备列表 */
Copy link
Contributor

Choose a reason for hiding this comment

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

代码中尽量不要用中文注释,这个问题请全文检查

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

}

UTEST_TC_EXPORT(test_pdma, "pdma", utest_tc_init, utest_tc_cleanup, 10);
UTEST_TC_EXPORT(test_pdma, "pdma", utest_tc_init, utest_tc_cleanup, 10);
Copy link
Contributor

Choose a reason for hiding this comment

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

为何会改动这个文件?

static void uart_tx_demo(void)
{
rt_device_t uart_dev;
char *msg = rt_malloc(2024);
Copy link
Contributor

Choose a reason for hiding this comment

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

为啥是 2024?为啥不用宏?

请尽量避免用立即数,此问题全文检查

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯嗯,这里2024就是随便搞个比较大的数测试

* - 本测试基于 K230 平台;
* - UART3 为开发板上的一个串口接口;
* - 发送的数据为 2023 个 '[' 字符,可通过串口调试工具观察输出;
* - 本测试仅验证 DMA 发送路径是否正常,不包含接收功能。
Copy link
Contributor

Choose a reason for hiding this comment

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

为啥不测试接收功能?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我研究了一下,关于uart做dma接收的功能有点困难,dma驱动里面有一个超时回调,如果是用rt_device_open去测试接受功能的话,没法做延时几秒等待键盘发送字符,目前关于接受功能的实现我还没有什么头绪。


/*
* 测试 UART3 在 DMA 模式下的数据发送功能
*
Copy link
Contributor

Choose a reason for hiding this comment

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

感觉如果真要测试 uart3,需要注明一下编译时配置上要专门 enable uart3

*/

#include <rthw.h>
#include <rtdevice.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

请把 drv_uart.c 开头的 license 也顺便整理一下。

同理请将 drv_uart.h 开头的 license 也整理一下。

和其他驱动文件保证一致。

另外 drv_uart.h 中声明的一些函数好像没用了,也清理一下吧。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

#include <lwp_user_mm.h>
#include <ioremap.h>

#include <rtdbg.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

为何要加这个?

TEST_PDMA_EVENT_NONE,
TEST_PDMA_EVENT_COMPLETE,
TEST_PDMA_EVENT_TIMEOUT
} test_pdma_event_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

不要代码拿过来就用。这里主要存在一个变量、类型的命名问题。

作为 k230 uart 的驱动的一部分,我建议你把全文的符号(变量名、函数名、常量...) 都加上相应的前缀。譬如统一加上 "k230_uart_" 这样的前缀。

对 global 的函数加上统一的前缀,尽量避免名字污染。
static 的函数可以不加,但最好加上一些特殊标记,譬如以下划线开头标识这是一个内部符号 ......

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

/* Configure DMA transfer */
err = k230_pdma_request_channel(&ch);

usr_pdma_cfg_t pdma_cfg;
Copy link
Contributor

Choose a reason for hiding this comment

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

这个 cfg 对象每次 write 都要初始化一次?效率是不是很低啊?打个比方,如果我发送 100 次一个字节的数据,也要初始化 100 次?

能不能建一个 dma channel 让多个 uart 通道复用,当然这要考虑一下上锁互斥的问题。
或者一个 uart 占一个 dma channel?

你研究一下呢?

总之目前的做法看上去效率会有点低哎,不清楚的话,可以去问问 canaan 的人有什么好方法。

BTW, uart_canaan 里的 dma 是怎么用的?我还没仔细看过。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,这个我研究一下

Added pdma support for uart driver and a test file test_uart.c.
The test uses pdma to improve uart send speed,
to check if the driver works correctly.

Signed-off-by: XU HU 1337858472@qq.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants