Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Nois CPU halt at fprintf

Altera_Forum
Honored Contributor II
1,492 Views

hi,everyone: 

I have to output information by UART in my project, When program loaded from FLASH(EPCS),then CPU halt at fprintf(),so do with getc(),fscanf(),but not fwrite(). but it is ok in debug mode with JTAG-UART. Why? 

Who can help me,thanks!
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
342 Views

it'd be easier if you can post the code here..

0 Kudos
Altera_Forum
Honored Contributor II
342 Views

code as following: 

 

int main() 

FILE *fp; 

char echo; 

 

fp = fopen(UART_0_NAME, "r+"); 

if (fp) 

while (1) 

echo = getc(fp); 

fwrite(&echo, 1, 1, fp); 

fprintf(fp, ">>\r\n"); // always stop here 

 

return 0; 

}
0 Kudos
Altera_Forum
Honored Contributor II
342 Views

Well, the stdio functions will probably be buffering the output data until \n is output - so nothing will try to access the uart itself until then. 

 

That probably means your uart either isn't configured properly (so the io cycles to it are stalling the cpu), or any interrupt service routine is misbehaving (looping or not clearing the IRQ line).
0 Kudos
Altera_Forum
Honored Contributor II
342 Views

What is the difference between using jtag debug and software run from flash? It confuses me. 

Everything is ok when debug it, but it don't work when boot from flash. 

Why?God,help me,please!
0 Kudos
Altera_Forum
Honored Contributor II
342 Views

Typically, when it's "running" from flash, it's really copying code from flash into RAM and then executing that code. 

 

How do you know that your code stops at fprintf() when loading from EPCS/flash? Have you run a minimal memtest (with a simple DMA in your system) on the memory you're loading to? What is your offchip memory? 

 

Regards, 

 

slacker
0 Kudos
Altera_Forum
Honored Contributor II
342 Views

i solved it finally!it is so easy when i got it. 

Only set "Exception Vecoter" in CPU seting to SDRAM not EPCS_FLASH_CONTROLLER in SOPC Builder. 

If exception vector be pointed to epcs_flash_controller, then interrupt of fprintf() happened, it can't jump to the correct location. 

Thanks to normad, dsl and slacker.
0 Kudos
Reply