GPIO P1.xx Interrupt Configuration

Hello,

I 're configuring GPIO pin for interrupt application.using EVK-NORA-B106 board.

My setup requires pin P1.05 then, I update the .dts file as follow:

Despite, the GPIO configuration using the functions:

gpio_pin_configure
gpio_pin_interrupt_configure
gpio_init_callback
gpio_add_callback
Interrupt doesn't work.
Issue could be genereted from warning displyed in the image? Implementation in .dts is correct?
For verification, I tried to use different pins and with P1.xx result is the same instead using pin P0.xx, interrupt works.
Thank you.
MP
  • Hi,

    Which code do you use to test this?

    Can you try the nrfx peripheral resource sharing example for your custom board?
    (If it works more or less out of the box)

    It should have gpio callbacks, so it is a way to check if the error is in hardware or software.

    Regards,
    Sigurd Hellesvik

  • Hello,

    I used the button example adding interrupt signal configuration in main.c file 

    /*
     * Copyright (c) 2016 Open-RnD Sp. z o.o.
     * Copyright (c) 2020 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr.h>
    #include <device.h>
    #include <drivers/gpio.h>
    #include <sys/util.h>
    #include <sys/printk.h>
    #include <inttypes.h>
    #include <irq.h>
    
    
    #define SLEEP_TIME_MS	1000
    
    
    #define INT_NODE DT_PHANDLE(DT_PATH(zephyr_user), interrupt_gpios)
    
    #define MY_DEV_IRQ  22       /* device uses IRQ 24 */
    #define MY_DEV_PRIO  2       /* device uses interrupt priority 2 */
    /* argument passed to my_isr(), in this case a pointer to the device */
    #define MY_ISR_ARG  DEVICE_DT_GET(INT_NODE)
    #define MY_IRQ_FLAGS 0       /* IRQ flags. Unused on non-x86 */
    
    const struct device *int_dev = DEVICE_DT_GET(INT_NODE);
    
    /*
     * Get button configuration from the devicetree sw0 alias. This is mandatory.
     */
    #define SW0_NODE	DT_ALIAS(sw0)
    #if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
    #error "Unsupported board: sw0 devicetree alias is not defined"
    #endif
    static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,{0});
    static struct gpio_callback button_cb_data;
    
    static const struct gpio_dt_spec int_gen = GPIO_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), interrupt_gpios, 0);
    static struct gpio_callback int_cb_data;
    
    /*
     * The led0 devicetree alias is optional. If present, we'll use it
     * to turn on the LED whenever the button is pressed.
     */
    static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios, {0});
    
    
    void button_pressed(const struct device *dev, struct gpio_callback *cb,
    		    uint32_t pins)
    {
    	printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
    }
    
    void interrupt_service(const struct device *dev, struct gpio_callback *cb,
    		    uint32_t pins)
    {
    	printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
    }
    
    /*void my_isr(void *arg)
    {
       printk("Button ");
    }*/
    
    void main(void)
    {
    	int ret;
    
    	/*if (!device_is_ready(int_dev)) {
    		  printk("ADC device not found\n");
    		return;
    	}*/
    
    	if (!device_is_ready(button.port)) {
    		printk("Error: button device %s is not ready\n",
    		       button.port->name);
    		return;
    	}
    
    	ret = gpio_pin_configure_dt(&int_gen, GPIO_INPUT);
    	//ret = gpio_pin_configure(int_dev, MY_DEV_IRQ, GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error ");
    		return;
    	}
    	ret = gpio_pin_interrupt_configure_dt(&int_gen, GPIO_INT_EDGE_TO_ACTIVE);
    	//ret = gpio_pin_interrupt_configure(int_dev, MY_DEV_IRQ, GPIO_INT_EDGE_RISING);
    	if (ret != 0) {
    		printk("Error ");
    		return;
    	}
    
    
    	ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error %d: failed to configure %s pin %d\n",
    		       ret, button.port->name, button.pin);
    		return;
    	}
    
    	ret = gpio_pin_interrupt_configure_dt(&button,
    					      GPIO_INT_EDGE_TO_ACTIVE);
    	if (ret != 0) {
    		printk("Error %d: failed to configure interrupt on %s pin %d\n",
    			ret, button.port->name, button.pin);
    		return;
    	}
    
    	gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));
    	gpio_add_callback(button.port, &button_cb_data);
    	printk("Set up button at %s pin %d\n", button.port->name, button.pin);
    
    	gpio_init_callback(&int_cb_data, interrupt_service, BIT(int_gen.pin));
    	gpio_add_callback(int_gen.port, &int_cb_data);
    	printk("Set up button at %s pin %d\n", int_gen.port->name, int_gen.pin);
    
    	if (led.port && !device_is_ready(led.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",
    		       ret, led.port->name);
    		led.port = NULL;
    	}
    	if (led.port) {
    		ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",
    			       ret, led.port->name, led.pin);
    			led.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", led.port->name, led.pin);
    		}
    	}
    	
    	//IRQ_CONNECT(MY_DEV_IRQ, MY_DEV_PRIO, my_isr, MY_ISR_ARG, MY_IRQ_FLAGS);
        //irq_enable(MY_DEV_IRQ);
    
    	printk("Press the button\n");
    	if (led.port) {
    		while (1) {
    			/* If we have an LED, match its state to the button's. */
    			int val = gpio_pin_get_dt(&button);
    
    			if (val >= 0) {
    				gpio_pin_set_dt(&led, val);
    			}
    			k_msleep(SLEEP_TIME_MS);
    		}
    	}
    }
    
       

    and added in .dts file the following declaration:

    zephyr,user{
    		interrupt-gpios = <&gpio1 4 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;		
    	};

    Then, I found the root cause in gpio channel.

    Using gpio1 I have access to P1.xx.

    Thank you for your support,

Related