cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with printf on F0

hospodar
Associate III
Posted on March 07, 2013 at 20:21

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);             

}

2 REPLIES 2
Posted on March 07, 2013 at 22:50

//******************************************************************************
// 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 */
}
//******************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hospodar
Associate III
Posted on March 08, 2013 at 01:11

Thank you very much. It´s working.