✨ feat: 添加my_printf函数
This commit is contained in:
parent
25cd595d66
commit
68f4c09140
|
@ -3,11 +3,15 @@
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stm32f1xx_hal_uart.h>
|
#include <stm32f1xx_hal_uart.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#define HUART1 (&huart1)
|
||||||
|
#define HUART2 (&huart2)
|
||||||
|
|
||||||
extern UART_HandleTypeDef huart2;
|
extern UART_HandleTypeDef huart2;
|
||||||
|
|
||||||
extern int __io_putchar(int ch) __attribute__((weak));
|
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);
|
uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us);
|
||||||
while (delay--);
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user