Skip to content

feat(dm): support OFW on Cortex-M targets. - #11669

Open
Rbb666 wants to merge 4 commits into
RT-Thread:masterfrom
Rbb666:dm-mcu
Open

feat(dm): support OFW on Cortex-M targets.#11669
Rbb666 wants to merge 4 commits into
RT-Thread:masterfrom
Rbb666:dm-mcu

Conversation

@Rbb666

@Rbb666 Rbb666 commented Jul 31, 2026

Copy link
Copy Markdown
Member

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

[

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

适配dm到mcu平台,mcu可以通过内建设备树进行子设备初始化和配置,
dm和传统设备驱动框架可以二选一进行使用
目前仅添加pin设备驱动

目前已验证的平台有:

  • armv7m:stm32f407+stm32h750
  • armv8m:renesas-ra8p1-m85

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

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

  • BSP:
  • .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
  • 已经使用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自查

Rbb666 added 3 commits July 31, 2026 15:07
Add the ARM NVIC PIC driver, no-MMU I/O mapping, built-in FDT support, and Cortex-M CPU hooks required by the native RT-Thread device model.
Add device-tree GPIO/EXTI controllers, built-in DTB support for GCC and ArmClang, and BSP integration for STM32F407 RT-Spark and STM32H750 ART-Pi. Document how BSP users enable the DM drivers.
Add M85 device-tree GPIO and external-interrupt controllers, IRQ20 FSP integration, built-in DTB support, and BSP usage documentation.
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: bsp_renesas

Reviewers: @kurisaW

Changed Files (Click to expand)
  • bsp/renesas/libraries/HAL_Drivers/drivers/SConscript
  • bsp/renesas/libraries/HAL_Drivers/drivers/dm/SConscript
  • bsp/renesas/libraries/HAL_Drivers/drivers/dm/builtin_fdt_gcc.S
  • bsp/renesas/libraries/HAL_Drivers/drivers/dm/drv_external_irq.c
  • bsp/renesas/libraries/HAL_Drivers/drivers/dm/drv_external_irq.h
  • bsp/renesas/libraries/HAL_Drivers/drivers/dm/drv_gpio.c
  • bsp/renesas/libraries/HAL_Drivers/drv_common.c
  • bsp/renesas/ra8p1-titan-board/README.md
  • bsp/renesas/ra8p1-titan-board/README_zh.md
  • bsp/renesas/ra8p1-titan-board/m85/.settings/standalone.prefs
  • bsp/renesas/ra8p1-titan-board/m85/Kconfig
  • bsp/renesas/ra8p1-titan-board/m85/SConstruct
  • bsp/renesas/ra8p1-titan-board/m85/board/dts/ra8p1-titan-m85.dts
  • bsp/renesas/ra8p1-titan-board/m85/configuration.xml
  • bsp/renesas/ra8p1-titan-board/m85/ra/fsp/inc/api/r_external_irq_api.h
  • bsp/renesas/ra8p1-titan-board/m85/ra/fsp/inc/instances/r_icu.h
  • bsp/renesas/ra8p1-titan-board/m85/ra/fsp/src/r_icu/r_icu.c
  • bsp/renesas/ra8p1-titan-board/m85/ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h
  • bsp/renesas/ra8p1-titan-board/m85/ra_cfg/fsp_cfg/r_icu_cfg.h
  • bsp/renesas/ra8p1-titan-board/m85/ra_gen/common_data.c
  • bsp/renesas/ra8p1-titan-board/m85/ra_gen/common_data.h
  • bsp/renesas/ra8p1-titan-board/m85/ra_gen/pin_data.c
  • bsp/renesas/ra8p1-titan-board/m85/ra_gen/vector_data.c
  • bsp/renesas/ra8p1-titan-board/m85/ra_gen/vector_data.h
  • bsp/renesas/ra8p1-titan-board/m85/rtconfig.py
  • bsp/renesas/ra8p1-titan-board/m85/script/fsp.ld
  • bsp/renesas/ra8p1-titan-board/m85/src/hal_entry.c

🏷️ 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/dm/SConscript
  • bsp/stm32/libraries/HAL_Drivers/drivers/dm/builtin_fdt_ac6.c

📊 Current Review Status (Last Updated: 2026-07-31 16:28 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.

@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

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

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

@Rbb666
Rbb666 removed the request for review from kurisaW July 31, 2026 08:29

void rt_hw_cpu_reset(void)
rt_weak void rt_hw_cpu_reset(void)
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这块src定义过一个弱符号了,如果有平台实现建议换成绑定rt_dm_machine_shutdown、rt_dm_machine_reset,或者改成Kconfig配置

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

libcpu\arm\cortex-m4\cpuport.c mcu在这里实现了一份 rt_hw_cpu_reset,意思是在这块使用dm的宏进行区分吗?

@GuEe-GUI GuEe-GUI Jul 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

那可以在libcpu\arm\cortex-m4\cpuport.c加个宏判断,然后DM分支另外绑定rt_dm_machine_reset的操作为之前libcpu\arm\cortex-m4\cpuport.c的rt_hw_cpu_reset

@wdfk-prog

Copy link
Copy Markdown
Contributor
  • 这个实用性一般般吧?不像linux那样可以修改设备树,直接嵌入了考虑的应该是设备树换到不同平台的适配性和移植性吧,没有考虑Zephyr那样的做法嘛?

@GuEe-GUI

Copy link
Copy Markdown
Contributor

这块的目的更多的是共同维护一个驱动代码,同时增加一定得灵活性,减少大量得HAL硬件描述

rt_err_t rt_pic_init(void);

#ifdef RT_PIC_ARM_NVIC
void rt_hw_nvic_dispatch(void);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这块可以不用添加,在CPU中断入口直接调用rt_pic_do_traps即可,可以参考/home/gui/Desktop/rt-thread/rt-thread-qemu/components/drivers/pic/pic-gicv2.c:

static rt_bool_t gicv2_handler(void *data)
{
}

static rt_err_t gicv2_ofw_init(struct rt_ofw_node *np, const struct rt_ofw_node_id *id)
{
    rt_pic_add_traps(gicv2_handler, gic);
}

rt_uint8_t priority_bits;
};

rt_inline void nvic_sync(void)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NVIC 作为公共 IP 代码得话尽量使用 cpuport 里面得内存屏障接口,比如 rt_hw_dsb();rt_hw_isb();

static volatile rt_uint32_t *nvic_reg32(struct arm_nvic *nvic,
rt_ubase_t offset, int hwirq)
{
return (volatile rt_uint32_t *)(nvic->base + offset) + NVIC_REG_INDEX(hwirq);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(volatile rt_uint32_t *)和(volatile rt_uint8_t *)等寄存器操作可以改用 HWREG32,HWREG8 代码会美观一些

{
rt_uint32_t exception;

__asm volatile ("mrs %0, ipsr" : "=r" (exception));

@GuEe-GUI GuEe-GUI Jul 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

特殊得寄存器访问可能就要在平台得cpuport或者cpu.h抽象一个宏接口来调用,比如gicv3的read_gicreg,同时如果按照前面说的rt_hw_nvic_dispatch改进建议,就不需要定义_nvic全局变量了,可以直接在nvic_handler的参数data获取到数据

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