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

unexpected sd_app_evt_wait() returning

Hello,

I have a BLE application, running a GATT server on a nrf52832. The main loop, is basically an endless loop, starting with a call to `sd_app_evt_wait()`, then handling events provided by `sd_ble_evt_get()`. I toggle a debug pin at the beginning and the end of the main loops body.

When I connect with a BLE client to the GATT server, the debug pin starts to toggle very quickly, with a period of ~12.5µs. I use a counter to ignore the first 1000 runs through the main loop, after which I insert a break point. No call to `sd_ble_evt_get()` returns any event. Before hitting the breakpoint, I store NVIC->ISPR[0] in a variable. The value of this variable is 1, which indicates, that `sd_app_evt_wait()` returned doe to a pending radio interrupt.
How can I avoid, to have `sd_app_evt_wait()` returning, even when there is no event to handle? How can I further investigate what happens here? (Softdevice in use is S132 Version 6.1.0).
Thanks in advance,
Torsten
  • Hi Torsten

    Before hitting the breakpoint, I store NVIC->ISPR[0] in a variable. The value of this variable is 1

     This is not Radio, but POWER/Clock. You should also check NVIC->ISPR[1] as the nRF52 have more than 32 interrupt sources. I'm guessing there is an interrupt that isn't configured correctly in there that is preventing your application from going to sleep.

    Best regards,

    Simon

  • Hi Simon,

    thank you for having a look into my issue. I've played a little with the static counter, that I use to have the break point a little bit later in time. I've used 50000, 50010 and 55000. `ISPR[0]` is always `0x400000` and `ISPR[1]` is always 0. This would map to `SWI2_EGU2_IRQn`. As far, as I can see, I'm using neither the SWI, nor the EGU peripheral.

    I wonder if there is something wrong with the method, I'm using to track down the interrupt, I'm looking for. This is the head of the body of my main loop:

    unset_pin( debug_pin );
                sd_app_evt_wait();
        set_pin( debug_pin );
    
        std::uint32_t pending0 = NVIC->ISPR[ 0 ];
        std::uint32_t pending1 = NVIC->ISPR[ 1 ];
        (void)pending0;
        (void)pending1;
        static int i = 55000;
        --i;
        if ( i == 0 )
            for ( volatile int f = 0; f != 100; ++ f )
                ;
    

    I'm setting the breakpoint at the body of the for loop. As I see that my collected client is interacting with the GATT server, I'm pretty sure, that delaying the break point works.

    kind regards,

    Torsten

  • This is strange. Do you experience this on a DK or a custom board, and what SDK version are you using? During research I found this post, which suggests removing the softdevice_handler.c file from the project when you encounter this error. Could you try that?

    Best regards,

    Simon

  • I'm on a DK (PCA10040 V0.9.0), with some GPIOs and mainly SPIs and Timers in use. From the SDK, only system_nrf52.c, gcc_startup_nrf52.S and the softdevice is in use. SDK Version is 15.2.0_9412b96.

  • Hi Torsten

    I've checked this out with my colleagues, and we would like you to check NVIC->ISER registers as we suspect SWI2 is enabled somewhere, which causes the SWI2_EGU2_IRQn. 

    Another solution would be that the application is trying to go to sleep somewhere else than the main.c file. Can you confirm whether or not you are calling a sleep function somewhere else?

    Best regards,

    Simon

Related