Adding to the device tree with overlays - Zephyr

I'm still new to Zephyr, so this could be an easy question that I'm googling poorly - if so, sorry in advance.  I just wanted to add an extra LED, led4, to the existing nrf9160dk device tree.  I tried adding it directly to the device tree like so

...

leds {
	compatible = "gpio-leds";
	led0: led_0 {
		gpios = <&gpio0 2 0>;
		label = "Green LED 1";
	};
	led1: led_1 {
		gpios = <&gpio0 3 0>;
		label = "Green LED 2";
	};
	led2: led_2 {
		gpios = <&gpio0 4 0>;
		label = "Green LED 3";
	};
	led3: led_3 {
		gpios = <&gpio0 5 0>;
		label = "Green LED 4";
	};
	led4: led_4 {
		gpios = <&gpio0 10 0>;
		label = "My red LED";
	};
};

...

aliases {
	led0 = &led0;
	led1 = &led1;
	led2 = &led2;
	led3 = &led3;
	led4 = &led4;
	pwm-led0 = &pwm_led0;
	sw0 = &button2;
	
...

but I get errors when trying to use DT_ALIAS(led4) telling me that there is no such device (error: 'DT_N_ALIAS_led4_P_gpios_IDX_0_VAL_pin' undeclared). Everything works fine for LEDs 0 - 3.

I figure that there is some juju with the using the dts files themselves (some command that you have to run in west to rebuild device trees?) so that overlays are preferred for this sort of thing.  So instead, I added the data in an overlay like this

/ {
	leds {
		led4: led_4 {
			gpios = <&gpio0 10 0>;
			label = "My red LED";
		};
	};

	aliases {
		led4 = &led4;
    };
};

with no change to the result.  I am fairly sure that I'm just missing the part of the documentation that tells you how to extend an existing device tree or overlay to accommodate new functionality, so if someone could point me in that direction it would be very helpful!

*EDIT:* I should add that I also added the overlay to CMakeLists.txt and I can see that it looks in the overlay, so I'm pretty confident that it is getting seen during build.

Parents Reply Children
No Data
Related