jfarjona
jfarjona

Reputation: 145

My GPIOs in the overlay file are not defined in devicetree_generated.h, zephyr fails

I am trying to use Zephyr (v.3.2.99) for a small application on the nRF52840 Dev Kit. I set up an overlay file nrf52840dk_nrf52840.overlay that is being read and processed by cmake. I get the devicetree_generated.h but it lacks the definition of the nodes.

Here is my overlay:

/ {
    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);

...

The error:

zephyr/include/generated/devicetree_generated.h:701:32: error: 'DT_N_S_pin_pwr_0_P_gpios_IDX_0_VAL_pin' undeclared here (not in a function); did you mean 'DT_N_S_leds_S_led_0_P_gpios_IDX_0_VAL_pin'?
701 | #define DT_N_ALIAS_pwr0 DT_N_S_pin_pwr_0 | ^~~~~~~~~~~~~~~~ F:/ncs/v2.2.0/zephyr/include/zephyr/devicetree.h:3901:9: note: in definition of macro '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 expansion of macro 'DT_PHA_BY_IDX' 164 |
DT_PHA_BY_IDX(node_id, gpio_pha, idx, pin) | ^~~~~~~~~~~~~ F:/ncs/v2.2.0/zephyr/include/zephyr/drivers/gpio.h:341:24: note: in expansion of macro 'DT_GPIO_PIN_BY_IDX' 341 | .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx),
| ^~~~~~~~~~~~~~~~~~ F:/ncs/v2.2.0/zephyr/include/zephyr/drivers/gpio.h:376:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX' 376 |
GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0) | ^~~~~~~~~~~~~~~~~~~~~~~ ../src/tvunit.c:25:40: note: in expansion of macro 'GPIO_DT_SPEC_GET' 25 | static const struct gpio_dt_spec pwr = GPIO_DT_SPEC_GET(PWR_IO, gpios);

If I look into the file devicetree_generated.h, the token DT_N_S_pin_pwr_0 is never defined (only referred to in the comments).

What am I doing wrong?

Upvotes: 1

Views: 1474

Answers (1)

Unn
Unn

Reputation: 5098

Zephyr's build system is not properly processing the pin_pwr_0 and like nodes as they don't have bindings. Generally, nodes in the devicetree also need bindings to be processed correctly. Since the nodes you are using are just pins/buttons; you should be able to use the generic gpio-keys compatible by adding this to each node: compatible = "gpio-keys"; More on Zephyr's devicetree binding rules can be found here: https://docs.zephyrproject.org/3.2.0/build/dts/bindings.html

Upvotes: 2

Related Questions