Follow the reference to port the bootloader

This commit is contained in:
2025-09-28 01:14:06 +08:00
parent 422c27846f
commit bd541d585e
23 changed files with 712 additions and 1638 deletions

33
Src/gpio.c Normal file
View File

@@ -0,0 +1,33 @@
#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);
}