You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.1 KiB
104 lines
3.1 KiB
/*
|
|
* @Author: sunlight 2524828700@qq.com
|
|
* @Date: 2024-09-13 21:25:41
|
|
* @LastEditors: sunlight 2524828700@qq.com
|
|
* @LastEditTime: 2024-09-19 14:02:17
|
|
* @FilePath: \auxiliary_addition\Usr\power\pwr.c
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
*/
|
|
|
|
#include "pwr.h"
|
|
|
|
#include "stm32f4xx_hal.h"
|
|
#include "zgpio.h"
|
|
|
|
/**
|
|
* @description:停止模式恢复正常HSE时钟
|
|
* @return {*}
|
|
*/
|
|
static void SystemConfig_Recover(void) {
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
|
|
/** Configure the main internal regulator output voltage
|
|
*/
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
RCC_OscInitStruct.PLL.PLLQ = 4;
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Initializes the CPU, AHB and APB buses clocks
|
|
*/
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @description: SleepMode Enter and Wakeup
|
|
* @return {*}
|
|
*/
|
|
void Power_SleepMode(void) {
|
|
HAL_SuspendTick(); // 暂停滴答时钟,防止通过滴答时钟中断唤醒
|
|
// printf("enter sleep");
|
|
DebugLight_OFF;
|
|
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFE); // 进入正常睡眠模式,中断唤醒
|
|
// printf("enter sleep");
|
|
HAL_ResumeTick(); // 被唤醒后,恢复滴答时钟
|
|
DebugLight_ON;
|
|
}
|
|
|
|
/**
|
|
* @description: StopMode Enter and Wakeup
|
|
* @return {*}
|
|
*/
|
|
void Power_StopMode(void) {
|
|
#if FLASH_PowerDown
|
|
HAL_PWREx_EnableFlashPowerDown(); // 掉电进一步降低功耗
|
|
#else
|
|
HAL_PWREx_DisableFlashPowerDown(); // 正常供电
|
|
#endif
|
|
DebugLight_OFF;
|
|
HAL_SuspendTick(); // 暂停时钟
|
|
HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); // 进入停止模式,中断唤醒
|
|
|
|
SystemConfig_Recover(); // 恢复HES时钟和PLL设置
|
|
HAL_ResumeTick(); // 恢复时钟
|
|
DebugLight_ON;
|
|
}
|
|
|
|
/**
|
|
* @description: StandbyMode Enter and Wakeup
|
|
* @return {*}
|
|
*/
|
|
void Power_StandByMode(void) {
|
|
// 检测复位来源
|
|
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB)) {
|
|
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); // 清除复位标志
|
|
}
|
|
|
|
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // 清除WU标志
|
|
#if WKUP
|
|
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // 使能WKUP引脚唤醒
|
|
#endif
|
|
DebugLight_OFF;
|
|
HAL_PWR_EnterSTANDBYMode(); // 进入待机模式
|
|
}
|
|
|
|
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) {}
|