enabling and wake up from sleep mode (systemoff)?

through RTC i am trying it but it is not happening can  you give any propre example one for the sleep mode enabling and wakening up from the sleep mode.

  • 1: It is the same, apart that k_sleep will also set the timer for you. You can also use k_sleep(K_FOREVER) if you want to just wait for an event. In addition you have k_cpu_idle(), which will also do the same. 

    Note that the device will also enter sleep in k_sem_take(), while it waits for the semaphore to be free. 

    2: It is the same. The OS (Zephyr) will handle the threads for you, and WFE will cause your current thread to go to sleep. If all the threads are in WFE/k_sleep, then the CPU will actually go to idle.

    3: You need to have all threads go to sleep when there is no more work. All of the BLE samples in NCS\nrf\samples\bluetooth does this. Study one of them, e.g. the peripheral_uart, which has two threads (main() and ble_write_thread())

    Best regards,

    Edvin

  • Hello Edvin,

    Thank you for the detailed explanation — it’s clear now.
    So to confirm my understanding:

    • __WFE(), k_sleep(), and k_cpu_idle() will all enter SystemOn-Idle.

    • The main advantage of using k_sleep() is that it integrates with the scheduler and handles wakeup timers.

    • As long as all threads are waiting (sleep/semaphore/etc.), the CPU will automatically go into SystemOn-Idle.

    I’ll go through the Bluetooth samples (like peripheral_uart) as you suggested to see this in practice.

    Best regards,
    Lalith

  • Hi
     
    If it is an battery overrented one then which one you will suggest.

    Best regards 
    Lalith

  • lalith88 said:
    So to confirm my understanding:

    Yes. All of those are correct.

    lalith88 said:
    If it is an battery overrented one then which one you will suggest.

    We don't have any recommendations for 3rd party products. Besides, this will very much depend on your device. How much current your application is drawing, and how long you want the battery to last, decides what capacity you would need. 

    The only thing that comes to mind is that you can look at the BOM for the Thingies that we have, such as the Thingy 53:

    https://www.nordicsemi.com/Products/Development-hardware/Nordic-Thingy-53/Downloads?lang=en#infotabs

    Look for the "Hardware Files", which contains the BOM.

    Best regards,

    Edvin

  • Hello Edvin,

    Sorry for the confusion in my previous question — I wasn’t asking about batteries.
    What I meant was:

    If I want to explicitly put the CPU into SystemOn-Idle, which method is recommended in Zephyr on the nRF5340?

    • Using k_sleep()

    • Using k_cpu_idle()

    • Or calling __WFE() directly

    From your previous reply, I understand they are functionally similar, but I’d like to know which one is considered best practice when writing Zephyr applications (for example, in terms of scheduler integration, power management, and maintainability).

    Best regards,
    Lalith

Related