cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS LowPower : adjust tickcount after wakeup

malarab
Senior II

Hello,

i configured FreeRTOS to enter STOP2 mode on idle task,

my wakup source are RTC and LPUART.

when the mcu is waked up by RTC according to ulExpectedIdleTime, every think is ok

but when it is waked up by the LPUART the tick count is not updated correctly (so all my software timers are not executed with the right period)

it should be an implementation on PostSleepProcessing() to modify the value of ulExpectedIdleTime according to RTC counter, but i cannot find how to do it !

any body have an idea ? where i can find the RTC counter for wakeup timer (i already checked all RTC register, i assume that it exist, but i cannot find it)

 

void PreSleepProcessing(uint32_t *ulExpectedIdleTime)
{
//LPUART :
//make sure that no LPUART transfer is on-going
while (__HAL_UART_GET_FLAG(&hlpuart1, USART_ISR_BUSY) == SET);
//make sure that LPUART is ready to receive
while (__HAL_UART_GET_FLAG(&hlpuart1, USART_ISR_REACK) == RESET);
//set the wake-up event:specify wake-up on RXNE flag
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY;
if (HAL_UARTEx_StopModeWakeUpSourceConfig(&hlpuart1, WakeUpSelection) != HAL_OK)
{
  Error_Handler();
}
//Enable the UART Wake UP from STOP mode Interrupt
__HAL_UART_ENABLE_IT(&hlpuart1, UART_IT_WUF);
//enable MCU wake-up by LPUART
HAL_UARTEx_EnableStopMode(&hlpuart1);

//RTC :
//## Setting the Wake up time ############################################
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 2*(*ulExpectedIdleTime), RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0) != HAL_OK)
{
  Error_Handler();
}
//Suspend systick
HAL_SuspendTick();
}

void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
{
    //Resume systick
    HAL_ResumeTick();

//Disable all used wakeup sources
//LPUART :
    HAL_UARTEx_DisableStopMode(&hlpuart1);

//RTC :
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
//Clear all related wakeup flags
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

 

Thank you :)

1 ACCEPTED SOLUTION

Accepted Solutions
Sarra.S
ST Employee

Hello @malarab

Indeed, when waking up from STOP2 mode due to an RTC interrupt, the tick count is typically updated based on the elapsed time calculated from the RTC's wake-up timer value.

However, when waking up due to an LPUART interrupt, you need to manually calculate the elapsed time and update the tick count accordingly.

You can Update the tick count by calling vTaskStepTick() with the number of ticks that correspond to the elapsed time (Read the RTC's current counter or timestamp value and calculate the elapsed time since the microcontroller entered STOP2 mode).

 

Hope that's clear!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Sarra.S
ST Employee

Hello @malarab

Indeed, when waking up from STOP2 mode due to an RTC interrupt, the tick count is typically updated based on the elapsed time calculated from the RTC's wake-up timer value.

However, when waking up due to an LPUART interrupt, you need to manually calculate the elapsed time and update the tick count accordingly.

You can Update the tick count by calling vTaskStepTick() with the number of ticks that correspond to the elapsed time (Read the RTC's current counter or timestamp value and calculate the elapsed time since the microcontroller entered STOP2 mode).

 

Hope that's clear!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.