feat(dm): support OFW on Cortex-M targets. - #11669
Conversation
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.
📌 Code Review Assignment🏷️ Tag: bsp_renesasReviewers: @kurisaW Changed Files (Click to expand)
🏷️ Tag: bsp_stm32Reviewers: @Liang1795 @hamburger-os @wdfk-prog Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-07-31 16:28 CST)
📝 Review Instructions
|
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
|
||
| void rt_hw_cpu_reset(void) | ||
| rt_weak void rt_hw_cpu_reset(void) | ||
| { |
There was a problem hiding this comment.
这块src定义过一个弱符号了,如果有平台实现建议换成绑定rt_dm_machine_shutdown、rt_dm_machine_reset,或者改成Kconfig配置
There was a problem hiding this comment.
libcpu\arm\cortex-m4\cpuport.c mcu在这里实现了一份 rt_hw_cpu_reset,意思是在这块使用dm的宏进行区分吗?
There was a problem hiding this comment.
那可以在libcpu\arm\cortex-m4\cpuport.c加个宏判断,然后DM分支另外绑定rt_dm_machine_reset的操作为之前libcpu\arm\cortex-m4\cpuport.c的rt_hw_cpu_reset
|
|
这块的目的更多的是共同维护一个驱动代码,同时增加一定得灵活性,减少大量得HAL硬件描述 |
| rt_err_t rt_pic_init(void); | ||
|
|
||
| #ifdef RT_PIC_ARM_NVIC | ||
| void rt_hw_nvic_dispatch(void); |
There was a problem hiding this comment.
这块可以不用添加,在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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
(volatile rt_uint32_t *)和(volatile rt_uint8_t *)等寄存器操作可以改用 HWREG32,HWREG8 代码会美观一些
| { | ||
| rt_uint32_t exception; | ||
|
|
||
| __asm volatile ("mrs %0, ipsr" : "=r" (exception)); |
There was a problem hiding this comment.
特殊得寄存器访问可能就要在平台得cpuport或者cpu.h抽象一个宏接口来调用,比如gicv3的read_gicreg,同时如果按照前面说的rt_hw_nvic_dispatch改进建议,就不需要定义_nvic全局变量了,可以直接在nvic_handler的参数data获取到数据
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
适配dm到mcu平台,mcu可以通过内建设备树进行子设备初始化和配置,
dm和传统设备驱动框架可以二选一进行使用
目前仅添加pin设备驱动
目前已验证的平台有:
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 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