add pin configuration in overlay file

Hi

I want to set P0.01 as gpio high, how do I configure in overlay file?

so that it remain high whenever I used overlay file.

Thanks !!

Parents Reply Children
  • Hi Amol,

    The following code would do the work. It would set pin 14 high whenever the mcu is booted. (I have tested with the pin number 14 that is connected to the led1).

    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/drivers/gpio.h>
    
    #define PORT    gpio0
    #define PIN  	14
    #define DIRFLAG 1
    
    static const struct device * DEV = DEVICE_DT_GET(DT_NODELABEL(PORT));
    
    int main(void)
    {
    	struct gpio_dt_spec pinspec = {.port=DEV, .pin=PIN, .dt_flags=DIRFLAG};
    	gpio_pin_configure_dt(&pinspec, GPIO_OUTPUT_ACTIVE);
    	gpio_pin_set_dt(&pinspec,1);	
    }

Related