This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What is the relationship between UART and printf within retarget?

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.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and retarget.c

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

0