#include "putil.h" #include #include #include #define MAX_PRINTF_BUFFER (256) UART_HandleTypeDef *huart_inst = NULL; static char send[10] = {'\0'}; int p_printf(const char *fmt, ...) { size_t size_str = strlen(fmt); if (size_str >= MAX_PRINTF_BUFFER) { return -1; } uint8_t printf_buffer[MAX_PRINTF_BUFFER]; memset(printf_buffer, '\0', MAX_PRINTF_BUFFER); va_list args; va_start(args, fmt); vsprintf((char *)printf_buffer, fmt, args); va_end(args); HAL_UART_Transmit(huart_inst, printf_buffer, strlen(printf_buffer), 100); return 0; } void p_uart_init(UART_HandleTypeDef *huart) { huart_inst = huart; PDEBUG("...\n"); PDEBUG("UART2 Initialized\n"); } void p_uart_async_write_byte(uint8_t byte) { sprintf(send, "%02x\n", byte); HAL_UART_Transmit(huart_inst, send, 3, 100); }