Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
2,357 Views

printf does not display in the console

Hi All, 

 

I am trying to get the cycloneiii_3c25_start_niosii_standard reference design files to run on the cyclone iii starter kit. 

 

The problem that i have is that once the Nios ii project is built and run on the board printf does not display anything to the console. 

 

The code is as simple as can be: 

 

# include <stdio.h> int main() { printf ("hello from Nios II!\n"); return 0; }  

 

I have seen that other people have made posts regarding this problem. 

 

I have checked that stdout is set to jtag_uart in the system library properties. 

 

 

in the debug window i see a message: 

<terminated, exit value :0> Nios II download output (dd/mm/yy hh:mm) 

 

It has been recommended in other that i should debug with breakpoints at alt_main() but i dont seem to be able to navigate to alt_main.c from Nios II IDE within my workspace. 

Even a search doesn't find it. 

 

Using windows explorer i find alt_main.c in nios2eds\components\altera_HAL\src 

 

I havent edited the SOPC reference design or the Nios II reference design so i would have assumed any problem would be a simple config issue. 

 

 

Any advice would be greatly appreciated.  

 

Thanks in advance.  

 

Ade
0 Kudos
15 Replies
Altera_Forum
Honored Contributor I
374 Views

You might just need to wait for the output to happen. 

It isn't 100% clear what happens when main returns! 

(Well there is code to close stdout etc - but I don't understand why!) 

 

Try adding for (;;); at the bottom of your function.
Altera_Forum
Honored Contributor I
374 Views

Hi dsl, i tried that and it made no difference. 

 

Do you how i can find alt_main() from my project/workspace - i think its worth adding a few break points and attempting to debug from there. 

 

Incidentally i just tried some example code from the tutorial but with the printf statement commented out. 

 

# include <stdio.h> # include "system.h" # include "altera_avalon_pio_regs.h" int main() { //printf("Hello from Nios II!\n"); int count = 0; int delay; while(1) { IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, count & 0x01); delay = 0; while(delay < 2000000) { delay++; } count++; } return 0; }  

 

This is meant to make the LED's on the board blink. 

 

This didnt work either - so the problem is not neccessarily specific to printf 

 

Many thanks.
Altera_Forum
Honored Contributor I
374 Views

As you main() function is the entry point of your project, everything outside of it is also outside of your project directory. But your project is started through a BSP, which should have been generated when you generated your project. 

With this in mind, you should be able to find alt_main() in  

<BSP-Project>/HAL/src/alt_main.c 

 

Are you using Jtag-uart or altera_uart driver an stdin/out/err?
Altera_Forum
Honored Contributor I
374 Views

Go to Run menu and select Debug... 

Select your target hardware on the left 

Select the Debugger tag in the right pane 

Usually the option "Break at main()" is selected by default; select "Break at alt_main()", too. 

Start Debug: processor should halt at the very beginning of alt_main() 

Step inside the function: probably code hags somewhere during system initialization
Altera_Forum
Honored Contributor I
374 Views

Thanks for feedback. 

 

mcr42 i am using a jtag_uart from SOPC builder. 

 

Cris, i debugeed as you suggested, when i break at alt_main() the debugger starts running and deosnt actually allow for me to step into any code, it displays an error stating 

remote communication error: software caused connection abort. 

 

If i break at program entry point it runs to a thread at location 0x0000000000. If i step into the next instruction i get the following error: 

cannot find bounds of current function. 

 

I have attached a screenshot of my debug panel.  

 

even when tested individually neither the code to driver the leds or the printf work. 

 

hmmmmmmmmmm
Altera_Forum
Honored Contributor I
374 Views

Open sopc builder and Nios II properties. 

Look where Nios reset vector is located. This must be a valid and initialized memory area.
Altera_Forum
Honored Contributor I
374 Views

reset vector ext_flash 0x00000000 

exception vector ext_ssram 0x01000020
Altera_Forum
Honored Contributor I
374 Views

Here is a screen shot of my SOPC design. 

 

I managed to get the LED's flashing with the same code on a small footprint design using only on chip RAM and nothing external. 

I could not use a Jtag debug module in this case and so just flashed the .hex into the FPGA by buidling the C code and then compiling the quartus project. 

 

this makes me think the problem is associated to one of the external memory components.  

 

The SOPC design is from an altera example for my kit - i didnt produce it myself and so do not completely understand the requirment for all of the components. 

 

I really want to have a SOPC design that can handle larger footprint Nios projects up and running. 

 

Any ideas would be welcome.  

 

Ade
Altera_Forum
Honored Contributor I
374 Views

I just tried to debug on the same SOPC design using the count binary template in Nios II. 

 

When trying to break at main() i got the following error: 

 

Nios II Elf Debugger (18/11/10 17:15) (Suspended) <Warning: 

Cannot insert breakpoint 1. 

Error accessing memory address 0x20003b8: Unknown error 4294967295. 

>  

Thread [0] (Suspended)  

1 <symbol is not available> 0x00000000  

 

 

I think there is definetly a problem with the memory configuration with my SOPC design. 

 

Problem being i am not sure where. 

 

Cheers.
Altera_Forum
Honored Contributor I
374 Views

 

--- Quote Start ---  

 

I could not use a Jtag debug module in this case and so just flashed the .hex into the FPGA by buidling the C code and then compiling the quartus project. 

 

--- Quote End ---  

 

I never worked with such a configuration. I think that if you don't have the jtag debug module inside Nios you can't debug anything. 

Try to change something in system library configuration, for example mapping you code into a different memory.
Altera_Forum
Honored Contributor I
374 Views

sorry cris this is a red herring - using this mechinism actually worked, the problem i have is when i DO use a jtag debug module with the larger platform nios project. 

 

I tried running this project in all of the memory locations in the design, but still no joy. 

 

Thanks.
Altera_Forum
Honored Contributor I
374 Views

One question; maybe is just a matter of visualization in the sopc builder picture you posted, since I can't see the complete system. 

I see that altmemddr clock is system_clk but ddr is mastered by the altmemddr_bridge with altmemddr_clk. 

I think this is not correct. You should use altmemddr_clk for ddr, too. Otherwise, why do you need to use the clock crossing bridge?
Altera_Forum
Honored Contributor I
374 Views

Hi digital_ade: 

I meet the same problem with you,can you give me some advices?
Altera_Forum
Honored Contributor I
374 Views

Hi i have some what similar problem. No output on the console from printf. during debug it hits breakpoints and returns from printf() call, but there is no out put. Quartus v15. where in Qsys do you verify/change the reset vector ?

Altera_Forum
Honored Contributor I
374 Views

 

--- Quote Start ---  

Hi i have some what similar problem. No output on the console from printf. during debug it hits breakpoints and returns from printf() call, but there is no out put. Quartus v15. where in Qsys do you verify/change the reset vector ? 

--- Quote End ---  

 

 

Reset vector is chosen under the Parameters tab for the NIOS.  

It is in the Vectors sub-tab. 

 

-Matt
Reply