cancel
Showing results for 
Search instead for 
Did you mean: 

Some problems about printing and scaning from serialPort using UART_Function.

GShen.1
Associate II

Hardword: STM32F0_Discovery

Develop_Kit: Keil5.30+STM32CubeMX

I define the printf function in main.c as below:

#include "stdio.h"

#ifdef __GNUC__

 #define PUTCHAR_PROTOTYPE int __io_putchar (int ch)

#else

 #define PUTCHAR_PROTOTYPE int fputc(int ch,FILE *f)

#endif

PUTCHAR_PROTOTYPE

{

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

return ch;

}

It can be print the message when I using [printf].

Just want to getchar from the serial port, I define the getchar_prototype as below:

#ifdef __GNUC__

 #define GETCHAR_PROTOTYPE int __io_getchar (void)

#else

 #define GETCHAR_PROTOTYPE int fgetc(FILE *f)

#endif

GETCHAR_PROTOTYPE

{

uint8_t ch=0;

__HAL_UART_CLEAR_OREFLAG(&huart1);

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

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

 return ch;

}

Unfortunately, the printf and scanf function aren`t useful in the MCU. How can I recover this function? And how to define the scanf function in the MDK keil.

0 REPLIES 0