Zephyr API-based sketch to blink external LED3 on DPin-3 fails to compile


Figure-1:

Referring to Fig-1 and the title, the following Zephyr API–based sketch fails to compile. The AI generated the required .overlay and .conf files for the Devicetree structure, which I have placed in the App Lab sketch folder.

I would appreciate help to resolve the issues.

Error Message:

/home/arduino/ArduinoApps/zephyrled3dpin3/sketch/sketch.ino:10:2: error: #error "Devicetree alias 'dpin3' is not defined. Make sure app.overlay is included."
10 | #error "Devicetree alias 'dpin3' is not defined. Make sure app.overlay is included."
|  ^~~~~
exit status 1

Sketch:

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

#define SLEEP_TIME_MS 1000

/* Define node alias matching app.overlay */
#define LED3_NODE DT_ALIAS(dpin3)

#if !DT_NODE_HAS_STATUS(LED3_NODE, okay)
#error "Devicetree alias 'dpin3' is not defined. Make sure app.overlay is included."
#endif

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED3_NODE, gpios);

void setup() 
{
  Serial.begin(115200);

  /* Verify hardware device readiness */
  if (!gpio_is_ready_dt(&led)) 
  {
      Serial.println("LED3 hardware device not ready!");
      return;
  }

  /* Configure pin as output */
  if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) {
      Serial.println("Failed to configure GPIO pin!");
  }
}

void loop() {
  gpio_pin_toggle_dt(&led);
  k_msleep(SLEEP_TIME_MS);
}

app.overlay

/ {
    aliases {
        dpin3 = &my_led3;
    };

    leds {
        compatible = "gpio-leds";
        my_led3: dpin_3_led {
            /* Pin 3 on the Arduino header (arduino_header 3 0) */
            gpios = <&arduino_header 3 GPIO_ACTIVE_HIGH>;
            label = "LED3 on DPin-3";
        };
    };
};

prj.conf

# Enable GPIO Driver Support
CONFIG_GPIO=y

# Enable Devicetree Overlay Parsing Support
CONFIG_DEVICETREE_BOARD_MERGE=y

As I mentioned before you can not add, delete, or change anything in the device tree, within an Arduino Sketch which I assume you are trying to do here as you have setup and loop.

If you really want to play with RAW zephyr, then you should look at installing
raw zephyr:

Getting Started Guide — Zephyr Project Documentation

I have not done much on zephyr directly with Uno Q, but details are up at:
Arduino UNO Q — Zephyr Project Documentation

With Zephyr builds you are free to change everything you want, the down side is it
does not come with any of the Arduino things like Serial.print... I have hacked up
versions of things like that in my own tests directory.

For example they have sample ones for doing ADC, like up at:
zephyr/samples/drivers/adc/adc_dt at main · zephyrproject-rtos/zephyr

In many of these samples, they have a boards directory which can have .overly and .config files specific to different boards. In this case they don't have a configuration for the Uno Q, but you can always create them.

Good luck