Issues with Overlay File in Zephyr Project Not Being Recognized

I’m currently working on a Zephyr blinky project in PlatformIO, and I’m trying to create an overlay file for nucleo_l432k. I’ve created the overlay file ‘nucleo_l432kc.overlay’ in the zephyr directory of my project and added the DTC_OVERLAY_FILE variable in the CMakeLists.txt file to point to this overlay file.

However, it seems like the system is not picking up the overlay file.

Here is the relevant part of my CMakeLists.txt file:

# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)

set(DTC_OVERLAY_FILE "nucleo_l432kc.overlay")

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(blinky)

target_sources(app PRIVATE ../src/main.c)

And here is the structure of my overlay file:

/ {
    aliases {
        myled = &led4;
    };

    leds {
        compatible = "gpio-leds";

        led4: led4 {
            gpios = <&gpiob 4 GPIO_ACTIVE_HIGH>;
            label = "my LED";
        };
    };
};

My code is this:

#include <stdio.h>

#include <zephyr/kernel.h>

#include <zephyr/drivers/gpio.h>

#include <zephyr/sys/printk.h>

/* The devicetree node identifier for the "led0" alias. */

#define LED4_NODE DT_ALIAS(led4)

#define SLEEP_TIME_MS 1000

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

Despite these settings, the overlay file doesn’t seem to be applied correctly. Could anyone provide some guidance on what might be going wrong?

Any help would be greatly appreciated!

I am getting this error:

In file included from C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/toolchain/gcc.h:98,
                 from C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/toolchain.h:50,
                 from C:/Users/asus/.platformio/packages/framework-zephyr/lib/libc/minimal/include/stdio.h:12,
                 from src\main.c:12:
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/device.h:85:41:Compiling .pio\build\nucleo_l432kc\lib__libc__minimal\zephyr\lib\libc\minimal\source\math\sqrtf.c.o     
 error: '__device_dts_ord_DT_N_ALIAS_led4_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function)
   85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                         ←[01;31m←[K^~~~~~~~~←[m←[K
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/device.h:212:37: note: in expansion of macro 'DEVICE_NAME_GET'
  212 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))     
      |                                     ←[01;36m←[K^~~~~~~~~~~~~~~←[m←[K
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/device.h:229:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
  229 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
      |                                  ←[01;36m←[K^~~~~~~~~~~~~~~~~~←[m←[K
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/drivers/gpio.h:331:25: note: in expansion of macro 'DEVICE_DT_GET'
  331 |                 .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\     
      |                         ←[01;36m←[K^~~~~~~~~~~~~←[m←[K
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/drivers/gpio.h:367:9:Archiving .pio\build\nucleo_l432kc\zephyr\drivers\reset\libdrivers__reset.a
 note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
  367 |         GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
      |         ←[01;36m←[K^~~~~~~~~~~~~~~~~~~~~~~←[m←[K
src\main.c:21:40: note: in expansion of macro 'GPIO_DT_SPEC_GET'
   21 | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED4_NODE, gpios);
      |                                        ←[01;36m←[K^~~~~~~~~~~~~~~~←[m←[K
Compiling .pio\build\nucleo_l432kc\arch__arm__core__cortex_m\zephyr\arch\arch\arm\core\cortex_m\reset.S.o
Compiling .pio\build\nucleo_l432kc\kernel\zephyr\kernel\mailbox.c.o
In file included from C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/arch/arm/arch.h:20,
                 from C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/arch/cpu.h:19,
                 from C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/kernel_includes.h:37,
                 from C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/kernel.h:17,
                 from src\main.c:13:
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/devicetree.h:237:32: error: 'DT_N_ALIAS_led4_P_gpios_IDX_0_VAL_pin' undeclared here (not in a function); did you mean 'DT_N_S_leds_S_led4_P_gpios_IDX_0_VAL_pin'?
  237 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
      |                                ←[01;31m←[K^~~~~~~~~~~←[m←[K
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/devicetree.h:4272:9: note:
 in definition of macro 'DT_CAT7'
 4272 |         a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7
      |         ^~
C:\Users\asus\.platformio\packages\framework-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)
      |         ←[01;36m←[K^~~~~~~~~~~~~←[m←[K
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/drivers/gpio.h:332:24: note: in expansion of macro 'DT_GPIO_PIN_BY_IDX'
  332 |                 .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx),                 \     
      |                        ←[01;36m←[K^~~~~~~~~~~~~~~~~~←[m←[K
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/drivers/gpio.h:367:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
  367 |         GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
      |         ←[01;36m←[K^~~~~~~~~~~~~~~~~~~~~~~←[m←[K
src\main.c:21:40: note: in expansion of macro 'GPIO_DT_SPEC_GET'
   21 | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED4_NODE, gpios);
      |                                        ←[01;36m←[K^~~~~~~~~~~~~~~~←[m←[K
C:\Users\asus\.platformio\packages\framework-zephyr\include/zephyr/devicetree.h:237:25: note:
 in expansion of macro 'DT_CAT'
  237 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
      |                         ←[01;36m←[K^~~~~~←[m←[K
src\main.c:18:19: note: in expansion of macro 'DT_ALIAS'
   18 | #define LED4_NODE DT_ALIAS(led4)
      |                   ←[01;36m←[K^~~~~~~~←[m←[K
src\main.c:21:57: note: in expansion of macro 'LED4_NODE'
   21 | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED4_NODE, gpios);
      |                                                         ←[01;36m←[K^~~~~~~~~←[m←[K   
*** [.pio\build\nucleo_l432kc\src\main.o] Error 1
================================ [FAILED] Took 31.27 seconds ================================

So, after changing this line, my problem is resolved.

#define LED4_NODE DT_ALIAS( myled)