标签:LLC parameter flag 基本 cpu ble tty struct scale
基本工程采用:基于HAL库的STM32H7工程开发->手动配置基本工程 配置的工程
新建bsp_SystemClockConfig.h和bsp_SystemClockConfig.c文件添加到工程中
bsp_SystemClockConfig.c文件内容如下:
1 #include "bsp_SystemClockConfig.h" 2 3 void SystemClock_Config(void) 4 { 5 RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 6 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 7 8 /** Supply configuration update enable 9 */ 10 HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); 11 /** Configure the main internal regulator output voltage 12 */ 13 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0); 14 15 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} 16 /** Initializes the RCC Oscillators according to the specified parameters 17 * in the RCC_OscInitTypeDef structure.PLL倍频时钟系数,以及系统时钟源的选择,和PLL时钟源的选择 18 */ 19 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 20 RCC_OscInitStruct.HSEState = RCC_HSE_ON; 21 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 22 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 23 RCC_OscInitStruct.PLL.PLLM = 5; 24 RCC_OscInitStruct.PLL.PLLN = 192; 25 RCC_OscInitStruct.PLL.PLLP = 2; 26 RCC_OscInitStruct.PLL.PLLQ = 2; 27 RCC_OscInitStruct.PLL.PLLR = 2; 28 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2; 29 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; 30 RCC_OscInitStruct.PLL.PLLFRACN = 0; 31 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 32 { 33 34 } 35 /** Initializes the CPU, AHB and APB buses clocks 各总线时钟分频因子 36 */ 37 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 38 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 39 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1; 40 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 41 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; 42 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2; 43 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2; 44 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; 45 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2; 46 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2; 47 48 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) 49 { 50 51 } 52 }
bsp_SystemClockConfig.h文件内容如下:
1 #ifndef __BSP_SYSTEMCLOCKCONFIG_H 2 #define __BSP_SYSTEMCLOCKCONFIG_H 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 #include "stm32h7xx_hal.h" 7 8 9 10 11 12 13 14 15 void SystemClock_Config(void); 16 17 #ifdef __cplusplus 18 } 19 #endif 20 21 #endif /* __BSP_SYSTEMCLOCKCONFIG_H */
新建bsp_led.c和bsp_led.h文件
bsp_led.c文件内容如下:
1 #include "bsp_led.h" 2 3 void User_LED_Init(void) 4 { 5 GPIO_InitTypeDef GPIO_InitStruct = {0}; 6 7 /* 使能GPIO时钟 */ 8 __HAL_RCC_GPIOB_CLK_ENABLE(); 9 10 /*设置初始化后的引脚状态 */ 11 HAL_GPIO_WritePin(LED_R_GPIO_Port, LED_R_Pin, GPIO_PIN_RESET); 12 13 /*配置GPIO引脚结构体参数 */ 14 GPIO_InitStruct.Pin = LED_R_Pin; 15 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 16 GPIO_InitStruct.Pull = GPIO_NOPULL; 17 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 18 19 HAL_GPIO_Init(LED_R_GPIO_Port, &GPIO_InitStruct); 20 }
bsp_led.h文件内容如下:
1 #ifndef __BSP_LED_H 2 #define __BSP_LED_H 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 #include "stm32h7xx_hal.h" 7 8 9 #define LED_R_Pin GPIO_PIN_0 10 #define LED_R_GPIO_Port GPIOB 11 12 void User_LED_Init(void); 13 14 15 16 17 18 #ifdef __cplusplus 19 } 20 #endif 21 22 #endif /* __BSP_LED_H */
然后在主函数中添加如下代码:
1 #include "main.h" 2 #include "bsp_SystemClockConfig.h" 3 #include "bsp_led.h" 4 5 int main(void) 6 { 7 //复位所有外设,并设置中断优先组,使能系统时钟 8 HAL_Init(); 9 //配置系统时钟源为外部时钟源 10 SystemClock_Config(); 11 MX_GPIO_Init(); 12 //板级外设初始化 13 User_LED_Init(); 14 while(1) 15 { 16 HAL_GPIO_TogglePin(LED_R_GPIO_Port,LED_R_Pin); 17 HAL_Delay(500); 18 } 19 } 20 void MX_GPIO_Init(void) 21 { 22 /* GPIO Ports Clock Enable 外部时钟和调试端口要用到的GPIO*/ 23 __HAL_RCC_GPIOA_CLK_ENABLE(); 24 __HAL_RCC_GPIOB_CLK_ENABLE(); 25 __HAL_RCC_GPIOC_CLK_ENABLE(); 26 __HAL_RCC_GPIOH_CLK_ENABLE(); 27 } 28 void SysTick_Handler(void) 29 { 30 HAL_IncTick(); 31 }
以上代码是LED灯每1秒亮一次(亮500毫秒,灭500毫秒)
基于HAL库的STM32H7工程开发->系统时钟设置-点亮LED灯
标签:LLC parameter flag 基本 cpu ble tty struct scale
原文地址:https://www.cnblogs.com/723687715-Q/p/14928934.html