165 lines
5.0 KiB
C
165 lines
5.0 KiB
C
/**
|
||
******************************************************************
|
||
* @file main.c
|
||
* @author fire
|
||
* @version V1.0
|
||
* @date 2018-xx-xx
|
||
* @brief LPTIM-低功耗定时器PWM输出
|
||
******************************************************************
|
||
* @attention
|
||
*
|
||
* 实验平台:野火 STM32H750开发板
|
||
* 论坛 :http://www.firebbs.cn
|
||
* 淘宝 :http://firestm32.taobao.com
|
||
*
|
||
******************************************************************
|
||
*/
|
||
#include "stm32h7xx.h"
|
||
#include "main.h"
|
||
#include "./lptim/bsp_lptim.h"
|
||
#include "./key/bsp_key.h"
|
||
#include "./delay/core_delay.h"
|
||
#include "./usart/bsp_debug_usart.h"
|
||
#include "./led/bsp_led.h"
|
||
|
||
static HAL_StatusTypeDef LPTIM_ClockEnable(void);
|
||
|
||
//static HAL_StatusTypeDef LSE_ClockEnable(void);
|
||
/**
|
||
* @brief 主函数
|
||
* @param 无
|
||
* @retval 无
|
||
*/
|
||
|
||
int main(void)
|
||
{
|
||
|
||
/* 系统时钟初始化成480MHz */
|
||
SystemClock_Config();
|
||
|
||
/* 默认不配置 MPU,若需要更高性能,当配置 MPU 后,使用
|
||
DMA 时需注意 Cache 与 内存内容一致性的问题,
|
||
具体注意事项请参考配套教程的 MPU 配置相关章节 */
|
||
// Board_MPU_Config(0, MPU_Normal_WT, 0xD0000000, MPU_32MB);
|
||
// Board_MPU_Config(1, MPU_Normal_WT, 0x24000000, MPU_512KB);
|
||
|
||
SCB_EnableICache(); // 使能指令 Cache
|
||
// SCB_EnableDCache(); // 使能数据 Cache
|
||
LED_GPIO_Config();
|
||
/* 初始化低速时钟为32.768KHz */
|
||
LPTIM_ClockEnable();
|
||
/* 初始化按键GPIO */
|
||
Key_GPIO_Config();
|
||
/* 串口初始化 */
|
||
DEBUG_USART_Config();
|
||
|
||
printf("\r\n 按下 KEY1 开始低功耗定时器在低功耗模式输出PWM\r\n");
|
||
|
||
while(1)
|
||
{
|
||
if (Key_Scan(KEY1_GPIO_PORT, KEY1_PIN) == KEY_ON)
|
||
{
|
||
printf("\r\n 开始低功耗定时器在低功耗模式输出PWM\r\n");
|
||
/* 低功耗定时器在低功耗模式输出PWM */
|
||
LED_BLUE;
|
||
LPTIM_PWM_OUT();
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief System Clock 配置
|
||
* system Clock 配置如下:
|
||
* System Clock source = PLL (HSE)
|
||
* SYSCLK(Hz) = 480000000 (CPU Clock)
|
||
* HCLK(Hz) = 240000000 (AXI and AHBs Clock)
|
||
* AHB Prescaler = 2
|
||
* D1 APB3 Prescaler = 2 (APB3 Clock 120MHz)
|
||
* D2 APB1 Prescaler = 2 (APB1 Clock 120MHz)
|
||
* D2 APB2 Prescaler = 2 (APB2 Clock 120MHz)
|
||
* D3 APB4 Prescaler = 2 (APB4 Clock 120MHz)
|
||
* HSE Frequency(Hz) = 25000000
|
||
* PLL_M = 5
|
||
* PLL_N = 192
|
||
* PLL_P = 2
|
||
* PLL_Q = 2
|
||
* PLL_R = 2
|
||
* VDD(V) = 3.3
|
||
* Flash Latency(WS) = 4
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
/**
|
||
* @brief System Clock Configuration
|
||
* @retval None
|
||
*/
|
||
void SystemClock_Config(void)
|
||
{
|
||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||
|
||
/** Supply configuration update enable
|
||
*/
|
||
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
||
/** Configure the main internal regulator output voltage
|
||
*/
|
||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
|
||
|
||
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
|
||
/** Initializes the CPU, AHB and APB busses clocks
|
||
*/
|
||
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 = 5;
|
||
RCC_OscInitStruct.PLL.PLLN = 192;
|
||
RCC_OscInitStruct.PLL.PLLP = 2;
|
||
RCC_OscInitStruct.PLL.PLLQ = 2;
|
||
RCC_OscInitStruct.PLL.PLLR = 2;
|
||
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
||
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
||
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||
{
|
||
}
|
||
/** Initializes the CPU, AHB and APB busses clocks
|
||
*/
|
||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|
||
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
|
||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
||
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
|
||
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
|
||
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
|
||
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
||
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
||
|
||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
||
{
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief 使能外部低速时钟 (LSE)
|
||
* @param 无
|
||
* @retval 初始化状态
|
||
*/
|
||
static HAL_StatusTypeDef LPTIM_ClockEnable(void)
|
||
{
|
||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||
/* 使能LSE时钟 */
|
||
#if (LPTIMx_CLK_Source == LSI)
|
||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
|
||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||
#elif (LPTIMx_CLK_Source == LSE)
|
||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||
#endif
|
||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||
return (HAL_RCC_OscConfig(&RCC_OscInitStruct));
|
||
}
|
||
|
||
/****************************END OF FILE***************************/
|