Zephyr and Device Tree GPIO on Custom Board. GPIO won't turn on

Hello,

I'm currently using the nRF SDK V2.6.1 and Zephyr V3.5(.99?) The .99 is the "PATCH". I'm attempting to work with the nRF5340dk.

For context, I'm learning how to work with Zephyr, VS Code, and all that, since before this I was used to the SoftDevice.

I have tried a bunch of tutorials for GPIOs, but here's what doesn't make sense to me.

In VS Code, I created a new project based on the blinky sample, but I want to start from there, so I figured I'll add a simple gpio and start expanding from there.

So I created an Overlay file that looks like this:

/ {
    gpiocustom {
        compatible = "gpio-leds";
        rstpin: rstpin {
            gpios = <&gpio0 3 GPIO_ACTIVE_HIGH>;
            label = "Reset Pin";
            status = "okay";
        };


    };
    aliases {
        rstpin = &rstpin;
    };
};

&gpio0 {
    status = "okay";
};

And wrote a main file that looks like this:

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

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

/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led2)
#define RST_PIN_NODE DT_ALIAS(rstpin)


/*
 * A build error on this line means your board is unsupported.
 * See the sample documentation for information on how to fix this.
 */
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
static const struct gpio_dt_spec resetPin = GPIO_DT_SPEC_GET(RST_PIN_NODE, gpios);

int main(void)
{
	int ret;
	uint16_t i = 0;
	

	if (!gpio_is_ready_dt(&led)) 
	{
		printk("LED not ready for some reason \n");
		return 0;
	}

	if(!gpio_is_ready_dt(&resetPin))
	{
		printk("Reset pin not ready\n");
		return 0;
	}

	ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
	ret = gpio_pin_configure_dt(&resetPin, GPIO_OUTPUT_INACTIVE);

	while (1) {
		ret = gpio_pin_toggle_dt(&led);
		printk("looped = %d\r", i++);

		k_msleep(SLEEP_TIME_MS);

		ret = gpio_pin_toggle_dt(&resetPin);
		k_msleep(SLEEP_TIME_MS );
	}
	return 0;	
}


And when I build it, the led from the original example lights up, but the other gpio (the "reset" pin) does not.

I have gone through several tutorials on the internet, but it doesn't help that most of them are using the original .dts file as opposed to the overlay, or the example doesn't work.

As per docs.zephyrproject.org/.../zephyr-user-node.html,
- I have attempted using the graphical DeviceTree functionality, to create an Overlay with the standard "zephyr,user" node, but the system Errors about not recognizing ZEPHYR_USER_NODE.
- I have attempted the code snippets attached and it doesn't work.

The code that I have compiles without error, but the GPIO just won't change. I have tried a couple other pin numbers, looking at device tree that they were not being used by something else, but I'm not sure how to get this to work.

I have also read other similar issues in the Nordic Support pages, but they seem to branch out towards different issues, where the solution doesn't seem to match what I'm doing.

Could you please provide a plain and simple example of how to add a custom GPIO from an overlay to a sample?

Thank you for your time,

Nico

Parents Reply Children
No Data
Related