SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By slagment
#146405
Hello,

I wish to define my own stream/IOstream/file descriptor so I can use fprintf with any hardware. I can hi-jack stdout and stderr and write to the UART, e.g., fprintf(stdout,"Comes out the UART %d", someInt).

I would rather have fprintf(myDefinedStream,"Comes out the someDevice %d", someInt).

I have many devices where fprintf would be handy, SDcard, external SRAM, ROM, LCD UART, and would like to define streams for them all.

All the low level code is written to write and read one char at a time, just got to define the stream and map to it.

Thanks

Using yagarto toolchain for arm. No FDEV functions that I can find.
User avatar
By viskr
#146409
You could do this for devices that function somewhat write-only, like SDcard for data logging, and LCD-UART. Maybe the same for reads as well like a ROM, though I don't see how it would be too useful for an SRAM. You'd have to do all the initialization to setup baud rates, pointers...

There's code out there for embedded systems for printf (the stock gcc stuff is not what you want to use, as the overhead is huge).

You could grab the code from our site for fprintf/printf that even handles single precision floats now, and the code is just over 4K for a Cortex ARM.