#include "stm32h7xx_hal.h"
// 定义LED引脚
#define LED_PIN GPIO_PIN_1
#define LED_PORT GPIOB
// 初始化GPIO
void GPIO_Init(void) {
__HAL_RCC_GPIOB_CLK_ENABLE(); // 使能GPIOB时钟
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
}
int main(void) {
HAL_Init(); // 初始化HAL库
GPIO_Init(); // 初始化GPIO
while (1) {
HAL_GPIO_TogglePin(LED_PORT, LED_PIN); // 切换LED状态
HAL_Delay(500); // 延时500ms
}
} |