Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ChuanN-sudo
Copy link

Requirement: The BSP for the k230 platform in the RT-Thread repository does not yet have an spi driver.

Solution: Provide QSPI driver for the k230 platform in the RT-Thread repository.

  • Supports OSPI controller with 1/2/4/8 data lines.

  • Supports QSPI0 and QSPI1 controllers with 1/2/4 data lines.

  • Implements DMA-based transfers for OSPI, QSPI, and DSPI modes.

  • Falls back to standard IRQ-driven transfers for legacy SPI mode (single line).

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

[

为什么提交这份PR (why to submit this PR)

为K230添加qspi驱动

你的解决方案是什么 (what is your solution)

添加qspi驱动

请提供验证的bsp和config (provide the config and bsp)

  • BSP:/bsp/k230/drivers/interdrv/qspi

  • .config:

  • action:

]

当前拉取/合并请求的状态 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
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

Requirement: The BSP for the k230 platform in the RT-Thread repository does not yet have an spi driver.

Solution: Provide QSPI driver for the k230 platform in the RT-Thread repository.

- Supports OSPI controller with 1/2/4/8 data lines.

- Supports QSPI0 and QSPI1 controllers with 1/2/4 data lines.

- Implements DMA-based transfers for OSPI, QSPI, and DSPI modes.

- Falls back to standard IRQ-driven transfers for legacy SPI mode (single line).

Signed-off-by: ChuanN <[email protected]>
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:k230_qspi_driver
  • 设置PR number为 \ Set the PR number to:10885
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 k230_qspi_driver 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the k230_qspi_driver branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions bot added the BSP label Nov 3, 2025
@github-actions
Copy link

github-actions bot commented Nov 3, 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/qspi/SConscript
  • bsp/k230/drivers/interdrv/qspi/drv_qspi.c
  • bsp/k230/drivers/interdrv/qspi/drv_qspi.h
  • bsp/k230/drivers/utest/SConscript
  • bsp/k230/drivers/utest/test_qspi.c
  • bsp/k230/rtconfig.h

📊 Current Review Status (Last Updated: 2025-11-03 10:19 CST)


📝 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.

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.

见下述评论,最主要的问题是目前的实现看上去没有考虑对三个 SPI 控制器的能力配置,请再研究一下,是否可以改进?

另外请将基线 rebase 到最新的 master,至少要高于 666fa24,并请参考一下 #10851#10869,新的对 k230 的驱动改动都需要更新 bsp/k230/.ci/attachconfig/ci.attachconfig.yml 文件了。

Copy link
Contributor

Choose a reason for hiding this comment

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

.config 上 enable 了一些本地测试的开关,譬如 utest 相关的,以及譬如 CONFIG_RT_USING_SPI 等。spi 和 utest 的开关默认应该都是关闭的。
正确的做法是,基于最新的 master 修改完 Kconfig 后,只运行一次 scons --menuconifg 保存后就是 pr 里应该看到的样子。

Copy link
Author

Choose a reason for hiding this comment

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

明白了,我改一下


config RT_USING_QSPI1
bool "Enable QSPI1(Support 1 2 4 and 8 lines)"
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.

我理解 k230 应该是有三个 SPI 的控制器,对照 TRM 的 1.5 章节,有两个 QSPI,一个 OSPI
image

结合一些微信群里的技术讨论,貌似有个叫 spi0 的对应了上表的 OSPI。

我觉得这里的配置存在一些问题,

  • 首先, BSP_USING_QSPI 的定义很奇怪,我建议直接就叫 BSP_USING_SPI
  • 第二级的 RT_USING_OSPI/RT_USING_QSPI0/RT_USING_QSPI1 这种定义也不合适,不如就叫 RT_USING_SPI0, RT_USING_SPI1RT_USING_SPI2 体现 K230 支持三个 SPI 控制器。
  • 关键是我们需要让用户能够定义每个 SPI 控制器的具体能力,有四种选择, 标准 SPI, Dual SPI, Quad SPI,Octal SPI。假设 RT_USING_SPI0 可以支持 4 种(即对应 TRM 表中的 0x9158_4000),那么 RT_USING_SPI1RT_USING_SPI1RT_USING_SPI2 就只支持 3 种。这个应该是做成可配置的。TRM 上似乎有寄存器可以配置不同模式,这个驱动代码种感觉没看出来啊?
  • 菜单里的注释也写得不对,目前看上去都是一样的能力了,但只有一个支持 4 种模式。

* The maximum clock frequency is 200 MHz.
*/
#ifdef RT_USING_OSPI
static k230_qspi_bus_t ospi_bus0;
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么不定义成数组,而是一个bus 一个?看上去比较奇怪,请尝试优化一下,可以参考一下其他的驱动代码。

*/
#ifdef RT_USING_QSPI0
static k230_qspi_bus_t qspi_bus0;
qspi_bus0.base = rt_ioremap((void *)SPI_QOPI_BASE_ADDR, SPI_OPI_IO_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

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

不要用 SPI_OPI_IO_SIZE, 很让人迷惑。用 SPI_QOPI_IO_SIZE / 2 还好看些。

*/
#ifdef RT_USING_QSPI1
static k230_qspi_bus_t qspi_bus1;
qspi_bus1.base = rt_ioremap((void *)SPI_QOPI_BASE_ADDR + SPI_OPI_IO_SIZE, SPI_OPI_IO_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

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

和上面一样的道理,不要 QPI 和OPI 混着用,代码可读性太差。

#endif
return RT_EOK;
}
INIT_DEVICE_EXPORT(rt_hw_qspi_bus_init); No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

最后一行要有一个空行,github 上已经有红色的告警了,一个红色的圆圈,中间一个减号那个。

@ChuanN-sudo ChuanN-sudo requested a review from unicornx November 4, 2025 11:56
@unicornx unicornx added the Arch: RISC-V BSP related with risc-v label Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: RISC-V BSP related with risc-v BSP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants