/*
File: printf.c

Copyright (C) 2004,2008  Kustaa Nyholm

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

copied from http://www.sparetimelabs.com/printfrevisited/index.html
modified by Philipp Scholl <scholl@teco.edu>

*/

#include "stdarg.h"
#include "string.h"
#include "stdio.h"
#include "stddef.h"
#include "stm32l4xx_hal.h"

extern UART_HandleTypeDef huart2;
int UART_Print(const char *fmt, ...)
{
  int m;
  char str[512] = {0};
  va_list va;
  va_start(va,fmt);
  m = vsnprintf(str, sizeof(str)-1, fmt, va);
  va_end(va);
  str[m+1] = '\0';
  HAL_UART_Transmit(&huart2,(uint8_t*)str,strlen(str),100);
  return m;
}
