- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using Quartus Lite 22.1.2. I am using the lightweight uart core. It is initialized by the alt_sys_init function and declares an object called uart_0. My problem is this object seems to be getting optimized out. In my main function, this line:
collect2: error: ld returned 1 exit status
make: *** [Makefile:1077: UserFlashTest.elf] Error 1
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
For the lightweight UART, it is not meant to use the device instantiation directly.
It should be used to use through calling the Standard C Library Function as mention in the link below:
https://www.intel.com/content/www/us/en/docs/programmable/683130/22-3/uart-api-34890.html
Regards
Jingyang, Teh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the quick answer. I had wondered about that so we tried the avalon uart and the same thing happens. Let me explain what we are trying to do and maybe there is a better way. We are trying to use this embedded console found here:
https://github.com/bradschl/embedded-c-debug-console
We have a getc function defined as below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I have not tried using the LightWeight UART IP before.
But from the user guide you would need to enable the small driver option in the BSP.
In your case have you initialized the called the initialize the UART in your code using the function "intel_lw_uart_ioctl_fd (alt_fd* fd, int req, void* arg);"
You would need to declare your own FD and pass it through the init function.
Could you try sharing your project folder for me to understand better?
Regards
Jingyang, Teh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Do you have any follow up question on this?
Regards
Jingyang, Teh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have been playing around with this more and have tried to open the uart in this way:
int fd;
fd = open(UART_0_NAME, O_RDWR);
This generates two errors:
Description Resource Path Location Type
conflicting types for 'fopen'; have 'FILE *(int, const char *)' UserFlashTest line 339, external location: /home/user/apps/intelFPGA_lite/22.1std/nios2eds/bin/gnu/H-x86_64-pc-linux-gnu/nios2-elf/include/stdio.h C/C++ Problem
initializer element is not constant UserFlash.c /UserFlashTest line 861 C/C++ Problem
Functions that call read and write with fd don't generate errors. I think if I could get past the open call, I would be good. Any suggestions as what might be wrong?
Regards,
Kelly Painter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
It seems weird that it is recognizing the FILE as an int type.
Could you try including these headers into your project and recompiling?
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
Regards
Jingyang, Teh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Do you have any update on this case?
After adding the header files did you manage to solve the error?
Regards
Jingyang, Teh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jingyang,
I added those includes and I still am getting the same errors.
Description Resource Path Location Type
conflicting types for 'fd'; have 'int' UserFlash.c /UserFlashTest line 859 C/C++ Problem
Invalid redeclaration of 'fd' UserFlash.c /UserFlashTest line 859 Semantic Error
Regards,
Kelly Painter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Do you have problem compiling a simple hello world example on your end?
Is it possible that you could zip up your project and share it to me to have a look?
Regards
Jingyang, Teh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Did you managed to try the hello world example?
Did you face the same issue?
Regards
Jingyang, Teh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
As we do not receive any response from you on the previous question/reply/answer that we have provided. Please login to ‘https://supporttickets.intel.com/s/?language=en_US’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.
Regards
Jingyang, Teh

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page