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

using open() C command in the Nios II

Hi, 

can we used open() and printf() C commands to save stream of data in the Nios II? 

when I used fp=open() Command, it send Null to fp pointer.How can I store my integer data? 

Thanks
0 Kudos
13 Replies
Altera_Forum
Honored Contributor I
77 Views

I'd write any data or logging info directly to standard output. I use the logging feature of PuTTy to capture the data. fopen isn't needed.

Altera_Forum
Honored Contributor I
77 Views

Dear Galfonz, 

Can you clarify your idea for me ? How i should use puTTy to capture data? whether the puTTy capture data after using printf() function of stdio.h? 

what software do i need? can you upload it for me?  

Thanks
Altera_Forum
Honored Contributor I
77 Views

PuTTY is a serial terminal emulator. Google "PuTTY download" to find it. This one works fine for me but there are several others. 

 

Your dev board probably has a hello, world example. Get that running. Then replace that software with your own code. Write you data to standard output using printf. Look at the PuTTY (or other terminal emulator) documentation to find out how to log console output to a file on your PC. Just be sure you don't write data faster than the serial port can handle. Slow down if you start missing characters. 

 

You can then use excel, matlab, etc to analyze your data.
Altera_Forum
Honored Contributor I
77 Views

ok. when I captured data using HyperTerminal, I saw some jump in my data. I think my serial port have a problem. So I want to log data using open and printf. because I think by this method that serial port do not involved. what is your opinion ? in this state puTTy is similar to HyperTerminal and it do not help me.  

t
Altera_Forum
Honored Contributor I
77 Views

For open and write/printf to work you need a file system. The NIOS II does not have a file system unless you include some storage device and a device driver for it. You can either log the data on the serial port as suggested. Another alternative is to use the JTAG serial port if your real serial port have issues as you described (or try to lower the serial port speed to see if it helps). Another method would be to include some serial file transfer protocol which includes error check and retry, e.g. kermit or x/y/zmodem.

Altera_Forum
Honored Contributor I
77 Views

When you see dropped characters, it is due to bytes being written to the serial port faster than they are output at the baud rate the port is using. At some point the FIFO will fill up and you will start losing characters. If just a few bytes are missing you could try raising the baud rate. Otherwise insert delays in your code, after every data line, or after every byte if you UART has a small FIFO. You could also see if your UART (including its driver) and USB<->serial chip implement hardware or software based flow control. See an RS232 tutorial for more info.

Altera_Forum
Honored Contributor I
77 Views

Thanks all. Mr. Peter i want to log data using Jtag UART. if it is not possible (I can not open a file and write to it), i should fix my UART port.Have you an idea?

Altera_Forum
Honored Contributor I
77 Views

The JTAG UART works just like a regular UART, but is using the JTAG connection, e.g. your USB Blaster. Note that the JTAG UART is quite slow. If you generate data faster than your UART is running you will experience data loss due to overrun. Check that your UART is fast enough to handle your data rate. You can enable the JTAG UART in your NIOS software. 

 

Check by lowering the speed of your real UART if you're having signal integrity problems. If it gets worse you're problem might be related to overruns.
Altera_Forum
Honored Contributor I
77 Views

Thanks Peter. I want to store up to 4-byte data per 1ms (or 32000bps). I think that i will not experience data loss. now my problem is Error by opening a file by command fopen(). But we can able to use New lib C Commands (fopen()) according to Nios II Software Developer’s Handbook. what is my mistake?

Altera_Forum
Honored Contributor I
77 Views

That should work if you capture binary data. But if you convert to ASCII (printf("%x")) you need 10 times the binary generation rate, which will exceed 115200 (I don't know what your actual UART rate is). 

 

In order to use fopen and fwrite your system must have some kind of storage and a driver interface to the storage.
Altera_Forum
Honored Contributor I
77 Views

In addition to the fopen() call in Newlib, you need a file system behind it, and a block device (sd card) behind that. All of that hardware, software and data must be in place and integrated together before the fopen() call will actually do what you expect. Typically this is handled by an operating system (Linux, Windows embedded, VxWorks, etc). In a bare metal situation you need to get all that code and integrate it together. Usually it's easier to just use a UART if the data rate is slow enough. 

 

You can write binary bytes to your UART if instead of PuTTy etc or system console for the JTAG UART, you run a program or script on your PC to capture binary bytes. Watch out for garbage characters transmitted at power-up. 

 

Don't forget to account for the start and stop bits. You are actually sending 10 bits serially for every byte given to the UART. I don't know if the JTAG UART can keep up at that rate.
Altera_Forum
Honored Contributor I
77 Views

Ok. many Thanks for your assistance Mr. Galfonz .

Altera_Forum
Honored Contributor I
77 Views

Altera supplies the "Host-Based File System" (altera_hostfs) that allows your NIOS HAL-based software to fopen()/fwrite() files that reside on your PC (while connected through JTAG, obviously). You can use this for the temporary kind of logging/debugging it sounds like you are trying to accomplish. 

 

The Altera System Console also provides services for transferring data to/from your target which may be better suited if you are trying to construct an in-hardware test environment. See http://www.alterawiki.com/wiki/system_console_byte_stream_example for one example.
Reply