cancel
Showing results for 
Search instead for 
Did you mean: 

printf() and fprintf()

scott239955
Associate II
Posted on February 19, 2003 at 04:09

printf() and fprintf()

4 REPLIES 4
scott239955
Associate II
Posted on May 17, 2011 at 11:33

I'm using the C compiler for the ST92F124/150. How do I use fprintf() or printf() in the normal way, but direct the output to a buffer, register, or memory in the firmware? I noticed that there is reference to printf() in stdio.h, but could not find fprintf(). From looking at the documentation, it looks like printf() can only be use to write to the standard output stream (the computer.) For example: fprintf(my_buffer, ''the hour is: %d'', hour);

romain2399
Associate II
Posted on May 17, 2011 at 11:33

The ''printf'' library uses the standard output defined at the ''cst9_stdout'' address.

You can fix the cst9_stdout location in the script file :

cst9_stdout = 0x200000 (begining of RAM, for example)

cst9_stderr = 0x200001

This is just a byte location, I mean it is not a computer screen (!), each byte is copied to this location and only the last one reamains after the printf execution.

But you can use the sprintf function (see printf.zip) to copy a string to a string pointer, using the format feature.

Pointer can only point to the memory (C compiler ''limitation'') as the pointer is a word value and a word is a memory address. It is not possible to have pointer to the Registers (8bit address).

[ This message was edited by: Romain on 17-02-2003 08:59 ]
scott239955
Associate II
Posted on May 17, 2011 at 11:33

That's helpful - I tried your program and it compiles and seems to work well. However, I have been tring to figure out why I can not compile printf() or sprintf() statements in my application. I have copied your code into one of my files, included the stdio.h line and added cst9_stdout and cst9_stderr definitions (also include the equates in the .ld file and then tried substituting your .ld file), but I get ''undefined reference to 'printf''' and ''undefined reference to'sprintf'''. Any ideas?

romain2399
Associate II
Posted on May 17, 2011 at 11:33

You should check your compiler options in the makefile (*.mak).

Do not use ''-nostdlib'' option so that the standard C libraries are included, and use the ''-nostartfiles'' option so that your startup files are used instead of the standard startup files.

Refer to the ''gcc9, Libraries & Startup Files Reference Manual'' located in the Start->Programs->STVD9->UserDoc folder.