2013-03-07 11:21 AM
Hello, I have project in Keil for demonstrating USART on STM32F0.
Program is working fine with putc, but with printf it isn´t working (building of program finish success in both case). Why printf isn´t work? My main.c is here:#include ''stm32f0xx.h''
#include ''periph_init.h''#include <stdio.h>int fputc(int ch, FILE *f) { USART_SendData(USART1, (uint8_t) ch); while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET) {} return ch;} int main(void){ periph_init (); printf(''print''); while (1); }2013-03-07 01:50 PM
//******************************************************************************
// Hosting of stdio functionality through USART1
//******************************************************************************
#include <
rt_misc.h
>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART1);
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
//******************************************************************************
2013-03-07 04:11 PM
Thank you very much. It´s working.