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

Cannot get button/gpio interrupt on NET CPU using nRF5340DK

Using just the nRF Connect SDK, I cannot get a push button to interrupt the NET CPU on the nRF5340DK.

I have the following code on the APP CPU:

  nrf_gpio_pin_mcu_select(23, NRF_GPIO_PIN_MCUSEL_NETWORK);

The following code runs on the NET CPU:

  nrfx_gpiote_init(NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);
  nrfx_gpiote_in_config_t cfg = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
  cfg.pull = NRF_GPIO_PIN_PULLUP;
  nrfx_gpiote_in_init(NRF_GPIO_PIN_MAP(0, 23), &cfg, MyEventHandler);
  nrfx_gpiote_in_event_enable(NRF_GPIO_PIN_MAP(0, 23), true);

Please help identify what I'm missing. Thank you in advance!

  • Hi,

    I cannot get a push button to interrupt the NET CPU on the nRF5340DK.

    By default, all pins are assigned to the application core. The application core's MCUSEL bitfield in register PIN_CNF[n] (n=0..31) (Retained) controls the allocation of the pins into cores, peripherals and the TaD subsystem. See this page.

    In order to enable the network domain to have control of the GPIO,set the GPIO's MCUSEL to NetworkMCU. You can add this to the remoteproc_mgr_config() function, similar to how it's done for the UART pins in that function.

    NRF_P0->PIN_CNF[MY_PIN_NUMBER] =
    	GPIO_PIN_CNF_MCUSEL_NetworkMCU << GPIO_PIN_CNF_MCUSEL_Pos;

  • Sigurd,

    Thanks for the response. However, I believe my code is already doing what you suggested. Unless I'm missing something, can you please elaborate?

    John

  • Hi,

    Did you connect GPIOTE_0 IRQ to nrfx_gpiote_irq_handler ?

    You could take a look at how it's done in the Zephyr nrfx sample. See this link. To test this sample, build the nrfx sample for the nrf5340pdk_nrf5340_cpunet. And for the app core, you could e.g. use the NCS empty_app_core sample, and build that for nrf5340pdk_nrf5340_cpuapp. See this link.

  • Ahh...I missed this. I have this connected now but still do not get an interrupt.

    I verified pin configuration is correct by using nrf_gpio_pin_read(23). I can see the return value is the correct button state. This confirms the NET CPU is in control of the pin.

    Now it is just a matter of getting a NET CPU interrupt on button toggle. These are the registers I verified after button push (looks correct):

    INTENSET (0x4100A304) = 0x8000000f
    EVENTS_IN[0] (0x4100A100) = 0x1
    EVENTS_IN[1] (0x4100A104) = 0x1
    EVENTS_IN[2] (0x4100A108) = 0x1
    EVENTS_IN[3] (0x4100A10C) = 0x1

    As for connecting ISR handlers, I confirmed the vector table is setup in this manner:

    SCB->VTOR = IrqVectors[]
    IrqVectors[26] =nrfx_gpiote_irq_handler  // 26: GPIOTE_IRQn
    NVIC_EnableIRQ(GPIOTE_IRQn);

    Global interrupts are enabled. Any thing else I should check?

  • The following works fine here, testing on NCS v1.3.0 on a PCA10095 version 0.7.0

    For nrf5340pdk_nrf5340_cpuapp, I'm running the empty_app_core sample.

    On nrf5340pdk_nrf5340_cpunet, I'm running this:

    main.c

    /*
     * Copyright (c) 2019 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr.h>
    
    #include <nrfx_gpiote.h>
    
    #include <logging/log.h>
    LOG_MODULE_REGISTER(nrfx_sample, LOG_LEVEL_INF);
    
    static void button_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
    	LOG_INF("GPIO input event callback");
    }
    
    void main(void)
    {
    	LOG_INF("nrfx_gpiote sample on %s", CONFIG_BOARD);
    
    	/* Connect GPIOTE_0 IRQ to nrfx_gpiote_irq_handler */
    	IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
    		    DT_IRQ(DT_NODELABEL(gpiote), priority),
    		    nrfx_isr, nrfx_gpiote_irq_handler, 0);
    
    
        nrfx_gpiote_init(NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);
        nrfx_gpiote_in_config_t cfg = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
        cfg.pull = NRF_GPIO_PIN_PULLUP;
        nrfx_gpiote_in_init(NRF_GPIO_PIN_MAP(0, 23), &cfg, button_handler);
        nrfx_gpiote_in_event_enable(NRF_GPIO_PIN_MAP(0, 23), true);
      
    }
    

    prj.conf

    CONFIG_GPIO=n
    CONFIG_NRFX_GPIOTE=y
    CONFIG_LOG=y
    CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100
    

    Then when I press button 1 (pin 23) on the kit, I get "GPIO input event callback" printed in the terminal (see this link on how to get log-output).

Related