HI.
I'm trying to understand the relationship between UART and printf within retarget.
as I understand, retarget supports to implement low level function fputc, if I want to use printf().
if I am right, I can't still understand the relationship between printf and UART_STDOUT.
especially, the below example is what I want to share you.
this is the hello.c example code.
//Hello.c #ifdef CORTEX_M3 #include "CMSDK_CM3.h" #else #include "CMSDK_CM4.h" #endif #include <stdio.h> #include "uart_stdout.h" int main(void) { // UART init UartStdOutInit(); printf("Hello world\n"); printf("** TEST PASSED **\n"); // End simulation UartEndSimulation(); return 0; }
and retarget.c
#include <stdio.h> #include <time.h> #include <rt_misc.h> #pragma import(__use_no_semihosting_swi) extern unsigned char UartGetc(void); extern unsigned char UartPutc(unsigned char my_ch); struct __FILE { int handle; /* Add whatever you need here */ }; FILE __stdout; FILE __stdin; int fputc(int ch, FILE *f) { return (UartPutc(ch)); } int fgetc(FILE *f) { return (UartPutc(UartGetc())); } int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; } void _ttywrch(int ch) { UartPutc (ch); } void _sys_exit(int return_code) { label: goto label; /* endless loop */ }
I can't understand how does printf() work? Is printf() working as UART function as a fake ? or really works as UART?
Is printf() connected UART function? I can't understand the relationship between UART function of cortex-m3 and printf().
Does printf() differently work such as printf() of ANCI C?
Would you please anyone help me to understand this question to clarify?
Thanks in advance
View all questions in Cortex-M / M-Profile forum