This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-EM-CC2340R5: RTS Timer: Waking up from standby by RTC timer

Part Number: LP-EM-CC2340R5
Other Parts Discussed in Thread: CC2340R5, SYSCONFIG

Tool/software:

Good afternoon,
I use cc2340r5 and simplelink_lowpower_f3_sdk_8_10_01_02 .
My program is based on basic_ble with some logical modifications. So now, after a certain time, I stop scanning the network, turn off all the peripherals and, according to the power policy, switch to Standby mode (which can be seen through the energy trace).
Now let's move on to the main question, can I create an RTC timer and use it to bring the device out of Standby mode?

And if it is possible, are there examples of setting the RTC timer somewhere?

Regards, Vadim.

 

  • Hello Vadim,

    I hope you are doing well. We can leverage the ClockP module for a low-power timer solution here! 

    Alternatively we have some older posts that implement similar solutions:

    https://e2e.ti.com/f/1/t/1234806/ (RTC alarm)

    https://e2e.ti.com/f/1/t/1327187/ (How to config to Standby mode and wakeup from RTC in Basic BLE Application)

    Thanks,
    Alex F

     

  • Hello Alex.

    I tried using ClockP to exit Standby mode. But it did not work, the timer was not called. If I understood the documentation correctly, in FreeRTOS this timer works as a service timer with priority.

    "With FreeRTOS, the ClockP functions are either run by a timer service task with priority configured by the application, or in hardware interrupt directly, depending on the device platform."


    One discussion mentioned LGPTimer, but it can't be done with Standby mode because the timer blocks that mode

    Fullscreen
    1
    2
    /* Set constraint to disallow standby while running */
    Power_setConstraint(PowerLPF3_DISALLOW_STANDBY);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



    So one correct option would be to record HWREG and interrupts as shown in the drivers/systimtimestamp example?

  • UPD.  I tried configuring SYSTIM , but that didn't work either. Maybe I'm doing something wrong.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #define SYSTIM_PERIOD_MS 2000
    #define SYSTIM_FREQ 32768 // Frequency 32.768 kHz for timer SYSTIM
    HwiP_Struct systimHwi;
    // Interrupt handler for SYSTIM
    void systimInterruptHandler(uintptr_t arg) {
    // Check if the interrupt from channel 0 worked
    if (HWREG(SYSTIM_BASE + SYSTIM_O_OUT) & SYSTIM_OUT_OUT0) {
    // Clear the interrupt
    HWREG(SYSTIM_BASE + SYSTIM_O_OUT) |= SYSTIM_OUT_OUT0; // Clear the event
    // Timer has expired, executing your code
    // For example, stopping a timer
    HWREG(SYSTIM_BASE + SYSTIM_O_CH0CFG) &= ~(1 << 1); // Disable the timer
    GPIO_toggle(CONFIG_GPIO_LED_RED);
    }
    }
    void systimTimerInit(void) {
    uint32_t timer_value =
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • UPD.
    About ClockP, I saw a strange result, it didn't come out of sleep after the scheduled time, but much later it did, and here I don't quite understand what caused it. Perhaps the time was not calculated correctly, and perhaps it was not the timer that woke him up at all.

  • UPD.

    So I'm sure that the device didn't wake up because of the timer, because I didn't get into the callBack function of the timer. 
    After about 20 minutes the wake up LED lights up as indicated in my PowerLPF3_AWAKE_STANDBY event handler. But there are other operations there, and I have not seen their implementation, I will conduct additional checks

  • UPD. 
    I also tried to implement the timer on the RTC, but still it seems to me that I made a mistake in its implementation.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #define RTC_PERIOD_MS 3000
    #define RTC_FREQ 32768 // Frequency 32.768 kHz for timer SYSTIM
    HwiP_Struct rtcHwi;
    void rtcInterruptHandler(uintptr_t arg) {
    if (HWREG(RTC_BASE + RTC_O_RIS) & RTC_RIS_EV0) {
    HWREG(RTC_BASE + RTC_O_ICLR) |= RTC_RIS_EV0;
    GPIO_toggle(CONFIG_GPIO_LED_GREEN);
    HWREG(RTC_BASE + RTC_O_CTL) |= RTC_CTL_RST;
    }
    }
    void rtcInit(void) {
    uint32_t rtc_interval = RTC_PERIOD_MS * (RTC_FREQ / 1000);
    HWREG(RTC_BASE + RTC_O_CH0CC8U) = rtc_interval;
    HWREG(RTC_BASE + RTC_O_IMASK) |= RTC_RIS_EV0;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hello Vadim,

    As you said, it looks like SYSTIM won't work "SYSTIM follows the RTC (Chapter 12) and can only be used in device active state" in this case. 

    A thread about wakeup from standby with GPIO: https://e2e.ti.com/f/1/t/1322974/

    A RTC code snippet from the following thread about RTC https://e2e.ti.com/f/1/t/1353182/

    Thanks,
    Alex F

  • Hello Alex,

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #define RTC_PERIOD_MS 3000
    #define RTC_FREQ 31250 // 31.25 kHz
    HwiP_Struct rtcHwi;
    void rtcInterruptHandler(uintptr_t arg) {
    if (HWREG(RTC_BASE + RTC_O_RIS) & RTC_RIS_EV0) {
    HWREG(RTC_BASE + RTC_O_ICLR) |= RTC_RIS_EV0;
    GPIO_toggle(CONFIG_GPIO_LED_GREEN);
    HWREG(RTC_BASE + RTC_O_CTL) |= RTC_CTL_RST;
    }
    }
    void rtcInit(void) {
    uint32_t rtc_interval = RTC_PERIOD_MS * (RTC_FREQ / 1000);
    HWREG(RTC_BASE + RTC_O_CH0CC8U) = rtc_interval;
    HWREG(RTC_BASE + RTC_O_IMASK) |= RTC_RIS_EV0;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



    This option works for me if I understand correctly.


    I have only one question, am I counting the period correctly?

    I took the frequency from sysconfig:




    Thanks,
    Vadim F

  • Hello Vadim,

    The frequency should be (*unless supplied externally, then it needs to be 31.25 kHz) 

      

    Thanks,
    Alex F

  • Hello Alex,

    Thanks for the answer, now i use 31.25 kHz

    Vadim F