zephyr 设备树节点中是否可以包含任意数据?
Is it possible to have arbitrary data in a zephyr device tree node?
我想使用设备树来存储一些系统级常量。
是否可以从设备树中存储和检索任意值?
尝试加载这些值无法编译,因为 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";
};
};
这里缺少的部分是设备树绑定,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、设置”条目中预期的格式:
compatible: "my-company,settings"
description: "Project specific settings and configuration"
properties:
custom-num:
type: int
required: true
another-value:
type: string
required: false
我想使用设备树来存储一些系统级常量。
是否可以从设备树中存储和检索任意值?
尝试加载这些值无法编译,因为 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";
};
};
这里缺少的部分是设备树绑定,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、设置”条目中预期的格式:
compatible: "my-company,settings"
description: "Project specific settings and configuration"
properties:
custom-num:
type: int
required: true
another-value:
type: string
required: false