GPIO overlays

I've been looking through this forum for advice on GPIO overlays and there seems to be a lot of confusion.

So I looked at the button and blinky examples and put together the following overlay for my board:

/{
	custom_leds {
 	   compatible = "gpio-leds";
	   led0: led_0 {
		  gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>;
		  label = "My custom LED";
	   };
	};
	aliases {
		mycustomled = &led0;
	};
 };
 

This repurposes GPIO 15 to be an LED instead of a button as it was in the original dts file.

The first problem with this approach is that I get the following warning:

Pin 15 of &gpio0 already assigned to &button2
bl652_dvk.dts(44, 12): Overlapping assignment

I suspect I'm not doing the overlay correctly to remap a GPIO from a button in the dts to an LED in the overlay. But it does build.

The next thing I do is to try and get a device in the runtime code with the following line:

const struct device * dev_custom_led = DEVICE_DT_GET(DT_NODELABEL(mycustomled));

This does not build, even though it's the same mechanism that I use to get the device for other things like the ADC or the SPI bus. So I suspect the warning in the device tree overlay is actually an error.

How should I do this? How do I use an overlay to repurpose a GPIO?

Related