对于LPTIM1,各种中断方式都可以唤醒停机模式,比如PWM中断,超时中断等(含软件触发和外部触发)。
而LPTIM2-LPTIM5的各种中断方式却都无法唤醒停机模式,但不做唤醒使用,也都正常,邪门了,看勘误手册也没有这种bug。
邪门,备份下这个问题吧。
停机模式下使用的LSE或者LSI为LPTIM提供时钟。
LPTIM1软件触发超时中断方式。
程序里面配置了8分频,4秒后唤醒。
LPTIM_HandleTypeDef LptimHandle = {0};
void bsp_InitLPTIM2(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
/* ## - 1 - Enable LPTIM clock ############################################ */
__HAL_RCC_LPTIM1_CLK_ENABLE();
__HAL_RCC_LPTIM2_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF1_LPTIM1;
GPIO_InitStruct.Pin = GPIO_PIN_0;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;
RCC_PeriphCLKInitStruct.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSE;
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
/* ### - 2 - Initialize the LPTIM peripheral ############################## */
LptimHandle.Instance = LPTIM1;
LptimHandle.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV8;
LptimHandle.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
LptimHandle.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
// LptimHandle.Init.Trigger.Source = LPTIM_TRIGSOURCE_0;
// LptimHandle.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_FALLING;
LptimHandle.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
LptimHandle.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
LptimHandle.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
LptimHandle.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
/* Initialize LPTIM peripheral according to the passed parameters */
if (HAL_LPTIM_Init(&LptimHandle) != HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
/* Enable and set LPTIM Interrupt to the highest priority */
HAL_NVIC_SetPriority(LPTIM1_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(LPTIM1_IRQn);
/* ### - 3 - Start counting in interrupt mode ############################# */
if (HAL_LPTIM_TimeOut_Start_IT(&LptimHandle, 32768, 32768/2) != HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
// if (HAL_LPTIM_PWM_Start_IT(&LptimHandle, 32768, 32768/2) != HAL_OK)
// {
// Error_Handler(__FILE__, __LINE__);
// }
/* ### - 4 - Enter in Stop mode ########################################### */
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
SystemClock_Config();
}
void LPTIM1_IRQHandler(void)
{
HAL_LPTIM_IRQHandler(&LptimHandle);
bsp_LedToggle(4);
} |