Search code examples
esp32gpiozephyr-rtos

Strange build errors with Zephyr and GPIO


I've hooked a led and resistor to GPIO33 and trying to get it to blink. I'm new to Zephyr and trying to learn GPIO and overlay, so I made my own overlay:

/ {
    leds {
        compatible = "gpio-leds";
        led0: led_0 {
            gpios = <&gpio0 33 GPIO_ACTIVE_HIGH>;
        };
    };
};

And my definitions:

#define LED0_NODE DT_NODELABEL(led0)
#define LED_GPIO DT_GPIO_LABEL(LED0_NODE, gpios)
#define LED_PIN DT_GPIO_PIN(LED0_NODE, gpios)
#define LED_FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)

Dont think rest of my code is important, since I get this error:

devicetree_generated.h:1506:46: error: 'DT_N_S_soc_S_gpio_3f404000_P_label' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_gpio_3f404000_P_reg'?
 1506 | #define DT_N_S_leds_S_led_0_P_gpios_IDX_0_PH DT_N_S_soc_S_gpio_3f404000

I have no idea what this means. Im building to the board esp32s2_saola. It confuses me it states ..._P_label is indeclared and suggests ..._P_reg.

How do I go about fixing this?


Solution

  • The issue is that DT_GPIO_LABEL will attempt to get the label property of the GPIO node rather than get its device name from either it's label property or devicetree label. See the answer here: https://stackoverflow.com/a/76143305/2774842

    It can be very difficult to handle errors like this as Zephyr's build system will convert devicetrees into complex series of macros and it's errors in those macros or finding the right macro that causes the compilation to fail with somewhat cryptic names and errors while the true error is in the code accessing the devicetree or the devicetree itself. You can try to piece together what they say by looking at the macro it's missing and figure out where it might be in the devicetree. Here, you can see _S_soc_S_gpio_3f404000 in the name so you know it's looking at node /soc/gpip@3f404000 and it's looking for a property in this node, ie _P_label. If you find that node in the devicetree (which is here: https://github.com/zephyrproject-rtos/zephyr/blob/c22c4fd49f6671079cd9df19d4c22678294be87d/dts/xtensa/espressif/esp32s2.dtsi#L132), you'll find it has no label property and thus the error.