printf is a standard library function; it is defined by the 'C' standard: it sends its output to stdout - nothing else.
So adding a parameter is not just ''retargetting'' - it is completely changing the standard behaviour! If you want to specify the output destingation in a standard library file, you will have to us fprintf or similar. Or you could redefine stdout between calls. Or create your own function that specifies a destination. Or did you want a function that sends its output to two destinations simultaneously?
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Look at how you've hosting the lcd/usart now, and have your ''sendchar()'' function send characters to both.
Or use sprintf() to generate data for both in your own ''DebugPrintf()'' function. #include <stdio.h> #include <rt_misc.h> #pragma import(__use_no_semihosting_swi) struct __FILE { int handle; /* Add whatever you need here */}; FILE __stdout; extern int sendchar (int ch); int fputc(int ch, FILE *f) { return (sendchar (ch)); } int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; } void _ttywrch(int ch) { sendchar (ch); } void _sys_exit(int return_code) { label: goto label; /* endless loop */ }
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
already I know this and I am retarget it to my lcd routine, my question is it possible to retarget it to 2 routinesor more? seial send char, glcd ? Thank you
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
The point Andrew and I made is that you could do it like this :
int sendchar (int ch) // Hosting function character output routine { sendchar_usart(ch); sendchar_lcd(ch); return(ch); } Why would this NOT work? If your clocks remain busted I could see the USART not outputing at the right baud rate. But that could be fixed by tweaking the baud rate register.
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
I'm using Keil and STLink on the STM32F4Discovery board and I see in uVision there's a window for ''Debug (printf) Viewer''. Which I assume takes printf() and xfers it through the attached STLink I'm debugging with, which sounds great to me!But I use printf() and it jumps to the reset vector. There's no compile warning about stdout being unimplemented or anything. What do I need to put in to transfer the data across the STLink?
Yeah the Keil tab I was using was ''STLink (deprecated)'' but just changing to ''STLink Debugger'' led to ''Device Not Found''. I made all the changes specified up there and the debugger works again. It doesn't bomb on printf, however, I don't see anything printing out in the printf() Viewer window.
The instructions listed in that blog link will work. However, as the author mentioned, it doesn't auto-program when entering Debug. I got no printf() output because I was running stale code. The fix is under ''Utilities->Update Target Before Debugging'' (check, obviously).