Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

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 advance

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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