Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
682 Views

C Program only runs on NIOS 2 IF a printf is in the code.

Hi, i am using quartus version 11.1 and i am using the tool for eclipse to make my c programs so that i can run them on the nios 2 hardware. I am using a altera de2 board. 

 

I am working on a bigger project with VGA and keyboard and now I have made a "handshake communication" between the nios and a ram-controller. This is just so that i am not loosing any new input to the ram. 

But this works very slowly, and with signal tap i have found out that it is nios that are extremly slow on reading the PIO as i use as a flag to tell when its okey to send next character. 

 

I think the problem is for me in ecplise somewhere, for some reason i can not run ANY program that does not include a printf. It is like the compiler is optimizing away the code. Let me show you some examples that in my opinion should work but does not, not even on other nios system that i have created just to try, some small simple ones. 

 

Checklist: 

I have tried created new quartus projekt and new sopc files with new nios. 

I have tried a new workspace in eclipse. 

I have tried not changed anythings in the makefile. 

For 4 weeks ago, it worked without the printf (I dont think that i have changed anything in eclipse, in that case, by mistake) 

Ps: even programs without loops do only run with printf. 

 

 

So, how should i do to be able to run c programs on my NIOS 2 that does not include a printf?  

 

This will NOT work, using on_chip_memory 

 

# define swit 0x01021010# define LEDR_BASE_ADDRESS 0x01021030 int main(void) { (with or witout volatile, niether works) int * led = (int *) LEDR_BASE_ADDRESS; volatile int * switches = (int *) swit; while(1) { *(led) = *(switches); } return 0; }  

 

But this WORKS, using on_chip_memory: 

 

# define swit 0x01021010# define LEDR_BASE_ADDRESS 0x01021030 int main(void) { (with or witout volatile, niether works) int * led = (int *) LEDR_BASE_ADDRESS; volatile int * switches = (int *) swit; while(1) { *(led) = *(switches); printf("Hello"); } return 0; }  

 

 

this will NOT work, using sdram_memory: 

 

# define lol 0x01021000# define ADDR_BASE_ADDRESS 0x01021040# define VGA_BASE_ADDRESS 0x01021030# define FLAG_BASE_ADDRESS 0x01021050 int main(void) { volatile int * flag = (int *) FLAG_BASE_ADDRESS; volatile int * vga = (int *) VGA_BASE_ADDRESS; volatile int * addr = (int *) ADDR_BASE_ADDRESS; int state = 0; *(vga) = 'a'; *(addr) = 0; while(1) { if((*(flag) & 0x01) == 0) { if(state == 0) { *(vga) = *(vga) +1; *(vga)= (*(vga) | 0x100); state = 1; } } else { if(state == 1){ *(vga)= (*(vga) & 0x0FF); *(addr) = *(addr)+1; state = 0; } } } return 0; } 

 

 

this WILL work, using sdram_memory: 

 

# define lol 0x01021000# define ADDR_BASE_ADDRESS 0x01021040# define VGA_BASE_ADDRESS 0x01021030# define FLAG_BASE_ADDRESS 0x01021050 int main(void) { volatile int * flag = (int *) FLAG_BASE_ADDRESS; volatile int * vga = (int *) VGA_BASE_ADDRESS; volatile int * addr = (int *) ADDR_BASE_ADDRESS; int state = 0; *(vga) = 'a'; *(addr) = 0; while(1) { printf("hi"); if((*(flag) & 0x01) == 0) { if(state == 0) { *(vga) = *(vga) +1; *(vga)= (*(vga) | 0x100); state = 1; } } else { if(state == 1){ *(vga)= (*(vga) & 0x0FF); *(addr) = *(addr)+1; state = 0; } } } return 0; } 

 

 

 

 

 

 

SOLUTION: 

The problem seems to only occure when in SOPC-builder choosing Processor -> Nios_processor -> and take the II/f core. 

 

 

So if you get this problem just go for the II/e core and that way it worked fine for me. 

 

0 Kudos
0 Replies