Skip to content

[components][ospi] Add OctaFlash Support - #11912

Open
CliffLL wants to merge 4 commits into
RT-Thread:masterfrom
CliffLL:octaflash-driver
Open

CliffLL wants to merge 4 commits into
RT-Thread:masterfrom
CliffLL:octaflash-driver

Conversation

@CliffLL

@CliffLL CliffLL commented Oct 21, 2026 •

Copy link
Copy Markdown

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

[

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

RT-Thread currently lacks a native OSPI path for accessing OctaFlash through its SPI driver layer and SFUD.

This PR adds OSPI support at the components layer while retaining the existing SPI and QSPI paths. To validate the complete path on hardware, it also adds a generic STM32 OctoSPI driver and board-level OSPI Flash support for the stm32l4r9-st-eval BSP. Together, these changes enable SFUD to access the Flash in 1-1-1 and 8-8-8 (OPI STR/DTR) modes.

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

  • Add OSPI bus, device, configuration, and message definitions, along with OSPI transfer helpers and build options in the SPI driver layer.
  • Integrate OSPI transfers and device probing with SFUD, including read, write, erase, and Flash status/control operations. Add MX25LM51245G to the SFUD device table for validation.
  • Add a generic STM32 OctoSPI low-level driver under HAL_Drivers, with STM32L4 controller configuration and build integration.
  • Add OctaFlash support to the stm32l4r9-st-eval BSP, including OCTOSPI1 pin/clock/MSP configuration and helpers for entering OPI STR/DTR modes.
  • Fix the BSP heap/linker layout to avoid the observed .bss overlap , build the BSP with GCC and run it on the board. Update the board documentation and regenerate the MDK5 and IAR projects.

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

  • BSP: bsp/stm32/stm32l4r9-st-eval/
  • .config: Enable the following options in menuconfig.
    1. Hardware Drivers Config/Onboard Peripheral Drivers/Enable OctaFlash (MX25LM51245GXDI00)
    2. Hardware Drivers Config/On-chip Peripheral Drivers/Enable OSPI BUS
    3. RT-Thread Components/Device Drivers/Using SPI Bus/Device device drivers/Using OSPI mode support
    4. RT-Thread Components/Device Drivers/Using SPI Bus/Device device drivers/Enable OSPI mode
    5. RT-Thread Components/Device Drivers/Using SPI Bus/Device device drivers/Using defined supported flash chip information table
  • action:

Verification

  • Built and ran the BSP with GCC.
  • Used sf probe ospi10, sf read [addr] [size], sf write [addr] [Value1] [Value2]..., sf erase [addr] [size (4096 = 4KB)], sf status 0 [Value], and sf bench to verify the 1-1-1 and 8-8-8 (OPI STR/DTR) data paths. For example: sf probe ospi10, sf read 0x1000 16, sf write 0x1000 0xAA 0xBB 0xCC 0xDD, sf erase 0x1000 4096, sf status 0 0x04, sf status, and sf bench yes.
  • Verified that the GCC build from the offline dist package succeeds.
  • Regenerated the MDK5 and IAR projects. Flashing with MDK5/IAR was not performed due to environment limitations.

Note: STM32L4 HAL package integration

The STM32L4 HAL package is maintained separately from the main RT-Thread repository and is downloaded for the BSP through pkgs --update. Therefore, changes to its SConscript are not included in this PR.

To build the STM32 OSPI driver, the package's bsp/stm32/libraries/stm32l4_hal_driver-latest/SConscript also needs to include stm32l4xx_hal_ospi.c in its RT_USING_SPI source list:

if GetDepend(['RT_USING_SPI']):
    src += [os.path.join(src_path, 'stm32l4xx_hal_spi.c')]
    src += [os.path.join(src_path, 'stm32l4xx_hal_spi_ex.c')]
    src += [os.path.join(src_path, 'stm32l4xx_hal_qspi.c')]
    src += [os.path.join(src_path, 'stm32l4xx_hal_ospi.c')]

Without this change, the required HAL OSPI implementation is not compiled, so the OSPI driver cannot be linked. The verification described in this PR was performed with this package-side change applied locally.

Once this build rule is incorporated into the STM32L4 HAL package, users will be able to use pkgs --update , enable the required options and build the BSP without modifying the downloaded package manually.
]

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

Purpose:
1. Introduce a native OSPI path into RT-Thread SPI driver layer, enabling OSPI alongside existing SPI/QSPI.
2. Make SFUD work over OSPI (read/write/erase/WREN/WRSR/RDSR) while keeping SPI/QSPI behavior unchanged.
3. Keep existing SPI/QSPI behavior unchanged.

Description:
1. components/drivers/spi/Kconfig: Add OSPI build options.
2. components/drivers/spi/SConscript: Include "dev_ospi_core.c".
3. components/drivers/spi/dev_ospi_core.c: Implement OSPI core transfer helpers.
4. components/drivers/spi/dev_spi_flash_sfud.c/.h: Add OSPI 1-1-1/8-8-8 paths for transferring messages and probing OSPI device.
5. components/drivers/spi/sfud/inc/sfud_cfg.h, sfud_def.h: Add OSPI enable macros and related definitions.
6. components/drivers/spi/sfud/inc/sfud_flash_def.h: Add MX25LM51245G (OctaFlash, 512Mbit) to device table for testing/verification.
7. components/drivers/spi/sfud/src/sfud.c: Integrate the OSPI path into SFUD for read, write, erase, WREN, WRSR, and RDSR operations while retaining the existing SPI/QSPI paths.
8. components/drivers/include/drivers/dev_spi.h: Add OSPI bus/config/message/device structs.

Tested in stm32l4r9-st-eval BSP project: Using "sf probe/read/write/erase/status/bench" to test 1-1-1 and 8-8-8 (OPI STR/DTR) data paths.

Signed-off-by: CliffLL <clifflin@mxic.com.cn>
Purpose:
Provide a generic OSPI low-level driver under STM32 HAL_Drivers to validate and enable the components-layer OSPI path on STM32 BSPs.

Description:
1. bsp/stm32/libraries/HAL_Drivers/drivers/drv_ospi.c/.h: Implement generic OctoSPI init, support transfers in SPI/OSPI mode (1-1-1/8-8-8) and provide helpers for command sequences.
2. bsp/stm32/libraries/HAL_Drivers/drivers/config/l4/ospi_config.h: Add default OCTOSPI mapping for stm32l4xx.
3. bsp/stm32/libraries/HAL_Drivers/drivers/SConscript, drv_config.h: Include the new driver when needed.

Tested in stm32l4r9-st-eval BSP project.

Signed-off-by: CliffLL <clifflin@mxic.com.cn>
Purpose:
1. Validate the components‑layer OSPI path on a real board by adding board‑level OctaFlash support (1‑1‑1 and OPI STR/DTR).
2. Provide a working BSP setup (clocks/pins/MSP/OSPIM and heap/linker fixes) for out-of-the-box SFUD testing.

Description:
1. Provide the OSPI flash driver to attach OSPI device on stm32l4r9‑eval, init bus and provide helpers to enter OPI STR/DTR for upper‑layer tests.
2. Modify the .ioc file and regenerate code to enable OCTOSPI1 and update pin/clock/MSP.
3. Add using OSPI options and include the new driver.
4. Fix heap/linker mismatches observed in GCC run: Align BSP with RT‑Thread heap/layout template to avoid .bss overlap.
5. Document OctaFlash support and usage notes for this board.
6. Regenerate the MDK5 and IAR projects for the BSP.

Notes:
1. Default to BSP minimal config per guideline: Only UART (console) and GPIO enabled; DMA off; FinSH MSH‑only; User main with 1Hz LED blink.
2. Dist packaging: created offline dist for testing; GCC build from dist is OK; MDK5 and IAR projects generated by dist are OK.
3. Due to environment limits, MDK5/IAR flashing was not performed. (Build and run were fully verified on GCC; MDK5/IAR projects were generated.)

Signed-off-by: CliffLL <clifflin@mxic.com.cn>
@github-actions

Copy link
Copy Markdown

👋 感谢您对 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

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 octaflash-driver
    Enter PR branch octaflash-driver in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 octaflash-driver 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the octaflash-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!

@CLAassistant

CLAassistant commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: bsp_stm32

Reviewers: @Liang1795 @hamburger-os @wdfk-prog

Changed Files (Click to expand)
  • bsp/stm32/libraries/HAL_Drivers/drivers/SConscript
  • bsp/stm32/libraries/HAL_Drivers/drivers/config/l4/ospi_config.h
  • bsp/stm32/libraries/HAL_Drivers/drivers/drv_config.h
  • bsp/stm32/libraries/HAL_Drivers/drivers/drv_ospi.c
  • bsp/stm32/libraries/HAL_Drivers/drivers/drv_ospi.h
  • bsp/stm32/stm32l4r9-st-eval/.config
  • bsp/stm32/stm32l4r9-st-eval/README.md
  • bsp/stm32/stm32l4r9-st-eval/board/CubeMX_Config/.mxproject
  • bsp/stm32/stm32l4r9-st-eval/board/CubeMX_Config/CubeMX_Config.ioc
  • bsp/stm32/stm32l4r9-st-eval/board/CubeMX_Config/Inc/stm32l4xx_hal_conf.h
  • bsp/stm32/stm32l4r9-st-eval/board/CubeMX_Config/Src/stm32l4xx_hal_msp.c
  • bsp/stm32/stm32l4r9-st-eval/board/CubeMX_Config/Src/stm32l4xx_it.c
  • bsp/stm32/stm32l4r9-st-eval/board/Kconfig
  • bsp/stm32/stm32l4r9-st-eval/board/SConscript
  • bsp/stm32/stm32l4r9-st-eval/board/board.c
  • bsp/stm32/stm32l4r9-st-eval/board/board.h
  • bsp/stm32/stm32l4r9-st-eval/board/linker_scripts/link.icf
  • bsp/stm32/stm32l4r9-st-eval/board/linker_scripts/link.sct
  • bsp/stm32/stm32l4r9-st-eval/board/ports/drv_ospi_flash.c
  • bsp/stm32/stm32l4r9-st-eval/project.ewp
  • bsp/stm32/stm32l4r9-st-eval/project.uvprojx
  • bsp/stm32/stm32l4r9-st-eval/rtconfig.h

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/drivers/include/drivers/dev_spi.h
  • components/drivers/spi/Kconfig
  • components/drivers/spi/SConscript
  • components/drivers/spi/dev_ospi_core.c
  • components/drivers/spi/dev_spi_flash_sfud.c
  • components/drivers/spi/dev_spi_flash_sfud.h
  • components/drivers/spi/sfud/inc/sfud_cfg.h
  • components/drivers/spi/sfud/inc/sfud_def.h

🏷️ Tag: components_driver_spi

Reviewers: @Liang1795 @wdfk-prog

Changed Files (Click to expand)
  • components/drivers/spi/Kconfig
  • components/drivers/spi/SConscript
  • components/drivers/spi/dev_ospi_core.c
  • components/drivers/spi/dev_spi_flash_sfud.c
  • components/drivers/spi/dev_spi_flash_sfud.h
  • components/drivers/spi/sfud/inc/sfud_cfg.h
  • components/drivers/spi/sfud/inc/sfud_def.h

📊 Current Review Status (Last Updated: 2026-10-21 15:22 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.

@wdfk-prog

Copy link
Copy Markdown
Contributor
  • OctaFlash SPI有啥特殊的吗?能够复用QSPI FLASH 或者FLASH SPI使用吗?可以对FLASH结构体或者QFlash结构体增加一个标识符来识别能力,进而选择对应驱动更好;然后通过Kconfig用宏进行裁剪出不需要的功能
  • 都差不多的驱动,没有必要在新增一个驱动这么多文件,能够复用的话,后续维护更好做.
  • 我觉得现在的QFLASH QSPI也一样可以这种优化掉.一个公共的SPI FLASH框架,再去对接不同的SPI QSPI OSPI即可

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants