This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

[NRF52 SD] sd_app_evt_wait wont sleep after BLE connection

To the wizards at Nordic,

I come to you with a rather perplexing issue, we are building a custom application on top of our nrf52 based design. The board seems to work great with all peripherals, and the SD behaving as expected. However we run into an issue where after a successful BLE connection, all future calls to sd_app_evt_wait() return immediately and do not let the CPU get to sleep.

At first I read about the possibility of a FPU exception preventing the sd from going to sleep due to the FPU_IRQn being pending. However, we later verified that the pending IRQn is actually the EGU2/SWI2/SoftDevice Event peripheral (IRQn == 22). We are currently using the 1.0.2 version of the S332 SD, but the same issue was observed in the 0.9.x version of the SD as well.

Looking over the softdevice specification it seems clear that the SWI2 peripheral is reserved for SoftDevice Event Notifications, but I am puzzled as to why the SD is not handling this interrupt. Furthermore, when I try to clear this using the sd_nvic_ClearPendingIRQ(..) it succeeds (which according to the documentation should fail since the SD is enabled), and then proceeds to hang the softdevice.

This is odd to us as we expect the SD to handle these events as per my understanding the app is not supposed to worry itself w/ the SWI2 events / interrupts. This is causing our device to consume 100% power right after a connection is successfully made. Before the connection is made - the app seems to be operating as expected.

As a side note - we are not using the provided connection manager, advertising and security modules. The only sd_ble... calls we use are as follows:

sd_ble_gap_adv_data_set
sd_ble_gap_adv_start
sd_ble_gap_adv_stop
sd_ble_gap_device_name_set
sd_ble_gap_ppcp_set
sd_ble_enable
sd_ble_evt_get

Advise / pointers would be awesome! Thank you!

EDIT1: After RK pointed out that the SWI2 event is for the app to consume FROM the SD, I started poking around at how this is normally handled. If you are using the softdevice_handler module, then this will (sneakily) setup a default SWI2 IRQ Handler. Whats more interesting (and undocumented) is the fact that the handler only needs to be defined (can be empty), for the pending interrupt to get cleared. So all I needed was to do the following:

  1. Enable SWI2_IRQn after the SD has been enabled.
  2. Create an empty SWI2 IRQ handler since my app's loop handles fetching events from BLE, ANT and the SOC.

Thanks for all the help - marking this closed!

-Shaba

Parents
  • Now that you put it that way, I think I understand what might be afoot. There is probably a security param update or the like that I am not responding to which is putting the system into an odd state. I expected those to show up when I call sd_ble_evt_get(). Is there a documented place which lists what reasons might cause SWI2 to need handling? Thanks for the quick reply RK! I will report back with any findings.

Reply
  • Now that you put it that way, I think I understand what might be afoot. There is probably a security param update or the like that I am not responding to which is putting the system into an odd state. I expected those to show up when I call sd_ble_evt_get(). Is there a documented place which lists what reasons might cause SWI2 to need handling? Thanks for the quick reply RK! I will report back with any findings.

Children
No Data
Related