cancel
Showing results for 
Search instead for 
Did you mean: 

USART to printf

finsprit
Associate
Posted on September 29, 2010 at 21:18

@page {margin:2cm;} .ExternalClassB84147A5E35D4D54A6663AEC4519B806 P {margin-bottom:0.21cm;}

I can compile and download the attach project to the STM32VLDISCOVERY without any warnings or errors. The code is sort of working because I can toggle LED3 and LED4 but the code just hangs when is comes to the printf(.

This is my first project with the STM32 and I can't figure out whats wrong ? I hope some of you can help me.

Thx.

#semihosting #retargetting #printf #rtfm
7 REPLIES 7
finsprit
Associate
Posted on September 30, 2010 at 00:16

solved 🙂

lastsamurai
Associate III
Posted on May 13, 2011 at 03:57

Hi,

Good to hear that you solved it.  I'm having the same problem, and would appreciate if you can attach your

sourcefiles

with the thread.

Cheers,

Sam

lastsamurai
Associate III
Posted on May 13, 2011 at 03:57

Hi,

Good to hear that you solved it.  I'm having the same problem, and would appreciate if you can attach your

sourcefiles

with the thread.

Cheers,

Sam

Posted on May 13, 2011 at 21:35

Good to hear that you solved it.  I'm having the same problem, and would appreciate if you can attach your

sourcefiles

with the thread.

This is surely going to depend on your tool chain. It's probably a matter of including the right libraries and turning off the Semi Hosting SWI calls, and replacing the fputc() and __ttywrch(), or equivalents, with suitable code to emit characters on a USART of your choice.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist
Posted on May 16, 2011 at 07:51

''This is surely going to depend on your tool chain.''

 

 

Yes, it certainly is!

The necessary details - and, probably, examples too - will be in the toolchain documentation...

Keil also use the term ''retargetting''

Some toolchains give you options on the level of printf support - from ''simple'' to ''full''...

andreaspiezia9
Associate III
Posted on January 06, 2014 at 08:58

Hi,

I've the same problem. I'using Keil MDK-ARM 4.72.1.0 toolchain.

I can't find the solution in the documentation, can you help me?

Thanks 

Posted on January 06, 2014 at 12:06

//******************************************************************************
// Hosting of stdio functionality through USART2
//******************************************************************************
#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(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART2);
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, 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..