XIAO nrf52840 Sense GPIO pin control with Zephyr

I’m working in Zephyr to have a bit more control over the BLE, but I’m currently just trying to map a GPIO pin (12) to a device tree node defined in my overlay file that allocates gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>; The problem is that pin 12 is already occupied by uart0_default. Therefore, I deleted the node and substituted a node in the overlay file (shown below).

> /delete-node/ &uart0_default;
> /delete-node/ &uart0_sleep;
> / {
> 	csn_pins {
> 		compatible = "spi-rhd";
> 		csn1: csn_1 {
> 			gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
> 			label = "csn manual gpio pin";
> 		};
> 	};
> };

I also have a corresponding yaml bindings folder in dts/bindings that defines the service:

description: |
  test
compatible: "spi-rhd"
child-binding:
  description: GPIO SPI CSN
  properties:
    gpios:
      type: phandle-array
      required: true
    label:
      type: string
      description: |
        Human readable string

Then I’m trying to just toggle the pin on a timer.

#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/printk.h>
#define CSN_NODE DT_NODELABEL(csn1)
static const struct gpio_dt_spec csn_spec = GPIO_DT_SPEC_GET(CSN_NODE, gpios);
int main(void) {
    int ret;
    ret = gpio_pin_configure_dt(&csn_spec, GPIO_OUTPUT_INIT_LOW);
    while (1) {
        gpio_pin_set_dt(&csn_spec, 0);
        k_sleep(K_MSEC(1000));
        gpio_pin_set_dt(&csn_spec, 1);
        k_sleep(K_MSEC(1000));
    }
}

So far, the code compiles and the new bindings are found and accepted, but I’m unable to see any change on the pin. Any pointers? I’m really confused why it is so hard to use an arbitrary pin on the board as a gpio.

In your code, you use DT_NODELABEL(csn1) but your device tree overlay defines it as csn_1. Update this to DT_NODELABEL(csn_1) or change the device tree node label to csn1 to match the code.

1 Like

I changed both to csn1. Still compiles but I’m not getting any new behavior on pin 12.