Button interrupt in Bootloader

Hi,

I am trying to edit my bootloader (buttonless USB DFU).

I want to add a button to exit the bootloader and return to the app.

The problem is that the gpiote interrupt is not firing.

The gpiote_event_handler I inserted in the function nrf_drv_gpiote_in_init(p_btn->pin_no, &config, gpiote_event_handler) is never hit.

Am I missing some setting?

I am using SDK 17.0.0

Thanks

Parents
  • Hi,

    This should work. I did a quick example now based on the <SDK17.1.0>\examples\dfu\open_bootloader\pca10056_usb_debug\ses\.

    The changes from the default project is this in main.c:

    diff --git a/examples/dfu/open_bootloader/main.c b/examples/dfu/open_bootloader/main.c
    index 48dd76b..c93eec1 100644
    --- a/examples/dfu/open_bootloader/main.c
    +++ b/examples/dfu/open_bootloader/main.c
    @@ -63,6 +63,7 @@
     #include "app_timer.h"
     #include "nrf_delay.h"
     #include "nrf_clock.h"
    +#include "nrf_drv_gpiote.h"
     
     /* Timer used to blink LED on DFU progress. */
     APP_TIMER_DEF(m_dfu_progress_led_timer);
    @@ -194,6 +195,31 @@ static void dfu_observer(nrf_dfu_evt_type_t evt_type)
                 break;
         }
     }
    +
    +
    +void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    +{
    +    NRF_LOG_INFO("Pin change interrupt!");
    +}
    +
    +
    +static void gpio_in_init(void)
    +{
    +    ret_code_t err_code;
    +
    +    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.pull = NRF_GPIO_PIN_PULLUP;
    +
    +    err_code = nrf_drv_gpiote_in_init(BSP_BUTTON_0, &in_config, in_pin_handler);
    +    APP_ERROR_CHECK(err_code);
    +
    +    nrf_drv_gpiote_in_event_enable(BSP_BUTTON_0, true);
    +}
    +
    +
     /**@brief Function for application main entry.
      */
     int main(void)
    @@ -216,6 +242,8 @@ int main(void)
         NRF_LOG_INFO("Open USB bootloader started");
         NRF_LOG_FLUSH();
     
    +    gpio_in_init();
    +
         ret_val = nrf_bootloader_init(dfu_observer);
         APP_ERROR_CHECK(ret_val);
     
    

    and this in sdk_config.h:

    diff --git a/examples/dfu/open_bootloader/pca10056_usb_debug/config/sdk_config.h b/examples/dfu/open_bootloader/pca10056_usb_debug/config/sdk_config.h
    index 41bf7db..aa8c99c 100644
    --- a/examples/dfu/open_bootloader/pca10056_usb_debug/config/sdk_config.h
    +++ b/examples/dfu/open_bootloader/pca10056_usb_debug/config/sdk_config.h
    @@ -1377,7 +1377,113 @@
     // </h> 
     //==========================================================
     
    -// <h> nRF_Drivers 
    +// <h> nRF_Drivers
    +
    +//==========================================================
    +// <e> GPIOTE_ENABLED - nrf_drv_gpiote - GPIOTE peripheral driver - legacy layer
    +//==========================================================
    +#ifndef GPIOTE_ENABLED
    +#define GPIOTE_ENABLED 1
    +#endif
    +// <o> GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins 
    +#ifndef GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
    +#define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
    +#endif
    +
    +// <o> GPIOTE_CONFIG_IRQ_PRIORITY  - Interrupt priority
    + 
    +
    +// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    +// <0=> 0 (highest) 
    +// <1=> 1 
    +// <2=> 2 
    +// <3=> 3 
    +// <4=> 4 
    +// <5=> 5 
    +// <6=> 6 
    +// <7=> 7 
    +
    +#ifndef GPIOTE_CONFIG_IRQ_PRIORITY
    +#define GPIOTE_CONFIG_IRQ_PRIORITY 4
    +#endif
    +
    +// </e>
    +
    +// <e> NRFX_GPIOTE_ENABLED - nrfx_gpiote - GPIOTE peripheral driver
    +//==========================================================
    +#ifndef NRFX_GPIOTE_ENABLED
    +#define NRFX_GPIOTE_ENABLED 1
    +#endif
    +// <o> NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins 
    +#ifndef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
    +#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
    +#endif
    +
    +// <o> NRFX_GPIOTE_CONFIG_IRQ_PRIORITY  - Interrupt priority
    + 
    +// <0=> 0 (highest) 
    +// <1=> 1 
    +// <2=> 2 
    +// <3=> 3 
    +// <4=> 4 
    +// <5=> 5 
    +// <6=> 6 
    +// <7=> 7 
    +
    +#ifndef NRFX_GPIOTE_CONFIG_IRQ_PRIORITY
    +#define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 6
    +#endif
    +
    +// <e> NRFX_GPIOTE_CONFIG_LOG_ENABLED - Enables logging in the module.
    +//==========================================================
    +#ifndef NRFX_GPIOTE_CONFIG_LOG_ENABLED
    +#define NRFX_GPIOTE_CONFIG_LOG_ENABLED 0
    +#endif
    +// <o> NRFX_GPIOTE_CONFIG_LOG_LEVEL  - Default Severity level
    + 
    +// <0=> Off 
    +// <1=> Error 
    +// <2=> Warning 
    +// <3=> Info 
    +// <4=> Debug 
    +
    +#ifndef NRFX_GPIOTE_CONFIG_LOG_LEVEL
    +#define NRFX_GPIOTE_CONFIG_LOG_LEVEL 3
    +#endif
    +
    +// <o> NRFX_GPIOTE_CONFIG_INFO_COLOR  - ANSI escape code prefix.
    + 
    +// <0=> Default 
    +// <1=> Black 
    +// <2=> Red 
    +// <3=> Green 
    +// <4=> Yellow 
    +// <5=> Blue 
    +// <6=> Magenta 
    +// <7=> Cyan 
    +// <8=> White 
    +
    +#ifndef NRFX_GPIOTE_CONFIG_INFO_COLOR
    +#define NRFX_GPIOTE_CONFIG_INFO_COLOR 0
    +#endif
    +
    +// <o> NRFX_GPIOTE_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
    + 
    +// <0=> Default 
    +// <1=> Black 
    +// <2=> Red 
    +// <3=> Green 
    +// <4=> Yellow 
    +// <5=> Blue 
    +// <6=> Magenta 
    +// <7=> Cyan 
    +// <8=> White 
    +
    +#ifndef NRFX_GPIOTE_CONFIG_DEBUG_COLOR
    +#define NRFX_GPIOTE_CONFIG_DEBUG_COLOR 0
    +#endif
    +
    +// </e>
     
     //==========================================================
     // <e> NRFX_CLOCK_ENABLED - nrfx_clock - CLOCK peripheral driver
    

    If you test that with a nRF52840 DK and press button 1 (0 in code), you will see a line printed.

  • Hi Einar,

    This test was very helpful.

    It seems my issue lies with the app_timer. The button IRQ is firing, but the debounce timer that app_button uses is not working. I think it has something to do with the fact that the DFU code uses a scheduler

Reply Children
Related