03复现问题
3.1. 软件配置如下图
3.1.1. LPTIM3 配置如下:
static void MX_LPTIM3_Init(void)
{
/* USER CODE BEGIN LPTIM3_Init 0 */
/* USER CODE END LPTIM3_Init 0 */
/* USER CODE BEGIN LPTIM3_Init 1 */
/* USER CODE END LPTIM3_Init 1 */
hlptim3.Instance = LPTIM3;
hlptim3.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
hlptim3.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
hlptim3.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
hlptim3.Init.Period = 99;
hlptim3.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
hlptim3.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
hlptim3.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
hlptim3.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
hlptim3.Init.RepetitionCounter = 0;
if (HAL_LPTIM_Init(&hlptim3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN LPTIM3_Init 2 */
/* USER CODE END LPTIM3_Init 2 */
}
启动 LPTIM3 :
if (HAL_LPTIM_TimeOut_Start_IT(&hlptim3, TIMEOUT) != HAL_OK)
{
Error_Handler();
}
在主循环中重复进入 STOP2 模式,由 LPTIM3 周期唤醒,这里需要注意一点的是在进入之前需 要先把滴答定时器关掉,否则有可能无法进入 STOP2 模式。
/* Suspend Tick */
HAL_SuspendTick();
/* Enter in Stop mode */
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
3.1.2. 配置电源模式输出引脚
为了方便低功耗调试,STM32U5 提供了电源模式输出 pin 脚用于指示 MCU 所处的低功耗模式,具体引脚分别是 PA5/PA6/PA7。
/*Configure GPIO pin : PA5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_CSLEEP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PA6 */
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_CSTOP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PA7 */
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_SRDSTOP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
▲ 图2. 电源模式输出状态
|