我将我的 L4R5ZI 芯片设置为 Stop2 模式,但不幸的是,它似乎不想从用户按钮唤醒。根据数据表,唤醒源包括:
复位引脚,
所有 I/O
BOR、PVD、PVM
RTC, IWDG
COMPx (x=1..2)
I2C3(7)
LPUART1(6)
LP
tiM1
我已将用户按钮 (PC13) 设置为上升沿的外部中断,并使用同一按钮使其进入低功耗模式。我的代码如下所示:
- static void MX_GPIO_Init(void)
- {
- /* Other GPIO setup here */
- /*Configure GPIO pin : B1_Pin */
- GPIO_InitStruct.Pin = B1_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
- /* Other GPIO setup here */
- }
- void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
- {
- if(GPIO_Pin == B1_Pin)
- {
- while(HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin) == GPIO_PIN_SET)
- {
- }
- if(lowpowermode == true)
- {
- lowpowermode = false;
- //ExitLowPowerMode();
- }
- else
- {
- lowpowermode = true;
- //EnterLowPowerMode();
- Run_Stop_Mode();
- //Enter_LowPower_Mode();
- }
- //HAL_GPIO_TogglePin(GPIOB, LD3_Pin);
- }
- }
- void EnterLowPowerMode()
- {
- HAL_TIM_Base_Stop_IT(&htim2);
- HAL_ADC_Stop_DMA(&hadc1);
- HAL_SPI_DeInit(&hspi1);
- __HAL_RCC_SPI1_CLK_DISABLE();
- //__HAL_RCC_GPIOC_CLK_DISABLE();
- __HAL_RCC_GPIOH_CLK_DISABLE();
- __HAL_RCC_GPIOA_CLK_DISABLE();
- __HAL_RCC_GPIOB_CLK_DISABLE();
- __HAL_RCC_GPIOD_CLK_DISABLE();
- __HAL_RCC_GPIOG_CLK_DISABLE();
- }
- void ExitLowPowerMode()
- {
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
- __HAL_RCC_GPIOG_CLK_ENABLE();
- __HAL_RCC_SPI1_CLK_ENABLE();
- HAL_SPI_Init(&hspi1);
- HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADC_Value, 1);
- HAL_TIM_Base_Start_IT(&htim2);
- }
- void Run_Stop_Mode()
- {
- EnterLowPowerMode();
- // Suspend the Ticks before entering the STOP mode or else this can wake the device up
- HAL_SuspendTick();
- // Enter Stop Mode
- HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
- SystemClock_Config();
- HAL_ResumeTick();
- ExitLowPowerMode();
- }
我错过了什么明显的东西吗?我是否需要专门设置该引脚以启用中断?我看过其他几个例子,但没有看到任何具体的设置。也许我找错地方了?
我想我可能非常接近,但我显然错过了一些东西。您能给我的任何帮助将不胜感激。谢谢!