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 27, 2025
@github-actions
Copy link

github-actions bot commented Aug 27, 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_uart.c
  • bsp/k230/rtconfig.h

📊 Current Review Status (Last Updated: 2025-08-28 18:07 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.

@unicornx unicornx self-requested a review August 27, 2025 06:12
@unicornx
Copy link
Contributor

unicornx commented Aug 27, 2025

该 PR 继续 #10628

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,第一次见 #10628

除了下面的代码中的 comments 外, commit 的标题中前缀请加空格,“bsp: k230: xxxx"

Copy link
Contributor

Choose a reason for hiding this comment

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

RT_CONSOLE_DEVICE_NAME 这个配置你忘记改了,应该恢复成默认配置 uart0, 否则控制台无法工作

Copy link
Contributor Author

Choose a reason for hiding this comment

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

抱歉,这个是我的疏忽

rt_uint32_t uart_to_size;
rt_uint32_t irqno;

#ifdef BSP_UART_USING_DMA
Copy link
Contributor

Choose a reason for hiding this comment

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

#ifdef 和 下面的 #end 请顶格写, 不要和代码一起缩进。这个问题你全文检查一下。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到

#define read32(addr) readl((void*)(addr))

#ifdef BSP_UART_USING_DMA
static void _k230_uart_pdma_call_back(rt_uint8_t ch, rt_bool_t is_done)
Copy link
Contributor

Choose a reason for hiding this comment

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

这个函数和其他 dma 相关函数放一起。我希望代码整理后用条件编译(BSP_UART_USING_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.

好的

K230_UART_PDMA_EVENT_COMPLETE,
K230_UART_PDMA_EVENT_TIMEOUT
} uart_pdma_event_t;
#endif
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_pdma_call_back 放在一起。

static rt_ssize_t _uart_dma_tran(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction);
#endif

const struct rt_uart_ops _uart_ops =
Copy link
Contributor

Choose a reason for hiding this comment

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

你调整一下 _uart_ops 的位置,放到文件的后面(rt_hw_uart_init() 之前)也是可以的,这样我理解上面部分函数声明都不需要了。你整理一下代码看看?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,我看一下

drv_uart_getc,
//TODO: add DMA support
RT_NULL
.configure = _rt_uart_configure,
Copy link
Contributor

Choose a reason for hiding this comment

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

_rt_uart_configure() 这个函数我们并没有实现什么,就不需要定义可,直接设置回调为 NULL。

Copy link
Contributor Author

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.

这个东西我后来尝试了一下,如果去掉的话,测试会报错,得加上

LOG_E("Failed to init DMA for %s, ret=%d\n", dev->name, ret);
return ret;
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

这一块代码缩进有问题,用 format 工具检查过吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

检查过,只不过感觉format工具有点问题,比如行尾空格消不掉

rt_hw_interrupt_umask(uart->irqno);
rt_uint32_t flags;
flags = RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX;
#ifdef BSP_UART_USING_DMA
Copy link
Contributor

Choose a reason for hiding this comment

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

#ifdef /#endif 不要和代码一起缩进,容易看混了。

@DannyRay019
Copy link
Contributor Author

汪老师,那个_rt_uart_configure我尝试去掉之后,测试会报错,还是需要加上的

@DannyRay019 DannyRay019 requested a review from unicornx August 28, 2025 00:42
@unicornx
Copy link
Contributor

汪老师,那个_rt_uart_configure我尝试去掉之后,测试会报错,还是需要加上的

具体测试什么?会报什么错?直接给 .configure 赋值 RT_NULL 不行吗?

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,主要看了一下 test 部分代码。

Copy link
Contributor

Choose a reason for hiding this comment

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

对于测试,有个问题,为啥不能 TX 要用 uart3?能否也用 uart0?
用 uart3 还要另外配置以及接线,会不会很麻烦?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,我待会再尝试一下,这个主要是涉及到要用dma的flag打开uart设备,用完之后可能没法正常用uart进行其他的输入输出了

serial = rt_container_of(uart_dev, struct rt_serial_device, parent);
uassert_not_null(serial);
size_t len = TEXT_LENGTH;
ret = rt_device_write(serial,0,msg,len);
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.

好的

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
@unicornx unicornx requested a review from Rbb666 August 29, 2025 02:32
@unicornx
Copy link
Contributor

@Rbb666 请 review & merge 如果没问题的话。谢谢。

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.

第 4 次 review

@Rbb666 Rbb666 merged commit 500deb8 into RT-Thread:master Aug 29, 2025
36 checks passed
@Rbb666 Rbb666 added this to the v5.2.2 milestone Sep 23, 2025
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.

3 participants