I need help getting a GPIO to work from the DTS to the code

Hi all,

this is a bit embarrassing, I updated from nrf SDK 2.5.0 to 3.1.1 and I'm a bit lost with the simplest things.

I need to toggle an LED on a custom board. I'm using an NRF52840 on a UBLOX module. The JLINK debugger recognises the microcontroller, and the power applied is ok.

I have a prj.conf file where the GPIO is enabled:

CONFIG_GPIO=y
I have an overlay file in the "boards" subfolder inside the project with the following statements:
/ { 
    
	leds {
		compatible = "gpio-leds";

		led0: led_0{
			gpios = < &gpio0 24 GPIO_ACTIVE_HIGH>;
			label = "LED0";
		};

		led1: led_1{
			gpios = < &gpio1 16 GPIO_ACTIVE_HIGH>;
			label = "LED1";
		};
	};
};
The init code for the GPIO is following (based on online examples and a previous project with the older SDK 2.5.0):
#define GPIO_LED_0_NODE DT_NODELABEL(led0)
static struct gpio_dt_spec gpio_led_0 = GPIO_DT_SPEC_GET(GPIO_LED_0_NODE, gpios);

void pin_ios_init(void)
{
	
	gpio_pin_configure_dt(&gpio_led_0, GPIO_DISCONNECTED);

	if (!gpio_is_ready_dt(&gpio_led_0))
	{
		LOG_ERR("Error LED 0 init");
	}

	return;
}
When I try to build, I noticed a warning:
CMake Warning at C:/ncs/v3.1.1/zephyr/CMakeLists.txt:1027 (message):
No SOURCES given to Zephyr library: drivers__gpio

Excluding target from build.
After a while everything else fails due to:
C:/ncs/v3.1.1/zephyr/include/zephyr/device.h:96:41: error: '__device_dts_ord_14' undeclared here (not in a function); did you mean '__device_dts_ord_104'?
   96 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                         ^~~~~~~~~
C:/ncs/v3.1.1/zephyr/include/zephyr/toolchain/common.h:168:26: note: in definition of macro '_DO_CONCAT'
  168 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
C:/ncs/v3.1.1/zephyr/include/zephyr/device.h:96:33: note: in expansion of macro '_CONCAT'
   96 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                 ^~~~~~~
C:/ncs/v3.1.1/zephyr/include/zephyr/device.h:293:37: note: in expansion of macro 'DEVICE_NAME_GET'
  293 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
      |                                     ^~~~~~~~~~~~~~~
C:/ncs/v3.1.1/zephyr/include/zephyr/device.h:310:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
  310 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
      |                                  ^~~~~~~~~~~~~~~~~~
C:/ncs/v3.1.1/zephyr/include/zephyr/drivers/gpio.h:334:25: note: in expansion of macro 'DEVICE_DT_GET'
  334 |                 .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
      |                         ^~~~~~~~~~~~~
C:/ncs/v3.1.1/zephyr/include/zephyr/drivers/gpio.h:370:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
  370 |         GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
      |         ^~~~~~~~~~~~~~~~~~~~~~~
C:/Users/fahre/Projects/_resonAg/Firmware/gamma_comms/src/tasks/pin_ios.c:14:41: note: in expansion of macro 'GPIO_DT_SPEC_GET'
   14 | static struct gpio_dt_spec gpio_led_0 = GPIO_DT_SPEC_GET(GPIO_LED_0_NODE, gpios);
Any help or pointers are greatly appreciated.
Cheers,
Albert
Parents Reply Children
  • Hi Edvin,

    I didn't get it working yet. It was just a mistake on the original question. I'll zip up the project later today, I'll still try to get it working.

    This is a custom board, but like I mentioned before, the programmer works and the microcontroller is detected. I have an LED on P0.24 that I'd like to toggle and it's something I'm struggling with the DTS currently.

    Cheers,

    Alberto

Related