Skip to main content
Associate II
December 4, 2025
Solved

STM32U073CCT6 and using LPTIM to wake up the CPU from STOPMODE2

  • December 4, 2025
  • 2 replies
  • 639 views

Hi

I'm trying to use an LP TIM to generate an interrupt after a time interval on an STM32U073CCT6. The interrupt will wake the processor from STOPMODE2.
I haven't found any examples, and the STM32CUBE MX doesn't have a software-triggered single-shot option. The LPTM1 clock is LSI.

Can you help me with this application?

BR

Gilberto

 

Best answer by Gyessine

hello @gilberto-falker 
Can you implement the following code in your project?
If everything is implemented correctly, the STM32 enters stop 2 mode after one second and wakes up from it after another second. The PA5 pin will be set to verify the operation. You can use the USERLED for visual verification.
Cube MX configuration:

Gyessine_1-1765189001255.png

Gyessine_0-1765188944868.png

 

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_LPTIM1_Init();

 HAL_NVIC_SetPriority(TIM6_DAC_LPTIM1_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(TIM6_DAC_LPTIM1_IRQn);

 HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 3999);
 HAL_Delay(1000);
 HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

 SystemClock_Config();

 while (1)
 {


 }
}

 

static void MX_LPTIM1_Init(void)
{
 hlptim1.Instance = LPTIM1;
 hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
 hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV16;
 hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_0;
 hlptim1.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_RISING;
 hlptim1.Init.Trigger.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION;
 hlptim1.Init.Period = 3999;
 hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
 hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
 hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
 hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
 hlptim1.Init.RepetitionCounter = 0;
 if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
 {
 Error_Handler();
 }
}

static void MX_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};

 __HAL_RCC_GPIOC_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

 GPIO_InitStruct.Pin = GPIO_PIN_5;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}

void TIM6_DAC_LPTIM1_IRQHandler(void)
{
 HAL_LPTIM_IRQHandler(&hlptim1);
}

void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
{
 if (hlptim->Instance == LPTIM1)
 {
 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
 }
}

Hope that helps!
Gyessine
 

2 replies

GyessineBest answer
Technical Moderator
December 8, 2025

hello @gilberto-falker 
Can you implement the following code in your project?
If everything is implemented correctly, the STM32 enters stop 2 mode after one second and wakes up from it after another second. The PA5 pin will be set to verify the operation. You can use the USERLED for visual verification.
Cube MX configuration:

Gyessine_1-1765189001255.png

Gyessine_0-1765188944868.png

 

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_LPTIM1_Init();

 HAL_NVIC_SetPriority(TIM6_DAC_LPTIM1_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(TIM6_DAC_LPTIM1_IRQn);

 HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 3999);
 HAL_Delay(1000);
 HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

 SystemClock_Config();

 while (1)
 {


 }
}

 

static void MX_LPTIM1_Init(void)
{
 hlptim1.Instance = LPTIM1;
 hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
 hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV16;
 hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_0;
 hlptim1.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_RISING;
 hlptim1.Init.Trigger.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION;
 hlptim1.Init.Period = 3999;
 hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
 hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
 hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
 hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
 hlptim1.Init.RepetitionCounter = 0;
 if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
 {
 Error_Handler();
 }
}

static void MX_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};

 __HAL_RCC_GPIOC_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

 GPIO_InitStruct.Pin = GPIO_PIN_5;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}

void TIM6_DAC_LPTIM1_IRQHandler(void)
{
 HAL_LPTIM_IRQHandler(&hlptim1);
}

void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
{
 if (hlptim->Instance == LPTIM1)
 {
 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
 }
}

Hope that helps!
Gyessine
 

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.
Associate II
December 8, 2025

Hi

It solved the problem.

BR

Gilberto