You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Zephyr DT_PHA_BY_NAME API报错:指定名称的宏未在devicetree_generated.h中定义

问题:设备树phandle-array与string-array关联生成命名宏失败

设备树节点代码

#address-cells = <1>;
#size-cells = <0>;

padctrl: pad-controller@0xA0111000 {
    compatible = "rapidsi,pads";
    reg = <0xA0111000>;
    #pad-cells = <3>;
    pad-controller;
    status = "okay";
};

fpga_cfg: cfg-ctrl@0xA0710000 {
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";

    ofe: ofe {
        compatible = "rapidsi,ofe";
        pads = <&padctrl 0 0x2 3>, <&padctrl 1 0x2 3>;
        pad-line-names = "CONFIG_DONE", "CONFIG_ERROR";
        status = "okay";
    };
};

现有YAML绑定代码

compatible: "rapidsi,pads"
include: [pad-controller.yaml, base.yaml]

properties:
    "#pad-cells":
        const: 3
    pad-cells:
        - pad
        - function
        - config_mode

compatible: "rapidsi,ofe"
include: [base.yaml]

properties:
    pads:
        type: phandle-array
        required: true
    pad-line-names:
        type: string-array

问题现象

调用Devicetree API DT_PHA_BY_NAME(DT_NODELABEL(ofe), pads, config_done, config_mode)时出现编译错误,提示对应NAME宏未声明,仅能通过索引(IDX)访问phandle-array的宏。

解决方法

问题出在YAML绑定未显式关联phandle-array与对应string-array。需要修改rapidsi,ofe的绑定,给pads属性添加names字段,指定对应的名称数组:

compatible: "rapidsi,ofe"
include: [base.yaml]

properties:
    pads:
        type: phandle-array
        required: true
        names: pad-line-names  # 新增:关联到pad-line-names属性
    pad-line-names:
        type: string-array

关键说明

Devicetree工具不会自动关联phandle-array和string-array,必须通过names字段明确指定哪个string-array是当前phandle-array的名称映射。这样工具才会将pad-line-names中的每个名称与pads中的对应条目绑定,生成支持DT_PHA_BY_NAME访问的命名宏。

同时需确保pad-line-names的元素数量与pads的phandle条目数量完全一致,当前设备树中两者都是2个,符合要求。

内容的提问来源于stack exchange,提问作者Sheikh Muhammad Junaid Aslam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 21:26:23