-
Notifications
You must be signed in to change notification settings - Fork 5.3k
bsp: k230: add qspi driver #10885
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
base: master
Are you sure you want to change the base?
bsp: k230: add qspi driver #10885
Conversation
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]>
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: bsp_k230Reviewers: @unicornx Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-11-03 10:19 CST)
📝 Review Instructions
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 里应该看到的样子。
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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

结合一些微信群里的技术讨论,貌似有个叫 spi0 的对应了上表的 OSPI。
我觉得这里的配置存在一些问题,
- 首先,
BSP_USING_QSPI的定义很奇怪,我建议直接就叫BSP_USING_SPI - 第二级的
RT_USING_OSPI/RT_USING_QSPI0/RT_USING_QSPI1这种定义也不合适,不如就叫RT_USING_SPI0,RT_USING_SPI1和RT_USING_SPI2体现 K230 支持三个 SPI 控制器。 - 关键是我们需要让用户能够定义每个 SPI 控制器的具体能力,有四种选择, 标准 SPI, Dual SPI, Quad SPI,Octal SPI。假设
RT_USING_SPI0可以支持 4 种(即对应 TRM 表中的 0x9158_4000),那么RT_USING_SPI1和RT_USING_SPI1和RT_USING_SPI2就只支持 3 种。这个应该是做成可配置的。TRM 上似乎有寄存器可以配置不同模式,这个驱动代码种感觉没看出来啊? - 菜单里的注释也写得不对,目前看上去都是一样的能力了,但只有一个支持 4 种模式。
| * The maximum clock frequency is 200 MHz. | ||
| */ | ||
| #ifdef RT_USING_OSPI | ||
| static k230_qspi_bus_t ospi_bus0; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最后一行要有一个空行,github 上已经有红色的告警了,一个红色的圆圈,中间一个减号那个。
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):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up