Files

33 lines
1.3 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "gd32e23x.h"
#include "gpio.h"
#include "systick.h"
#include "board_config.h"
/**
* ************************************************************************
* @brief 初始化 GPIO 为确定状态
*
* @details 本函数仅为外设提供确定的初始状态避免因GPIO状态不确定而导致的异常动作。
* 在系统复位后GPIO寄存器可能处于不确定状态通过显式配置确保
* - 未使用的GPIO配置为输入或低功耗状态
* - 关键控制信号配置为安全的默认状态
* - 防止外设因GPIO状态不明确而产生意外行为
*
* @note 此函数应在系统初始化早期调用,在启用具体外设功能之前执行
* @note 具体的外设功能初始化应在各自模块中单独进行
*
* @param none
* @return none
* ************************************************************************
*/
void gpio_init(void) {
// 使能 LED 时钟
rcu_periph_clock_enable(LED_RCU);
// 配置 LED 为输出模式
gpio_mode_set(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_PIN);
gpio_output_options_set(LED_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED_PIN);
// 初始化 LED 为低电平LED 开启)
gpio_bit_reset(LED_PORT, LED_PIN);
}