2023-08-09 02:42 AM - edited 2023-08-09 02:42 AM
Hi everyone.
I'm currently testing low power modes in ThreadX on a NUCLEO-F767ZI board using CubeMX and CubeIDE (current versions).
ThreadX tick period is set to 1 ms, and low power is enabled. What happens is that the scheduler awakes every millisecond even if HAL_SuspendTick() is called (seems because ThreadX SysTick_Handler remains active).
Shouldn't the scheduler be suspended for some milliseconds until next timer should be ready to run (or an interrupt would fire)? If this is correct a timeout timer seems to be not necessary. Is this due to the faster ThreadX tick?
This is the partial code:
void App_ThreadX_LowPower_Enter(void)
{
/* USER CODE BEGIN App_ThreadX_LowPower_Enter */
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
/* USER CODE END App_ThreadX_LowPower_Enter */
}
void App_ThreadX_LowPower_Exit(void)
{
/* USER CODE BEGIN App_ThreadX_LowPower_Exit */
HAL_ResumeTick();
/* USER CODE END App_ThreadX_LowPower_Exit */
}
ULONG App_ThreadX_TimerAdjust(void)
{
/* USER CODE BEGIN App_ThreadX_TimerAdjust */
uint32_t tmp1;
tmp1 = __HAL_TIM_GET_COUNTER(&htim13);
HAL_TIM_Base_Stop(&htim13);
// Convert to system ticks, always returns 0 as timer is stopped in 1 ms
return tmp1 / 1000;
/* USER CODE END App_ThreadX_TimerAdjust */
}
void App_ThreadX_Timer_Setup(ULONG count)
{
/* USER CODE BEGIN App_ThreadX_Timer_Setup */
uint16_t timeout;
timeout = (count * 1000 / TX_TIMER_TICKS_PER_SECOND);
__HAL_TIM_SET_COUNTER(&htim13, 0);
htim13.Instance->ARR = timeout * 1000 - 1;
if (HAL_TIM_Base_Start(&htim13) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END App_ThreadX_Timer_Setup */
}
Also, in order to reduce power consumption in sleep mode, is it correct to call __HAL_RCC_xxx_CLK_SLEEP_DISABLE once for the peripherals not needed in sleep mode?
Thank you for your comments.
2024-06-11 03:20 PM
@paolog Did you ever get an answer to this? I have the same questions on a STM32U5 project.
2024-06-12 12:14 AM
@rdot unfortunately not. So I decided to abandon ThreadX as no support is available. I moved to FreeRTOS (considering adopting SafeRTOS at a later project stage) as there's a lot more information available, as well examples.