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

gpiote interrupt cannot wake sd_app_evt_wait?

I have tried to use sd_app_evt_wait() to sleep cpu, and use gpiote interrupt to wake up cpu from sleep. However, gpiote interrupt cannot wake up cpu. When I use __WFE(), gpiote interrupt can wake up cpu. And even if I use sd_app_evt_wait(), log print using Segger RTT seems to wake up cpu however log print place is after sleep loop. This is very strange.

Would you explain this phenomenon?

code is like below.

static void sf_gpiote_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
     _print_info("gpiote interrupt\r\n");
     s_is_resp_ready = true;
}


static void sf_wait_resp()
{
     while(!s_is_resp_ready)
     {
        __WFE();
        // sd_app_evt_wait();
     }
     s_is_resp_ready = false;

    //_print_info("resp_ready\r\n");
}
Parents
  • You forgot the C optimizer:

    volatile int s_is_resp_ready;
    

    Without the volatile, the optimizer will replace the

    while(!s_is_resp_ready)
    

    with an unconditional loop. Look at the disassembly if you can.

  • I tried volatile, and it works well!! Still it is strange why __WFE() works well without volatile. I cannot understand compiler behavior. Can you explain? Anyway, thank you for your answer!

Reply
  • I tried volatile, and it works well!! Still it is strange why __WFE() works well without volatile. I cannot understand compiler behavior. Can you explain? Anyway, thank you for your answer!

Children
No Data