Stream creating, using fprintf for everything.

Your source for all things Atmel.

Moderator: phalanx

Post Reply
slagment
Posts: 40
Joined: Fri Oct 08, 2010 4:10 pm

Stream creating, using fprintf for everything.

Post by slagment » Thu Jun 21, 2012 1:51 pm

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
viskr
Posts: 263
Joined: Tue Jun 20, 2006 10:29 am
Location: Lake Tahoe, CA
Contact:

Re: Stream creating, using fprintf for everything.

Post by viskr » Thu Jun 21, 2012 2:19 pm

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.
reviving the BASIC stamp http://www.basicchip.com

Post Reply