Altera_Forum
Honored Contributor
15 years agoMy program get stuck in fopen() while trying to open the LCD HAL mount point.
Hi, I got a problem integrating two parts of a C program with Nios II 9.1 IDE. It's for a university team project and we use a time limited core license of Quartus II 9.1SP1 web edition. We're using Terasic DE2 development board which include a Cyclone II FPGA, 8MB SDRAM, LCD, GPIO and so many other things that we're not using for the project. So, as you can understand, we're loading our program in SDRAM. We've started making our Nios II system with SOPC Builder adding all components we needed for the project based on an Altera tutorial. Our Nios II system is the same from the beginning and all programs tested on it have working well, but now we got a problem integrating two part of the program.
The two part are running fine a part. My team and I tested the first part implementing the main program with LCD display functions and it's working well. We tested the second part in the same project after moving the first part source files away. The major differences of this second part is that it uses the UART core and malloc() function. The test had good results. The second part is running fine with a temporary main() function that I made explicitly to test it. When building the two parts together in the same Nios II C project, we have no errors nor warnings. The problem is when the program is running. When trying to open the "/dev/lcd_0" mount point the program get stuck within the fopen() function never returning to the caller. However, it's the same exact code that it's executed when the first part program is running appart ; in that way, it's working well, the fopen returns the FILE pointer... Actually, we traced the problem to the first call to fopen() and I simplified the program to better explain it. Now, the first statement executed in the main() is a test function for the lcd. The code goes like this :/* FILE : main.c */
# include <stdio.h>
void test_lcd(void)
{
FILE * lcd;
fprintf(stderr, "Test_lcd_start\n");
lcd = fopen("/dev/lcd_0", "w");
if(lcd == NULL)
{
fprintf(stderr, "Failed to open LCD");
exit(EXIT_FAILURE);
}
fprintf(lcd, "Hello on the LCD\n");
fprintf(stderr, "Test_lcd_end\n");
fclose(lcd);
}
int main(void)
{
test_lcd();
}When I debug it with Nios II 9.1 IDE, the program gets in the fopen function. If I hit 'pause', the program is in the fopen subcalls to Hardware Abstraction Layer (HAL) library functions. It is stuck in a infinite loop that I don't have time to totally understand. Anyway, that is not my code, its Altera, and I suppose it works, but there is something somewhere in my code that causes that situation in Altera code. This is where, I'm stuck myself, what goes wrong and where? :confused: Maybe some of you have ideas or knows of related issues to my problem? As a bonus, I've noticed something. When I run the test_lcd() code directly in main(), it works??? How, I don't know and I don't think it very solves the problem. I mean that I will probably have related bugs harder to find if it works weird like this and not in a sub function. None the less, it's a clue. :rolleyes:That's an example : /* FILE : main.c */
# include <stdio.h>
int main(void)
{
FILE * lcd;
lcd = fopen("/dev/lcd_0", "w");
if(lcd == NULL)
{
fprintf(stderr, "Failed to open LCD");
exit(EXIT_FAILURE);
}
fprintf(stderr, "Hello on the LCD\n");
fclose(lcd);
}As I said, the first part and the second part of the program are working well apart. When the two are build together, I got the fopen() problem without ever trying to call a function from the second part source file. If somebody could help, my team and I will very appreciate. Pic.