How to burn a binary file to flash in niosii

Source: Internet
Author: User

We can use the flash burning and writing function in the nioshi II to solidify the FPGA.ProgramAnd system parameters. What if we want to separately burn system parameters? It is to write binary data in the idle area of flash or Apsara stack. In the software, we can read the data in flash. How can we burn useful data. The following is an example.

First, you must understand the differences between binary files and text files.

We all know that computer storage is physically binary, soThe difference between a text file and a binary file is not physical, but logical. The two are only different at the encoding level.
To put it simply:

Text files are character-encoded files. Common encodings include ASCII and Unicode.

Binary files are value-encoded files. You can specify the meaning of a value based on the specific application.).

From the above we can see that text files are basically fixed-length encoding. Based on characters, each character is fixed in the specific encoding, And the ASCII code is 8 bits, unicode generally occupies 16 bits.

The binary file can be regarded as a variable-length encoding, because it is a value encoding. It is up to you to decide how many bits represent a value.

Take it easy to understand and understand data operations.

 

If you manually add "10 20 30" to the new TXT file, select program a file into flash memory on the niosii burn-on interface, as shown in.

 

 

Select the TXT file to be written, and select the device to be written, Flash, or Apsara stack. The experiment I did was performed on the PV, without flash. I think flash should also work. The last step is to specify the offset to avoid overwrite data.Code.

So what is the data read during testing in the software? Do We Need 10 20 30? The answer is no. The read data is 49 48 32 50 48 32 51 48. What is the relationship between the data we read and the data we previously wrote? In fact, when writing, it is based on characters. The ASCII value corresponding to the character "1" is 49, and the rest are in turn. In this way, we do not store the values we want to store. It is mainly about the data format.

So how can we burn it right? First, we need to store these values in binary format. My practice is to convert them using file operations in C language. (I don't know if there are any other simple practices. You are welcome to discuss them .) The Code is as follows:

 1 # Include <stdio. h>
2 # Define Size 2
3 Char A [size] = { 0 };
4 Struct Data {
5 Int Num;
6 } Da [size];
7
8 Void Save ()
9 {
10 File * FP;
11 Int I;
12 /*
13 Fp = fopen ("data.txt", "rb ");
14 For (I = 0; I <size; I ++)
15 {
16 Fread (& Da [I], sizeof (struct data), 1, FP );
17 Printf ("% 4D", DA [I]. Num );
18 }
19 */
20 If (FP = fopen ( " Data.txt " , " WB " ) = NULL)
21 {
22 Printf ( " Cannot open file \ n " );
23 Return ;
24 }
25 For (I = 0 ; I <size; I ++)
26 If (Fwrite (& Da [I], Sizeof ( Struct Data ), 1 , FP )! = 1 )
27 // If (fwrite (& A [I], 1, 1, FP )! = 1)
28
29 Fclose (FP );
30
31 }
32 Void Main ()
33 {
34 Int I;
35 For (I = 0 ; I <size; I ++)
36 Scanf ( " % D " , & Da [I]. Num );
37 // Scanf ("% C", & A [I]);
38 Save ();
39
40 }

Code Description:

Row 35 and 36: The input value is included in the variable;

20th rows ~ Row 29th: open the file in a binary format, and write the value in the variable to the TXT file. The most important thing is the 20th line. "WB" indicates opening a binary file for the output. You can query other file usage methods.

Run the program. Enter 10 20 30 and then press Enter. After running the program, the data.txt file in the software project is found to be garbled and should not be in a panic. This indicates that the above Code has taken effect. We can read it in binary format to see if it is the number we entered before. Convert 20th rows ~ Line 3: unregister the code at line 35 and Line 36. Open Line 3 ~ Run the 19th lines of code and we can see the required values. For example.

Now, let's test how to burn the data.txt file into FPGA.

In the code of niosii, read the Flash (EPC), extract the stored values, and assign values to int-type data. In this way, external values can be used in the code. For flash operations, the code will not be detailed here. If you need it, you can discuss it together.

Here, I would like to thank Hao from the lab. Now, let's summarize it here.

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.