Merge branch 'feat-csj' into dev

This commit is contained in:
JasonChen 2024-07-14 17:29:01 +08:00
commit 9a9d13f7ba

View File

@ -3,11 +3,15 @@
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stm32f1xx_hal_uart.h>
#include <time.h>
#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