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++
12590 Discussions

Standard stdout through JTAG

Altera_Forum
Honored Contributor II
1,518 Views

I am interested in build the following environment through Nios II. 

 

Through a proper Qsys system, i.e., JTAG included, it is possible to use printf commands to be echoed in the Nios Console. 

 

Based on this, I suppose it is possible to redirect the standard output to a file and use the fprintf command to register some results I am looking for inspect during some loops.  

 

Is this possible? If 'yes', where can I find a documentation which can help me?
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
499 Views

This file I mentioned must be located in the PC.

0 Kudos
Altera_Forum
Honored Contributor II
499 Views

You are looking for the "host based filesystem". In the BSP editor, I believe it is a software package you can add. There is an example on the alterawiki site.

0 Kudos
Altera_Forum
Honored Contributor II
499 Views

 

--- Quote Start ---  

You are looking for the "host based filesystem". In the BSP editor, I believe it is a software package you can add. There is an example on the alterawiki site. 

--- Quote End ---  

 

 

 

Thanks ted
0 Kudos
Altera_Forum
Honored Contributor II
499 Views

I thought it is not necessary to open a new thread because this post is problem-related. 

 

To configure my bsp file system: 

 

  • At the BSP Editor, I enabled the hostfs, leaving the /mnt/host as the default and clicked at the generate button 

  • After this, I right-clicked my bsp project, went to the Nios option, and perfomed the generate/compile (I don´t remember exactly) command 

  • And, finnaly I compiled my code with success 

 

 

My problem: my simple example-program only runs in debug, i.e., using step-over I can run the program until its end. It is also possible to see the myfile.txt at my /software/my_proj directory 

 

But, running directly, it freezes after the "before open" message. During the execution or after aborting it, I can´t see any myfile.txt in the directory previously mentioned. 

 

My .c code is: 

 

# include <stdio.h> # include <string.h> int main() { char *msg = "hello to file"; FILE *fp; printf("before fopen...\n"); /* it freezes here */ fp = fopen("/mnt/host/myfile.txt", "w"); printf("after fopen\n"); if(fp != NULL){ printf("inside if...\n"); fprintf(fp, "%s", msg); fclose(fp); printf("file closed\n"); } else printf("Error during opening file\n"); printf("Hello from JTAG CONSOLE Nios II!\n"); return 0; }  

 

any tip why i only can run via debug and can´t run directly?
0 Kudos
Altera_Forum
Honored Contributor II
499 Views

I'm not sure what you are referring to and what is different for you between "via debug" and "run directly" ? 

 

The host filesystem is using the debugger / JTAG to do the communication that happens during the file operations, so you can't ever run it without being connected and running through the debugger.
0 Kudos
Altera_Forum
Honored Contributor II
499 Views

 

--- Quote Start ---  

I'm not sure what you are referring to and what is different for you between "via debug" and "run directly" ? 

 

The host filesystem is using the debugger / JTAG to do the communication that happens during the file operations, so you can't ever run it without being connected and running through the debugger. 

--- Quote End ---  

 

 

thank you for your time. 

 

I will try to be clearer than before. Please, check if now it is understandable. 

 

running "directly" I was refererring when I click over my project, right-click it, select "Run As" and choose Nios II. This makes the progam to be executed non-stopable, non-step-by step. When I choose this option, the program freezes, as previously described. 

 

runnig via debug is when I select debug on the menu, the debug environment is opened, and I click at the F6 (step over) and execute each one of the commands that exist on the .c code. Choosing this way, I can run, step-by-step my code with sucess, as I mentioned before. The proof is that after the execution, the myfile.txt is created and contains the "hello to file" message. 

 

In both cases all environment is prepared, i.e., my jtag is connected, the hardware is already with the .sof file, etc.
0 Kudos
Altera_Forum
Honored Contributor II
499 Views

The documentation for the host file system says: 

 

--- Quote Start ---  

 

The host-based file system only operates while debugging a project. It cannot be used for run sessions. 

 

--- Quote End ---  

 

 

Using "Run As" is probably exactly what they are referring to when they say it cannot be used that way. So, don't do that.
0 Kudos
Altera_Forum
Honored Contributor II
499 Views

 

--- Quote Start ---  

The documentation for the host file system says: 

 

 

Using "Run As" is probably exactly what they are referring to when they say it cannot be used that way. So, don't do that. 

--- Quote End ---  

 

 

 

oopps, sorry! 

https://www.altera.com.cn/zh_cn/pdfs/literature/hb/nios2/n2sw_nii52004.pdf, p. 6-15, third feature/restriction. I found it. 

 

Thank you again, ted
0 Kudos
Reply