This commit is contained in:
2026-05-21 08:07:16 +08:00
parent 90908cf018
commit 84d8874a38
32 changed files with 271 additions and 27 deletions
+6
View File
@@ -10,6 +10,7 @@ static char debug_buffer[256];
/**
* @brief 初始化调试串口(USART2, PA2=TX, PA3=RX)
*/
/* 函数作用:初始化 USART2 调试串口并输出启动日志。 */
void Debug_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
@@ -52,6 +53,7 @@ void Debug_Init(void)
/**
* @brief 通过调试串口发送一个字节
*/
/* 函数作用:通过 USART2 发送单个调试字节。 */
static void Debug_SendByte(uint8_t byte)
{
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
@@ -61,6 +63,7 @@ static void Debug_SendByte(uint8_t byte)
/**
* @brief 通过调试串口发送字符串
*/
/* 函数作用:通过 USART2 连续发送调试字符串。 */
static void Debug_SendString(const char* str)
{
while (*str)
@@ -72,6 +75,7 @@ static void Debug_SendString(const char* str)
/**
* @brief 格式化调试信息输出(类似printf)
*/
/* 函数作用:格式化调试信息并通过串口输出。 */
void Debug_Printf(const char* format, ...)
{
va_list args;
@@ -85,7 +89,9 @@ void Debug_Printf(const char* format, ...)
#else
// 调试关闭时,提供空实现
/* 函数作用:调试关闭时提供空初始化函数,保持接口兼容。 */
void Debug_Init(void) {}
/* 函数作用:调试关闭时丢弃格式化输出,保持接口兼容。 */
void Debug_Printf(const char* format, ...) {}
#endif
+2
View File
@@ -8,9 +8,11 @@
#define DEBUG_ENABLE 1 // 暂时关闭,添加Debug.c后改回1
// 调试串口初始化(使用USART2,PA2/PA3)
// 函数作用:初始化调试串口 USART2,供 DEBUG_PRINT 输出日志使用。
void Debug_Init(void);
// 调试信息输出函数
// 函数作用:按 printf 格式输出调试日志到调试串口。
void Debug_Printf(const char* format, ...);
// 快捷宏定义
+5
View File
@@ -8,6 +8,7 @@ volatile uint32_t g_time_ms = 0;
/**
* @brief 初始化SysTick定时器,配置为1ms中断一次
*/
/* 函数作用:初始化 SysTick,使系统每 1ms 进入一次中断。 */
void Delay_Init(void)
{
// 配置SysTick为1ms中断一次。SystemCoreClock通常是72MHz。
@@ -22,6 +23,7 @@ void Delay_Init(void)
* @brief 获取自启动以来的毫秒数
* @retval 当前的毫秒时间戳
*/
/* 函数作用:返回系统启动以来累计的毫秒计数。 */
uint32_t Get_Time_ms(void)
{
return g_time_ms;
@@ -30,6 +32,7 @@ uint32_t Get_Time_ms(void)
// --- 以下是你原本就有的阻塞式延时函数,保持不变 ---
/* 函数作用:使用 SysTick 实现微秒级阻塞延时。 */
void Delay_us(uint32_t xus)
{
SysTick->LOAD = 72 * xus;
@@ -39,6 +42,7 @@ void Delay_us(uint32_t xus)
SysTick->CTRL = 0x00000004;
}
/* 函数作用:基于毫秒 tick 实现毫秒级阻塞延时。 */
void Delay_ms(uint32_t xms)
{
// 使用SysTick计时器实现精确延时
@@ -48,6 +52,7 @@ void Delay_ms(uint32_t xms)
}
}
/* 函数作用:通过循环调用毫秒延时实现秒级阻塞延时。 */
void Delay_s(uint32_t xs)
{
while(xs--)
+5
View File
@@ -5,12 +5,17 @@
#include "stm32f10x.h" // 确保包含了这个
// 添加下面两个函数的声明
// 函数作用:初始化 SysTick 延时模块和毫秒计时基准。
void Delay_Init(void);
// 函数作用:返回系统启动以来经过的毫秒数。
uint32_t Get_Time_ms(void);
// 保留你原有的函数声明
// 函数作用:阻塞延时指定微秒数。
void Delay_us(uint32_t us);
// 函数作用:阻塞延时指定毫秒数。
void Delay_ms(uint32_t ms);
// 函数作用:阻塞延时指定秒数。
void Delay_s(uint32_t s);
#endif