Arduino Nano 33 BLE Sense Unresponsive when IRQ is triggered through NRF's EGU

Hello,

Right now I am planning on adding a simple custom interrupt to a voltmeter setup I have developed for a more consistent SAADC sampling rate. I have largely bypassed the existing Arduino API due to its lack of features which shield many of the capabilities of the NRF52840.

Using the forum here in Nordic's website, I was able to develop an IRQ using the NRF52840's EGU (Event Generator Unit), and the CPU's nested NVIC (Nested Vector Interrupt Control).

The following code is what I used roughly when testing the interrupt. The result is after the line below, the board becomes unresponsive.

NRF_EGU3->TASKS_TRIGGER[0] = 1;

I have experienced issues in the past with the code in Arduino interrupts being too long causing the system to stall; however, this IRQ does not have anything except clearing the triggered event flag. Any ideas why this is happening?

UPDATE: Please refer my last post below. It seems after this exercise that direct insertion of NRF interrupts through the EGU are currently unsupported in the Arduino development. As a result, I ended up using a TIMER interrupt. In the future, if anyone has updates/knowhow in this area, feel free to include them in this forum.

#include "nrf_egu.h" // Event Generator Unit HAL

void SWI3_EGU3_IRQHandler(void)
{   
    // Clear SWI Event. 
    NRF_EGU3->EVENTS_TRIGGERED[0] = 0;
}

static void init_egu()
{  
    // Enable TRIGGERED0 interrupt
    NRF_EGU3->INTENSET = EGU_INTENSET_TRIGGERED0_Enabled << EGU_INTENSET_TRIGGERED0_Pos;
    
    // Set EGU3 Interrupt priority to 6 (Default).
    NVIC_SetPriority(SWI3_EGU3_IRQn,6);
    
    //Enable SWI3_EGU3 interrupt. 
    NVIC_EnableIRQ(SWI3_EGU3_IRQn);
}


void setup()
{   
    // Initialize the EGU
    egu_init();
    
    // Trigger event
    NRF_EGU3->TASKS_TRIGGER[0] = 1; // CRASH OCCURS HERE

    // Extra code
}

void loop()
{
    // Extra code
}

Thanks!

After some investigation into Arduino's source code for mbedOs in file nrf52840.h, I found the following code.

  • It seems the Interrupt number does exist and should be unique from the other peripheral interrupts.
  • I also was able to verify that the interrupt is enabled.
  • I also verified that when the interrupt in the EGU is not enabled, it does not executed when the TASKS_TRIGGER[0] register is toggled.
  • I tested this on multiple boards (Arduino Nano 33 BLE/Arduino Nano 33 BLE Sense) with the same crash occurring.

I am still curious on as to why the system crashes after the enabled interrupt is triggered.

/* -------------------------  Interrupt Number Definition  ------------------------ */

typedef enum {
/* -------------------  Cortex-M4 Processor Exceptions Numbers  ------------------- */
  Reset_IRQn                    = -15,              /*!<   1  Reset Vector, invoked on Power up and warm reset                 */
  NonMaskableInt_IRQn           = -14,              /*!<   2  Non maskable Interrupt, cannot be stopped or preempted           */
  HardFault_IRQn                = -13,              /*!<   3  Hard Fault, all classes of Fault                                 */
  MemoryManagement_IRQn         = -12,              /*!<   4  Memory Management, MPU mismatch, including Access Violation
                                                         and No Match                                                          */
  BusFault_IRQn                 = -11,              /*!<   5  Bus Fault, Pre-Fetch-, Memory Access Fault, other address/memory
                                                         related Fault                                                         */
  UsageFault_IRQn               = -10,              /*!<   6  Usage Fault, i.e. Undef Instruction, Illegal State Transition    */
  SVCall_IRQn                   =  -5,              /*!<  11  System Service Call via SVC instruction                          */
  DebugMonitor_IRQn             =  -4,              /*!<  12  Debug Monitor                                                    */
  PendSV_IRQn                   =  -2,              /*!<  14  Pendable request for system service                              */
  SysTick_IRQn                  =  -1,              /*!<  15  System Tick Timer                                                */
/* ---------------------  nrf52840 Specific Interrupt Numbers  -------------------- */
  POWER_CLOCK_IRQn              =   0,              /*!<   0  POWER_CLOCK                                                      */
  RADIO_IRQn                    =   1,              /*!<   1  RADIO                                                            */
  UARTE0_UART0_IRQn             =   2,              /*!<   2  UARTE0_UART0                                                     */
  SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn=   3,      /*!<   3  SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0                                */
  SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn=   4,      /*!<   4  SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1                                */
  NFCT_IRQn                     =   5,              /*!<   5  NFCT                                                             */
  GPIOTE_IRQn                   =   6,              /*!<   6  GPIOTE                                                           */
  SAADC_IRQn                    =   7,              /*!<   7  SAADC                                                            */
  TIMER0_IRQn                   =   8,              /*!<   8  TIMER0                                                           */
  TIMER1_IRQn                   =   9,              /*!<   9  TIMER1                                                           */
  TIMER2_IRQn                   =  10,              /*!<  10  TIMER2                                                           */
  RTC0_IRQn                     =  11,              /*!<  11  RTC0                                                             */
  TEMP_IRQn                     =  12,              /*!<  12  TEMP                                                             */
  RNG_IRQn                      =  13,              /*!<  13  RNG                                                              */
  ECB_IRQn                      =  14,              /*!<  14  ECB                                                              */
  CCM_AAR_IRQn                  =  15,              /*!<  15  CCM_AAR                                                          */
  WDT_IRQn                      =  16,              /*!<  16  WDT                                                              */
  RTC1_IRQn                     =  17,              /*!<  17  RTC1                                                             */
  QDEC_IRQn                     =  18,              /*!<  18  QDEC                                                             */
  COMP_LPCOMP_IRQn              =  19,              /*!<  19  COMP_LPCOMP                                                      */
  SWI0_EGU0_IRQn                =  20,              /*!<  20  SWI0_EGU0                                                        */
  SWI1_EGU1_IRQn                =  21,              /*!<  21  SWI1_EGU1                                                        */
  SWI2_EGU2_IRQn                =  22,              /*!<  22  SWI2_EGU2                                                        */
  SWI3_EGU3_IRQn                =  23,              /*!<  23  SWI3_EGU3                                                        */
  SWI4_EGU4_IRQn                =  24,              /*!<  24  SWI4_EGU4                                                        */
  SWI5_EGU5_IRQn                =  25,              /*!<  25  SWI5_EGU5                                                        */
  TIMER3_IRQn                   =  26,              /*!<  26  TIMER3                                                           */
  TIMER4_IRQn                   =  27,              /*!<  27  TIMER4                                                           */
  PWM0_IRQn                     =  28,              /*!<  28  PWM0                                                             */
  PDM_IRQn                      =  29,              /*!<  29  PDM                                                              */
  MWU_IRQn                      =  32,              /*!<  32  MWU                                                              */
  PWM1_IRQn                     =  33,              /*!<  33  PWM1                                                             */
  PWM2_IRQn                     =  34,              /*!<  34  PWM2                                                             */
  SPIM2_SPIS2_SPI2_IRQn         =  35,              /*!<  35  SPIM2_SPIS2_SPI2                                                 */
  RTC2_IRQn                     =  36,              /*!<  36  RTC2                                                             */
  I2S_IRQn                      =  37,              /*!<  37  I2S                                                              */
  FPU_IRQn                      =  38,              /*!<  38  FPU                                                              */
  USBD_IRQn                     =  39,              /*!<  39  USBD                                                             */
  UARTE1_IRQn                   =  40,              /*!<  40  UARTE1                                                           */
  QSPI_IRQn                     =  41,              /*!<  41  QSPI                                                             */
  CRYPTOCELL_IRQn               =  42,              /*!<  42  CRYPTOCELL                                                       */
  PWM3_IRQn                     =  45,              /*!<  45  PWM3                                                             */
  SPIM3_IRQn                    =  47               /*!<  47  SPIM3                                                            */
} IRQn_Type;

UPDATE:

Using the code following forum with slight modifications, I was able to have the desired behavior for my voltmeter setup without the freezing behavior.

This code is both tested on Arduino Nano 33 BLE, and Arduino Nano 33 BLE Sense.

That's great. I'm glad the forum post was helpful.

1 Like