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

application fails to wake up from sleep

Before starting advertising, we want to write some configuration information to NVM. In order to write to NVM, we first call sd_flash_page_erase and wait for the response from the softDevice. While waiting, we call sd_app_evt_wait. We expect to receive the SWI2 interrupt indicating that the erase is complete.

On most of our boards, this happens correctly, within ~50ms, and we have no subsequent problem. However, on some boards the SWI2 interrupt doesn’t fire until after the NRF is woken up by an external interrupt from a different processor, several seconds later. Our conclusion is that we are asleep (NRF_POWER_MODE_LOWPWR). We know we have interrupts configured correctly because it works fine on some boards, so how could we be stuck in sleep?

In debugging this issue, we also noticed that the RTC1 interrupt stops firing during the time the NRF is asleep. We expect the processor to wake up every 125ms and service RTC1, but this interrupt also doesn’t fire until we get an external wakeup from the host processor.

Another confusing element is that we made a seemingly unrelated change that seems to “fix” both problems above. In our initialization sequence, we were calling sd_radio_notification_cfg_set very early on, before writing to NVM. When we moved the call to happen AFTER writing to NVM, the above problems went away. But considering that we’re writing to NVM before starting advertising, I can’t understand how this change would have any effect.

How can radio notifications affect whether the RTC1 interrupt fires or whether the NRF gets stuck in sleep?

  • Hi

    It seems that you have your case resolved by moving your radio notification initialization just before starting advertising, am I correct?

    A flash erase operation takes about 21ms. What is the frequency of your radio events, i.e. what is your connection interval?

    What softdevice are you using, type and version?

  • Tags: nrf51822, s110, softdevice 6.0.0.

    This whole problem happens during our startup process before we start advertising (sd_ble_gap_adv_start). We are not confident that our fix truly resolves the issue, or just masks it.

    We don't start advertising until the flash erase/write is complete (in the code both before and after the "fix"). Now we've moved radio notification initialization to a point later in the process, but it is also before we start advertising. I don't expect that sd_radio_notification_cfg_set should cause any radio activity if we haven't yet turned on advertising, correct? So it’s hard to see how it can affect writes to NVM, and it's hard to be convinced that our fix is really a fix.

  • Hi

    It is not a behavior that is expected or that we recognize immediately. I have tried to reproduce the issue with the description that you have provided, but without luck. I attach my test code. Perhaps you can run my test code on the devices in question on your side to see if you can produce the issue with it.

    ble_app_template_with_flash_erase_operation.zip

    Have you set priority low for the radio notifications?
    What is your advertising interval?
    Do you get any error code when you call the sd_flash_page_erase operation?
    What flash page are you erasing?

    • radio notification priority is high: sd_nvic_SetPriority(SWI1_IRQn, NRF_APP_PRIORITY_HIGH);
    • The advertising interval for the first couple minutes is 20ms, but we are not advertising when this bug happens. So I really don’t think the interval should be relevant.
    • We do not get any error code from the call to sd_flash_page_erase.
    • We are erasing page: 252 (then we will write that page with some configuration data)

    I will try to figure out a way to run your project on my board. It won't be trivial, but hopefully by tomorrow.

    Thanks

Related