Forum Discussion
UART with fopen
im trying read and write to my uart device like:
FILE *urt;
urt = fopen("/dev/UART","r+");
fprintf(urt,"data"); but fopen does not work for me unless i disable small c library. and when i do that it naturally increases my memory footprint. is there a way to do this without disabling small c? am i doing something wrong. the error im getting with small c enabled is "undefined reference to 'fopen' " thanks in advance5 Replies
- Altera_Forum
Honored Contributor
Well, the stdio functions aren't in the small library - removing them is most of what is done to make it 'small'.
Possibly you can use the Posix open() and write() functions, but they still require a significant amount of interface 'glue' before you get to the device driver. For a small system you have to stop pretending you are writing a portable application for a large operating system and start writing code that is specific to the hardware you actually have. The means that you need to directly call the 'driver' functions, and probably change the driver internals to behave the way you need them to behave, instead of relying on 'standard' driver semantics. - Altera_Forum
Honored Contributor
http://www.alteraforum.com/forum/showthread.php?t=16836&goto=nextoldest
Is one of many threads that discuss UART access. There are some code examples included that work without open/fopen/write ... - especial on the later pages Maybe you will find there something useful - Altera_Forum
Honored Contributor
well i found an alternative method.. that is to use the the rs232 UART core for altera DE2 boards.. ftp://ftp.altera.com/up/pub/university_program_ip_cores/80/rs232.pdf its driver nicely does the job for me.. :)
but i think you're right.. when you're writing embedded programs you cant take drivers for granted.. so ill try and make my program work by directly interfacing with the device registers :) - Altera_Forum
Honored Contributor
In my project I set the UART to be used for stdin and stdout and then I use the alt_printf, alt_putchar, and alt_getchar functions to read and write to the uart. My entire nios code is still under 7kb and fits in my onchip memory with plenty of room.
- Altera_Forum
Honored Contributor
yeah i figured thats the easiest way to do it.. but i need to use my console window and keyboard therefore i need both jtag_uart and my uart.. if i switch one of them to be my stdin,stdout im gonna need an alternative method to communicate to the other :)
thanks anyway