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

Is it okay to use __WFE() instead of sd_app_evt_wait() when using the SoftDevice?

It appears that my watchdog timer is running during interrupts that are handled by the SoftDevice and do not cause a return from sd_app_evt_wait. This is described in the answer to this question and means I am sometimes unable to feed the watchdog before it triggers a reset.

I am looking at using WFE instead of sd_app_evt_wait as a solution, but a lot of comments in other questions say to use sd_app_evt_wait when you are using the SoftDevice. It is not clear to me whether this is strictly required or not.

For example, this question's answer says:

It is not recommended to do that. The SD has its own housekeeping to do. sd_app_evt_wait is very reliable. If you do your approach you will just leave a bunch of stuff on that should be asleep.

But he does not give a source for this information.

Furthermore, an answer to this question says:

If I had to guess, I think Nordic has added some internal state-saving and safeties that keep the CPU awake and ready if some timing critical radio operation is about to occur.

A guess that is responded to affirmatively by Stefan Birnir Sverrisson.

I am hoping someone can tell me if I will break something if I decide to use WFE.

I should mention that the particular project that has this watchdog timer issue uses the nRF51 and version 12.3.0 of the SDK.

Parents
  • I don't think using WFE could cause severe issue with the softdevice. The main point of using sd_app_evt_wait () is to avoid wasting energy to continue the loop in main() when the softdevice is handling advertising event or empty connection event. 

    You can use this in your loop:

    __WFE();

    __SEV();
    __WFE();

    But for handling the watch dog, we would suggest you to use a dedicated app timer instead of feeding the dog in main loop. 

Reply
  • I don't think using WFE could cause severe issue with the softdevice. The main point of using sd_app_evt_wait () is to avoid wasting energy to continue the loop in main() when the softdevice is handling advertising event or empty connection event. 

    You can use this in your loop:

    __WFE();

    __SEV();
    __WFE();

    But for handling the watch dog, we would suggest you to use a dedicated app timer instead of feeding the dog in main loop. 

Children
  • Thank you for your response, it is exactly kind of answer I was hoping to get.

    About those three lines of code, I saw something similar in this question. Although it seemed unnecessary at first I think I understand it now: although what I expected was that the event register would be always cleared when returning from __WFE, whatever wakes up the processor will sometimes (but not always?) set the event register which remains set until the next call to WFE. So the purpose of the last two lines is to clear the event register, otherwise I would loop twice instead of once, correct?

Related