Forum Discussion
Hi Jingyang,
Yes, I have been trying to use the standard c library functions as you suggested with no luck. I found this page which seems like pretty standard stuff:
However, the Nios 2 compiler doesn't like any of it. Specifically, I am trying to do this:
FILE* file;
file = fopen("/dev/uart_0", "w+");
fd = fileno(file);
This generates a couple of errors:
conflicting types for 'file'; have 'int' UserFlash.c /UserFlashTest line 861 C/C++ Problem
conflicting types for 'fopen'; have 'FILE *(int, const char *)' UserFlashTest line 339, external location: /home/seahawk/apps/intelFPGA_lite/22.1std/nios2eds/bin/gnu/H-x86_64-pc-linux-gnu/nios2-elf/include/stdio.h C/C++ Problem
Invalid redeclaration of 'file' UserFlash.c /UserFlashTest line 861 Semantic Error
I tried the same thing using gcc on Ubuntu with no problems
#inclu
de <stdio.h>
int main() {
FILE *file = fopen("log.txt", "a");
int fd;
if (file == NULL) {
perror("Error opening file");
return 1;
}
const char *log_entry = "Log entry: Application started";
fprintf(file, "%s\n", log_entry);
fd = fileno(file);
fprintf(file, "fd = %d\n", fd);
fclose(file);
printf("Done");
return 0;
}
The first thing I am not sure about is the name parameter as pointed out from that website above, it is in system.h Here is mine with respect to uart_0. I am not sure if the name is /dev/uart_0 or UART_0_NAME. Neither one works.
/*
* uart_0 configuration
*
*/
#define ALT_MODULE_CLASS_uart_0 intel_lw_uart
#define UART_0_BASE 0x142380
#define UART_0_BAUD 115200
#define UART_0_DATA_BITS 8
#define UART_0_FIXED_BAUD 1
#define UART_0_FREQ 90000000
#define UART_0_IRQ 7
#define UART_0_IRQ_INTERRUPT_CONTROLLER_ID 0
#define UART_0_NAME "/dev/uart_0"
#define UART_0_PARITY 'N'
#define UART_0_READ_DEPTH 1024
#define UART_0_SIM_TRUE_BAUD 0
#define UART_0_SPAN 32
#define UART_0_STOP_BITS 1
#define UART_0_SYNC_REG_DEPTH 2
#define UART_0_TYPE "intel_lw_uart"
#define UART_0_USE_CTS_RTS 0
#define UART_0_USE_EOP_REGISTER 0
#define UART_0_WRITE_DEPTH 1024
I did ask my management about sharing my project folder and they really don't want to do that, unfortunately.
Hopefully, you will have a nugget of wisdom for me that will solve this problem.
Regards,
Kelly Painter