Forum Discussion
Altera_Forum
Honored Contributor
16 years agoDE2 -- UART transmit and receive compiling error
Hi all,
I'm using the DE2 kit, with Quartus II (using SOPC) and NIOS IDE software to make an UART communication. But the compilation was always failed. Does anyone know how I can work around it? Thanks in advance The example code from the NIOS handbook was: # include "sys/alt_stdio.h"# include "stdio.h"# include "string.h"# include "system.h" int main() { char* msg = "Detected character\n"; FILE* fp; char prompt = 0; printf("Testing begin\n"); fp = fopen ("/dev/uart_0","r+"); if (fp) { while (prompt!=0) { prompt = getc(fp); if (prompt=='t') { fwrite (msg,strlen(msg),1,fp); } } fprintf(fp,"closing\n"); fclose(fp); } return 0; } The error of the compilation was: /cygdrive/c/altera/91/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/lib/libc.a(closer.o) In function `_close_r': /cygdrive/c/altera/91/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/lib/libc.a(lseekr.o) In function `_lseek_r': /cygdrive/c/altera/91/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/lib/libc.a(openr.o) In function `_open_r':6 Replies
- Altera_Forum
Honored Contributor
thanks a lot it is useful to me
- Altera_Forum
Honored Contributor
i got rid of the problem by unchecking "Lightweight device driver API" at the lib preferences!
Now also the filepointer is != NULL! :) - Altera_Forum
Honored Contributor
i discovered exactly the same problem!
i also have to add that the filepointer fd is still NULL after fopen so i think this function fails too! the full error messages: --- Quote Start --- /var/opt/altera/9.0/nios2eds/bin/nios2-gnutools/H-i686-pc-linux-gnu/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/lib/mno-hw-mul/libc.a(closer.o)(.text+0x18): In function `_close_r': /data/sc-build/build/nios2eds-gnutools-linux32-9.0/bin/nios2-gnutools/src/newlib/newlib/libc/reent/closer.c:53: warning: warning: close is not implemented and will always fail /var/opt/altera/9.0/nios2eds/bin/nios2-gnutools/H-i686-pc-linux-gnu/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/lib/mno-hw-mul/libc.a(lseekr.o)(.text+0x20): In function `_lseek_r': /data/sc-build/build/nios2eds-gnutools-linux32-9.0/bin/nios2-gnutools/src/newlib/newlib/libc/reent/lseekr.c:58: warning: warning: lseek is not implemented and will always fail /var/opt/altera/9.0/nios2eds/bin/nios2-gnutools/H-i686-pc-linux-gnu/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/lib/mno-hw-mul/libc.a(openr.o)(.text+0x20): In function `_open_r': /data/sc-build/build/nios2eds-gnutools-linux32-9.0/bin/nios2-gnutools/src/newlib/newlib/libc/reent/openr.c:59: warning: warning: open is not implemented and will always fail --- Quote End --- - Altera_Forum
Honored Contributor
I can give you my functions I used to test the Uart. Maybe these can help you to find the problem.
void init_uart(int BAUD) { int divi; divi = (100000000 / BAUD) + 0.5; IOWR_16DIRECT(RS232_INST_BASE, 0x14, divi); } void write_uart(char x) { unsigned long status = 0; while((status & 0x00000040) != 0x00000040) { status = IORD_ALTERA_AVALON_UART_STATUS(RS232_INST_BASE); } IOWR_ALTERA_AVALON_UART_TXDATA(RS232_INST_BASE, x); } char read_uart(void) { char x; x = IORD_ALTERA_AVALON_UART_RXDATA(RS232_INST_BASE); return x; } - Altera_Forum
Honored Contributor
Thanks Jacol,
The errors still exist. - Altera_Forum
Honored Contributor
Hi,
maybe this inclution helps you. # include "altera_avalon_uart_regs.h"