29 lines
648 B
C
29 lines
648 B
C
#include "../2025_include_user/Print.h"
|
|
|
|
void Print_init() {
|
|
NVIC_ClearPendingIRQ(PRINTF_INST_INT_IRQN);
|
|
NVIC_EnableIRQ(PRINTF_INST_INT_IRQN);
|
|
}
|
|
|
|
// 串口发送单字节
|
|
void print_char(char ch) {
|
|
DL_UART_Main_transmitDataBlocking(PRINTF_INST, (uint8_t)ch);
|
|
}
|
|
|
|
// 字符串输出
|
|
void print_str(const char *str) {
|
|
while (*str) {
|
|
print_char(*str++);
|
|
}
|
|
}
|
|
|
|
// 自定义格式化输出
|
|
void print(const char *format, ...) {
|
|
char buffer[128]; // 注意大小,防止栈溢出
|
|
va_list args;
|
|
va_start(args, format);
|
|
vsnprintf(buffer, sizeof(buffer), format, args);
|
|
va_end(args);
|
|
print_str(buffer);
|
|
}
|