From 68f4c091402509a6ba85a915eb0823959dfa9af2 Mon Sep 17 00:00:00 2001 From: JasonChen <2805998671@qq.com> Date: Sun, 14 Jul 2024 17:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=B7=BB=E5=8A=A0my=5Fprin?= =?UTF-8?q?tf=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Inc/syscalls.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Core/Inc/syscalls.h b/Core/Inc/syscalls.h index 81c09c0..5327636 100644 --- a/Core/Inc/syscalls.h +++ b/Core/Inc/syscalls.h @@ -3,11 +3,15 @@ #include #include +#include #include #include #include #include +#define HUART1 (&huart1) +#define HUART2 (&huart2) + extern UART_HandleTypeDef huart2; extern int __io_putchar(int ch) __attribute__((weak)); @@ -76,4 +80,23 @@ void delay_us(uint16_t us) { uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us); while (delay--); } + +/** + * @brief 自定义printf + * @param huart, buf + * @return void + * + * @usage my_printf(HUART1, "USART1_Target:\r\n"); + */ +void my_printf(UART_HandleTypeDef *huart, const char *buf, ...) { + const char *p = buf; + char str[255] = {0}; + va_list v; + va_start(v, buf); + vsprintf(str, buf, v); + HAL_UART_Transmit(huart, str, strlen(str), 0xff); + va_end(v); +} + + #endif