"StringOut" works while "printf" doesn't.
Hello,
I'm working with the NUCLEO-F722ZE EVB on STM32CubeIDE.
In my code I tried to make the "printf" function work.
I used the procedure described in this video:
https://www.youtube.com/watch?v=9ntZ3dwGsMk
It basically involves adding this code (the full code is below) :
#include <stdio.h>
int fputc(int ch, FILE *f)
{
HAL_UART_Transmit ( & huart3 , (uint8_t *)&ch , 1 , 0xFFFF ) ;
return ch ;
}To prove that the UART peripheral works - I try to print Hello World using 2 methods. As follows:
StringOut ( "Hello World with StringOut\n\r" ) ;
printf ( "Hello World with printf" ) ;But when I run the code only "Hello World with StringOut" gets printed on the screen. The printf function doens't do anything.
Help me fix the printf function.
This is the full code:
#include "main.h"
#include <stdio.h>
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
void StringOut ( char * s )
{
HAL_UART_Transmit ( & huart3 , ( void * ) s , strlen ( s ) , 1000 ) ;
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_USART3_UART_Init();
while (1)
{
StringOut ( "Hello World with StringOut\n\r" ) ; // Prints successfully
printf ( "Hello World with printf" ) ; // Nothing happens. The code just proceeds ahead.
}
}
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit ( & huart3 , (uint8_t *)&ch , 1 , 0xFFFF ) ;
return ch ;
}