Extending zephyr-blinky with another led doesn't work

I’m pretty fresh to zephyr and device tress. I’ve encountered it a bit at work but haven’t quite become friends with it.

I’ve taken a simple blinky example which works fine. The LED blinks and now I’m just trying to add another LED for me to control. I thought this would be a simple copy paste with minor modifications but I’m missing something fundamental here.

I’m trying to keep this minimal
This is my dts file

/*
 * Copyright (c) 2017 Arthur Sfez
 *
 * Based on stm32L476g_disco:
 *
 * Copyright (c) 2017 Linaro Limited
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/dts-v1/;
#include <st/l4/stm32l431Xc.dtsi>
#include <st/l4/stm32l431r(b-c)yx-pinctrl.dtsi>

/ {
	model = "Custom STM32L431RC board";
	compatible = "st,devboard";

	chosen {
		zephyr,console = &usart2;
		zephyr,shell-uart = &usart2;
		zephyr,sram = &sram0;
		zephyr,flash = &flash0;
	};

	leds {
		compatible = "gpio-leds";
		green_0: led_0 {
			gpios = <&gpioc 2 GPIO_ACTIVE_HIGH>;
		};
		green_1: led_1 {
			gpios = <&gpioc 3 GPIO_ACTIVE_HIGH>;
		};
	};

        aliases {
                led0 = &green_0;
                led1 = &green_1;
        };

};

&clk_lsi {
	status = "okay";
};

&clk_hsi {
	status = "okay";
};

&pll {
	div-m = <2>;
	mul-n = <20>;
	div-p = <7>;
	div-q = <8>;
	div-r = <2>;
	clocks = <&clk_hsi>;
	status = "okay";
};

&rcc {
	clocks = <&pll>;
	clock-frequency = <DT_FREQ_M(80)>;
	ahb-prescaler = <1>;
	apb1-prescaler = <1>;
	apb2-prescaler = <1>;
};

&usart2 {
	pinctrl-0 = <&usart3_tx_pc10 &usart3_rx_pc11>;
	pinctrl-names = "default";
	current-speed = <921600>;
	status = "okay";
};

&rtc {
	clocks = <&rcc STM32_CLOCK_BUS_APB1 0x10000000>,
		 <&rcc STM32_SRC_LSI RTC_SEL(2)>;
	status = "okay";

	backup_regs {
		status = "okay";
	};
};

And here is my main where I try to use it


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

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 300

/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
#define LED1_NODE DT_ALIAS(led1)

static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios);

int main() {

    if (!gpio_is_ready_dt(&led0))
    {
      return 1;
    }

    int ret = gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
    if (ret < 0)
    {
      return 1;
    }

    while (1)
    {
      ret = gpio_pin_toggle_dt(&led0);
      if (ret < 0)
      {
        return 1;
      }
      k_msleep(SLEEP_TIME_MS);
    }

}

I’m not using led1 yet because it’s already failing at the GPIO_DT_SPEC_GET macro with the following error.

Compiling .pio/build/stm32l431rc/src/main.o
In file included from /home/simon/.platformio/packages/framework-zephyr/include/zephyr/toolchain/gcc.h:92,
from /home/simon/.platformio/packages/framework-zephyr/include/zephyr/toolchain.h:50,
from /home/simon/.platformio/packages/framework-zephyr/include/zephyr/kernel_includes.h:19,
from /home/simon/.platformio/packages/framework-zephyr/include/zephyr/kernel.h:17,
from src/main.cpp:2:
/home/simon/.platformio/packages/framework-zephyr/include/zephyr/device.h:85:41: error: ‘__device_dts_ord_DT_N_ALIAS_led1_P_gpios_IDX_0_PH_ORD’ was not declared in this scope
85 | #define DEVICE_NAME_GET(dev_id) _CONCAT(_device, dev_id)
| ^~~~~~~~~
/home/simon/.platformio/packages/framework-zephyr/include/zephyr/toolchain/common.h:132:26: note: in definition of macro ‘_DO_CONCAT’
132 | #define _DO_CONCAT(x, y) x ## y
| ^
/home/simon/.platformio/packages/framework-zephyr/include/zephyr/device.h:85:33: note: in expansion of macro ‘_CONCAT’
85 | #define DEVICE_NAME_GET(dev_id) CONCAT(device, dev_id)
| ^~~~~~~
/home/simon/.platformio/packages/framework-zephyr/include/zephyr/device.h:211:37: note: in expansion of macro ‘DEVICE_NAME_GET’
211 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
| ^~~~~~~~~~~~~~~
/home/simon/.platformio/packages/framework-zephyr/include/zephyr/device.h:228:34: note: in expansion of macro ‘DEVICE_DT_NAME_GET’
228 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
/home/simon/.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)),
| ^~~~~~~~~~~~~
/home/simon/.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)
| ^~~~~~~~~~~~~~~~~~~~~~~
src/main.cpp:13:41: note: in expansion of macro ‘GPIO_DT_SPEC_GET’
13 | static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
| ^~~~~~~~~~~~~~~~
In file included from /home/simon/.platformio/packages/framework-zephyr/include/zephyr/arch/arm/aarch32/arch.h:20,
from /home/simon/.platformio/packages/framework-zephyr/include/zephyr/arch/cpu.h:19,
from /home/simon/.platformio/packages/framework-zephyr/include/zephyr/kernel_includes.h:33:
/home/simon/.platformio/packages/framework-zephyr/include/zephyr/devicetree.h:233:32: error: ‘DT_N_ALIAS_led1_P_gpios_IDX_0_VAL_pin’ was not declared in this scope; did you mean ‘DT_N_S_leds_S_led_0_P_gpios_IDX_0_VAL_pin’?
233 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS
, alias)
| ^~~~~~~~~~~
/home/simon/.platformio/packages/framework-zephyr/include/zephyr/devicetree.h:4151:9: note: in definition of macro ‘DT_CAT7’
4151 | a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7
| ^~
/home/simon/.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)
| ^~~~~~~~~~~~~
/home/simon/.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),
| ^~~~~~~~~~~~~~~~~~
/home/simon/.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)
| ^~~~~~~~~~~~~~~~~~~~~~~
src/main.cpp:13:41: note: in expansion of macro ‘GPIO_DT_SPEC_GET’
13 | static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
| ^~~~~~~~~~~~~~~~
/home/simon/.platformio/packages/framework-zephyr/include/zephyr/devicetree.h:233:25: note: in expansion of macro ‘DT_CAT’
233 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS
, alias)
| ^~~~~~
src/main.cpp:10:19: note: in expansion of macro ‘DT_ALIAS’
10 | #define LED1_NODE DT_ALIAS(led1)
| ^~~~~~~~
src/main.cpp:13:58: note: in expansion of macro ‘LED1_NODE’
13 | static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
| ^~~~~~~~~
src/main.cpp:13:34: warning: ‘led1’ defined but not used [-Wunused-variable]
13 | static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
| ^~~~
*** [.pio/build/stm32l431rc/src/main.o] Error 1

I can’t see why led0 would work but not led1.
I appreciate your help.

EDIT:
I found someone having a similar problem on the Nordic Semi forum:

They don’t seem to be able to give a straight simple answer. Is it really this difficult to do something so basic?
Is it really this difficult

Well it seems like I have to do clean builds if I do changes in the dts file. Is there a way to avoid that?
To clarify, I can’t just do a change in the .dts file and then do pio run. I have to run pio run --target clean and then pio run.

But otherwise I guess that’s the solution