This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

extra gpios in board overlay for nrf9160dk

I need a gpio to control an external peripheral.

I thought to code should be similar to controlling one of the leds.

board overlay:

&gpio17 {
  status = "okay"
  gpio17: gpio_17 {
    gpios = <&gpio0 17 0>;
    label = "PUP";
  };
}

Source:

#define PUP_NODE DT_ALIAS(gpio17)
#if DT_NODE_HAS_STATUS(PUP_NODE, okay)
#define PUP DT_GPIO_LABEL(PUP_NODE, gpios)
#define PUP_PIN DT_GPIO_PIN(PUP_NODE, gpios)
#define PUP_FLAGS DT_GPIO_FLAGS(PUP_NODE, gpios)
#else
#error "Unsupported board: gpio17 devicetree alias is not defined"
#endif

const struct device *power_up = device_get_binding(PUP);
gpio_pin_configure(power_up, PUP_PIN, GPIO_OUTPUT_ACTIVE | PUP_FLAGS);
gpio_pin_set(power_up, PUP_PIN, (int)power_up_is_on);

building this with west gives me a syntax error related to the overlay

I don't understand how overlays should define additional gpios beyond the standard ones for leds.

Any advice please?

Parents
  • Hello Paul,

    Wouldn’t it be easier to just use GPIO PIN 17 directly, like in the following example?

    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS   1000
    
    #define GPIO0_LABEL DT_PROP(DT_NODELABEL(gpio0), label)
    #define GPIO0_STATUS DT_PROP(DT_NODELABEL(gpio0), status)
    #define PIN 2
    #define FLAGS 0
    
    void main(void)
    {
        const struct device *dev;
        bool led_is_on = true;
        int ret;
        
        dev = device_get_binding(GPIO0_LABEL);
        if (dev == NULL) {
            return;
        }
        else printf("Periphal %s initialised, status %s \n", GPIO0_LABEL, GPIO0_STATUS);
    
        ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
        if (ret < 0) {
            return;
        }
    
        while (1) {
            gpio_pin_set(dev, PIN, (int)led_is_on);
            led_is_on = !led_is_on;
            k_msleep(SLEEP_TIME_MS);
        }
    }

    But if you prefer grouping for your application, you can have a look at this section:

    https://devzone.nordicsemi.com/f/nordic-q-a/70542/dts-compatible-property-nrf5-sdk/289816#289816

    In this example grouping is done in a .dts file, I recommend you do it in an overlay file instead.

    Regards,

    Markus

  • Thx

    When I add this to my overlay for the 9160-dk ...

    custom_pin_group {
    compatible = "gpio-keys";
      customa: customa {
        gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
      };
      customa: customb {
        gpios = <&gpio0 17 GPIO_ACTIVE_LOW>;
      };
    };

    I get:

    Error: nrf9160dk_nrf9160ns.dts.pre.tmp:608.1-17 syntax error

    FATAL ERROR: Unable to parse input tree

    Line 608 is this one: custom_pin_group {

    I note you other suggestion but am trying to master doing things with overlays if I can.

Reply Children
No Data
Related