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.
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
/* Set constraint to disallow standby while running */ Power_setConstraint(PowerLPF3_DISALLOW_STANDBY);
UPD. I tried configuring SYSTIM , but that didn't work either. Maybe I'm doing something wrong.
#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 = SYSTIM_PERIOD_MS * (SYSTIM_FREQ / 1000); // Conversion to the number of clocks (timer clocks) // Setting the timer period (value in clocks) HWREG(SYSTIM_BASE + SYSTIM_O_CH0CC) = timer_value; // Configuration of the SYSTIM channel to work in countdown mode // Enable channel, timer in countdown mode (Count-down) HWREG(SYSTIM_BASE + SYSTIM_O_CH0CFG) = (SYSTIM_CH0CFG_MODE_CAPT | // Timer mode: Capture SYSTIM_CH0CFG_INP_RISE | // Capture on the rising edge (you can choose FALL or BOTH) SYSTIM_CH0CFG_REARM_DIS | // Disabling continuous capture (One-shot mode) SYSTIM_CH0CFG_RES_US); // 1 µs resolution (can be changed to SYSTIM_CH0CFG_RES_NS for 250 // ns) // Initialize interrupt for SYSTIM channel 0 HwiP_construct(&systimHwi, INT_CPUIRQ0, systimInterruptHandler, NULL); HwiP_enableInterrupt(INT_CPUIRQ0); // Enable interrupt // Start timer HWREG(SYSTIM_BASE + SYSTIM_O_CH0CFG) |= SYSTIM_CH0CFG_MODE_CAPT; // Enable the timer channel to run // Reset timer event HWREG(SYSTIM_BASE + SYSTIM_O_OUT) &= ~SYSTIM_OUT_OUT0; // Clear channel 0 event }
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.
#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; HwiP_construct(&rtcHwi, INT_CPUIRQ0, rtcInterruptHandler, NULL); HwiP_enableInterrupt(INT_CPUIRQ0); HWREG(RTC_BASE + RTC_O_CTL) |= RTC_CTL_RST; HWREG(RTC_BASE + RTC_O_CTL) &= ~RTC_CTL_RST; }
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,
#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; HwiP_construct(&rtcHwi, INT_CPUIRQ0, rtcInterruptHandler, NULL); HwiP_enableInterrupt(INT_CPUIRQ0); HWREG(RTC_BASE + RTC_O_CTL) |= RTC_CTL_RST; HWREG(RTC_BASE + RTC_O_CTL) &= ~RTC_CTL_RST; }
Hello Vadim,
The frequency should be (*unless supplied externally, then it needs to be 31.25 kHz)
Thanks,
Alex F