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

SoftDevice does 26ms of work inside first call to sd_app_evt_wait()

nRF52832_XXAA, S132 v5.0.1, SDK 14.0.0

We enable SoftDevice via nrf_sdh_enable_request(). We immediately assert nrf_sdh_is_enabled() so we know it worked. On the first call to sd_app_evt_wait() we see SoftDevice take control of the CPU for 26ms. We have not started advertising or done any BLE work, the device is silent.

In certain boot conditions, this is fine and we don't care, SD can do what it wants. In other boot conditions, this 26ms work happens while we're doing open-loop battery measurement and powering the device off of a tiny capacitor. SD's mystery work immediately overwhelms this cap and the measurement aborts.

The code looks almost exactly like this:

nrf_sdh_enable_request();
volatile bool done = false;
while (!done) {
  sd_app_evt_wait();
}

Questions:

1. What is SD doing?

2. How do we know when SD will do work when we sleep?

3. Is there any API for us to test that SD is done with whatever its 26msec work is?

4. Will this work ever take more or less time than 26msec?

We need to know when it's safe to sleep for 125msec with no SD activity, or we can't boot correctly.

(Note that we used to enable SD after doing all of this work, but that led to a race when initializing the LFCLK so we enable SD very early now).

Parents
  • The image on the top-left is from a DC power analyzer on the nRF52 1v8 rail, and the 4-channel scope shot shows the battery current in green. Each demarcation is 10ms, so x2-x1 is ~26.

    If we do this instead:

    volatile bool done = false;
    while (!done) {
      __WFE();
    }
    nrf_sdh_enable_request();
    

    Changing the sd_app_evt_wait() to a __WFE() because we haven't started SD yet, and of course never hit the nrf_sdh_enable_request, the power analyzer and scope shots are totally flat.

Reply
  • The image on the top-left is from a DC power analyzer on the nRF52 1v8 rail, and the 4-channel scope shot shows the battery current in green. Each demarcation is 10ms, so x2-x1 is ~26.

    If we do this instead:

    volatile bool done = false;
    while (!done) {
      __WFE();
    }
    nrf_sdh_enable_request();
    

    Changing the sd_app_evt_wait() to a __WFE() because we haven't started SD yet, and of course never hit the nrf_sdh_enable_request, the power analyzer and scope shots are totally flat.

Children
No Data
Related