You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
623 B
C

3 years ago
#include "putil.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#define MAX_PRINTF_BUFFER (256)
UART_HandleTypeDef* huart_inst = NULL;
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;
}