This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ncs gpiote interrupt issue

Hi,

Using the SDK 17 library, i had the following code running fine:

	//Setup the external interupt and timer interupt
	//Pin Interupt setup
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    in_config.sense = NRF_GPIOTE_POLARITY_HITOLO;
    in_config.pull = NRF_GPIO_PIN_PULLUP;
    //in_config.hi_accuracy = true;

    err_code = nrf_drv_gpiote_in_init(IO_NET_RX, &in_config, NET_INTERRUPT);
    APP_ERROR_CHECK(err_code);

    nrfx_gpiote_in_event_enable(IO_NET_RX, true);
    ......
    
    static void NET_INTERRUPT(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        nrf_drv_timer_clear(&NET_TIMER);
    	nrf_drv_timer_disable(&NET_TIMER);
    	nrf_drv_gpiote_in_event_disable(IO_NET_RX);
        ...
    }
    

Now i am porting it to ncs 1.9.0, i have changed the code to:

	//Setup the external interupt and timer interupt
	//Pin Interupt setup
	// ** IN NCS THIS SEEMS TO ALREADY BE INITIALISED
	if (!nrfx_gpiote_is_init()){
    	err_code = nrfx_gpiote_init(2);
		if (err_code != NRFX_SUCCESS) {
			printk("Failed to init gpiote (err %d)\n", err_code);
			return;
		}
	}	
    
    nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    in_config.sense = NRF_GPIOTE_POLARITY_HITOLO;
    in_config.pull = NRF_GPIO_PIN_PULLUP;
    //in_config.hi_accuracy = true;

    err_code = nrfx_gpiote_in_init(IO_NET_RX, &in_config, NET_INTERRUPT);
     if (err_code != NRFX_SUCCESS) {
		printk("Failed to init gpiote in (err %d)\n", err_code);
		return;
	}	

    nrfx_gpiote_in_event_enable(IO_NET_RX, true);	
    
    ......
    
    static void NET_INTERRUPT(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
    	nrf_drv_gpiote_in_event_disable(IO_NET_RX);
        ...
    }
    

Upon running, i get the following zephr error:

(sorry, copy/paste doesnt seem to work from the nrf terminal)

Any pointers to what has not been setup correctly?

many thanks

Parents
  • Hi,

     

    Here's a simple example on how to use it, based on hello_world:

    /*
     * Copyright (c) 2012-2014 Wind River Systems, Inc.
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr.h>
    #include <sys/printk.h>
    #include <hal/nrf_gpio.h>
    #include <nrfx_gpiote.h>
    
    #define IO_NET_RX 13
    #define LED_0 17
    
    static void NET_INTERRUPT(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
    	nrf_gpio_pin_toggle(LED_0);
    }
    
    void main(void)
    {
    	printk("Hello World! %s\n", CONFIG_BOARD);
    	nrf_gpio_cfg_output(LED_0);
    	uint32_t err_code;
    	if (!nrfx_gpiote_is_init()){
        	err_code = nrfx_gpiote_init(2);
    		if (err_code != NRFX_SUCCESS) {
    			printk("Failed to init gpiote (err %d)\n", err_code);
    			return;
    		}
    	}
    	nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    	in_config.sense = NRF_GPIOTE_POLARITY_HITOLO;
    	in_config.pull = NRF_GPIO_PIN_PULLUP;
    	//in_config.hi_accuracy = true;
    
    	err_code = nrfx_gpiote_in_init(IO_NET_RX, &in_config, NET_INTERRUPT);
    	if (err_code != NRFX_SUCCESS) {
    		printk("Failed to init gpiote in (err %d)\n", err_code);
    		return;
    	}
    
    	nrfx_gpiote_in_event_enable(IO_NET_RX, true);
    }
    

     

    Here's my prj.conf:

    CONFIG_GPIO=y
    CONFIG_NRFX_GPIOTE=y
    # Comment in this if you get mpu/stack faults on the uart
    # CONFIG_MAIN_STACK_SIZE=4096

     

    Could you check if this works on your end?

     

    Kind regards,

    Håkon

  • Hi Håkon,

    Thanks for your reply

    After testing further, i found its actually a timer which is causing the problem, i also have the following code:

    static void NET_TIMER_INTERRUPT(nrf_timer_event_t event_type, void* p_context)
    {
    	nrf_gpio_pin_toggle(IO_NET_DGB);
    }
    
    
    const nrfx_timer_t NET_TIMER = NRFX_TIMER_INSTANCE(2);
    
    #define NET_SILENCE_POWER_DETECT_US	(8000ul)
    static uint32_t NET_SILENCE_POWER_DETECT;
    
    void init(void)	
    {
    	
    	//Timer setup
    	nrfx_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
    
        timer_cfg.mode = NRF_TIMER_MODE_TIMER;
        timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
        timer_cfg.frequency = NRF_TIMER_FREQ_8MHz;
        timer_cfg.interrupt_priority = 3; 
    
        err_code = nrfx_timer_init(&NET_TIMER, &timer_cfg, NET_TIMER_INTERRUPT);
        if (err_code != NRFX_SUCCESS) {
    		printk("Failed to init timer (err %d)\n", err_code);
    		return;
    	}	
    	
    	//Reset the timer
    	nrfx_timer_clear(&NET_TIMER);
    	
    	//Syncronise the start of the next packet
    	NET_SILENCE_POWER_DETECT = nrfx_timer_us_to_ticks(&NET_TIMER, NET_SILENCE_POWER_DETECT_US);
    	nrfx_timer_extended_compare(&NET_TIMER, NRF_TIMER_CC_CHANNEL0, (NET_SILENCE_POWER_DETECT/4), NRF_TIMER_SHORT_COMPARE0_STOP_MASK, true);
    	
    	//Enable Timer + External Interupt
    	nrfx_timer_enable(&NET_TIMER);
    
    }

    This is the code causing the interrupt exception, the gpiote is working fine

    my prj.conf contains

    CONFIG_NRFX_TIMER2=y

    Again, this code seems fine under the SDK 17

    Regards

    Billy

Reply
  • Hi Håkon,

    Thanks for your reply

    After testing further, i found its actually a timer which is causing the problem, i also have the following code:

    static void NET_TIMER_INTERRUPT(nrf_timer_event_t event_type, void* p_context)
    {
    	nrf_gpio_pin_toggle(IO_NET_DGB);
    }
    
    
    const nrfx_timer_t NET_TIMER = NRFX_TIMER_INSTANCE(2);
    
    #define NET_SILENCE_POWER_DETECT_US	(8000ul)
    static uint32_t NET_SILENCE_POWER_DETECT;
    
    void init(void)	
    {
    	
    	//Timer setup
    	nrfx_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
    
        timer_cfg.mode = NRF_TIMER_MODE_TIMER;
        timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
        timer_cfg.frequency = NRF_TIMER_FREQ_8MHz;
        timer_cfg.interrupt_priority = 3; 
    
        err_code = nrfx_timer_init(&NET_TIMER, &timer_cfg, NET_TIMER_INTERRUPT);
        if (err_code != NRFX_SUCCESS) {
    		printk("Failed to init timer (err %d)\n", err_code);
    		return;
    	}	
    	
    	//Reset the timer
    	nrfx_timer_clear(&NET_TIMER);
    	
    	//Syncronise the start of the next packet
    	NET_SILENCE_POWER_DETECT = nrfx_timer_us_to_ticks(&NET_TIMER, NET_SILENCE_POWER_DETECT_US);
    	nrfx_timer_extended_compare(&NET_TIMER, NRF_TIMER_CC_CHANNEL0, (NET_SILENCE_POWER_DETECT/4), NRF_TIMER_SHORT_COMPARE0_STOP_MASK, true);
    	
    	//Enable Timer + External Interupt
    	nrfx_timer_enable(&NET_TIMER);
    
    }

    This is the code causing the interrupt exception, the gpiote is working fine

    my prj.conf contains

    CONFIG_NRFX_TIMER2=y

    Again, this code seems fine under the SDK 17

    Regards

    Billy

Children
Related