I use this code for retarget printf()
, but it does not work
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the LCD */
lcd_Data_Write((u8)ch);
return ch;
}
I use STM32F103RBT6
compiler : GCC with emBitz editor
Tank you Bence Kaulics
I use tinyprintf library and it worked quite well : github link
Try hijacking the _write function like so:
As an alternative, you could write your own
printf()
function using, Variable Argument Functions (va_list).With
va_list
a custom print function looks like the following:Usage example:
Note that while this solution gives you convenient function to use, it is slower than sending raw data or using even
sprintf()
. I have used this solution both on AVR and on STM32 microcontrollers.You could further modify the
vprint
like this, whereperiphery_t
is a simpleenum
type: