cancel
Showing results for 
Search instead for 
Did you mean: 

how to use ''printf''?

Min-Kyoung Kim
Associate III
Posted on February 09, 2017 at 14:47

I'm using examples of project  'UART_Printf'. 

But I can't use printf. 

I set uart1. and I checked that uart1 tx/rx works. 

I added below code to my source. 

&sharpinclude 'stdio.h'

&sharpifdef __GNUC__

/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf

set to 'Yes') calls __io_putchar() */

&sharpdefine PUTCHAR_PROTOTYPE int __io_putchar(int ch)

&sharpelse

&sharpdefine PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

&sharpendif /* __GNUC__ */

PUTCHAR_PROTOTYPE

{

/* Place your implementation of fputc here */

/* e.g. write a character to the USART1 and Loop until the end of transmission */

HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);

return ch;

}

#uart #printf #stm32f4
10 REPLIES 10