我试图将Zephyr (v.3.2.99)用于nRF52840开发工具包上的小型应用程序。我设置了一个覆盖文件nrf52840dk_nrf52840。cmake正在读取和处理的覆盖层。我得到devicetree_generated.h,但它缺少节点的定义。
这是我的叠加:
/ {
aliases {
pwr0 = &pinpwr0;
eu0 = &pineu0;
psw0 = &pinsw0;
};
pinpwr0: pin_pwr_0 {
gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>;
label = "power";
};
pineu0: pin_eu_0 {
gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>;
label = "eu";
};
pinsw0: pin_sw_0 {
gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>;
label = "switch";
};
chosen {
nordic,nus-uart = &uart0;
};
};
My c file:
…
#define PWR_IO DT_ALIAS(pwr0)
#if DT_NODE_HAS_STATUS(PWR_IO, okay)
#define PWR_IO_PIN DT_GPIO_PIN(PWR_IO, gpios)
#else
#error "Cannot find the board"
#define PWR_IO_PIN 0
#endif
static const struct gpio_dt_spec pwr = GPIO_DT_SPEC_GET(PWR_IO, gpios);
…
错误:
和风/include/生成/devicetree_generated.h: 701:32:错误:'DT_N_S_pin_pwr_0_P_gpios_IDX_0_VAL_pin'未声明(不在函数);你是说' dt_n_s_led_s_led_0_p_gpios_idx_0_val_pin '吗?
701 | #define DT_N_ALIAS_pwr0 dt_n_s_pin_pwr0^~~~~~~~~~~~~~~~ F:/ncs/v2.2.0/zephyr/include/zephyr/devicetree.h:3901:9: note: in定义宏'DT_CAT7' 3901 | a1 ## a2 ## a3 ## a4 ##A5 ## a6 ## a7^~ F:/ncs/v2.2.0/zephyr/include/zephyr/devicetree/gpio.h:164:9: note: in扩展宏'DT_PHA_BY_IDX' 164 |
DT_PHA_BY_IDX(node_id, gpio_pha, idx, pin)| ^~~~~~~~~~~~~ F:/nc/v2.2.0/和风/include/和风/司机/gpio.h: 341:24:注意:在扩展宏'DT_GPIO_PIN_BY_IDX' 341 | .pin =DT_GPIO_PIN_BY_IDX (node_id道具,idx),
| ^~~~~~~~~~~~~~~~~~ F:/nc/v2.2.0/和风/include/和风/司机/gpio.h: 376:9:注意:在扩展宏'GPIO_DT_SPEC_GET_BY_IDX' 376 |
GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)/^~~~~~~~~~~~~~~~~~~~~~~ ../src/tunit .c:25:40:注:在宏'GPIO_DT_SPEC_GET' 25 |静态构造结构的扩展gpio_dt_spec pwr = GPIO_DT_SPEC_GET(PWR_IO, gpios);
如果我查看文件devicetree_generated.h,令牌DT_N_S_pin_pwr_0从未定义(仅在注释中引用)。
我做错了什么?
Zephyr的构建系统不能正确处理pin_pwr_0
和like节点,因为它们没有绑定。通常,devicetree中的节点也需要正确处理绑定。因为你使用的节点只是针/按钮;您应该能够通过将其添加到每个节点来使用通用的gpio-keys
兼容:compatible = "gpio-keys";
更多关于Zephyr的设备树绑定规则的信息可以在这里找到:https://docs.zephyrproject.org/3.2.0/build/dts/bindings.html