0

我想使用设备树来存储一些系统级常量。

是否可以从设备树中存储和检索任意值?

尝试加载这些值无法编译,因为 build/zephyr/include/generated/devicetree_unfixed.h 缺少“custom-num”或“another-value”的值。

...
    int custom_num = DT_PROP(DT_PATH(settings), custom_num);
    printf("custom_num %d\n", custom_num);
...
...
zephyr/include/devicetree.h:81:17: error: 'DT_N_S_settings_P_custom_num' undeclared (first use in this function)
   81 | #define DT_ROOT DT_N
      |                 ^~~~
...

设备树覆盖文件:

/* SPDX-License-Identifier: Apache-2.0 */
/ {
        aliases {
                someuart-uart = &uart7;
        };

        settings {
                custom-num = < 29992 >;
                another-value = "some string";
        };
};
4

1 回答 1

0

这里缺少的部分是设备树绑定,https: //docs.zephyrproject.org/latest/guides/dts/bindings.html#,dt条目必须匹配才能正确处理。

解决这个问题的提示来自 zephyrproject 问题跟踪器:https ://github.com/zephyrproject-rtos/zephyr/issues/42404

首先,我们必须稍微调整覆盖以包含一个“兼容”条目,例如:

/* SPDX-License-Identifier: Apache-2.0 */
/ {
        aliases {
                someuart-uart = &uart7;
        };

        settings {
                compatible = "my-company,settings";  /* <--------- */
                custom-num = < 29992 >;
                another-value = "some string";
        };
};

然后在项目的dts/bindings/文件夹中创建一个文件,根据 Zephyr 的建议,在兼容字符串之后命名:

dts/bindings/my-company,settings.yaml

包含“ my-company,settings ”条目中预期的格式:

compatible: "my-company,settings"

description: "Project specific settings and configuration"

properties:
  custom-num:
    type: int
    required: true
  another-value:
    type: string
    required: false
于 2022-02-03T14:13:09.583 回答