Creating a Webserver on the Nios development kit Stratix Edition board Enoch Hwang A) Creating the Nios System (Nios v3.2 can only work with Quartus II v5.1 and below. Need to also remove Nios II completely.) 1) Use the standard_32 reference Nios template design in the directory: D:\My_Programs\Altera\Nios Board\standard_32 2) Use Quartus II and SOPC Builder. Must use the Nios module and not the Nios II module. Compile the Nios system and generate a.hexout output file. To generate a.hexout file from Quartus: select menu Assignment Device Device & Pin options button Programming Files tab Check the hex output file. 3) Download the Nios system to the FPGA using Quartus II with the ByteBlaster parallel cable. (This is volatile. Go to step (4) if you want non-volatile) 4) Start the Nios SDK Shell from Windows Start menu. The following commands are issued from this Shell. 5) To save the Nios system in flash so that when you power up the board, the FPGA will automatically be configured with this Nios system, you need to use hexout2flash to convert the.hexout file generated by Quartus to.flash. Issue the hexout2flash command from the SDK Shell monitor. [SOPC Builder]$ hexout2flash -b 0x600000 standard_32.hexout 6) Now download the FPGA configuration data to the user portion of the flash memory at 0x600000. Press the SW0 and CPU Reset on the Nios board first. (All the LEDs on the 7- segment should lit). Need to connect the serial cable from the PC s serial port to the Console port on the Nios board. [SOPC Builder]$ nios-run standard_32.hexout.flash or [SOPC Builder]$ perl -x c:/altera/kits/nios/bin/nios-run.pl standard_32.hexout.flash Notes: i) Start the GERMS monitor (Nios terminal mode) from the Nios SDK Shell by pressing SW0 and CPU Reset on the Nios board (All the LEDs on the 7-segment should lit) and then typing nr t in the SDK Shell. Need to connect the serial cable from the PC s serial port to the Console port on the Nios board.
ii) iii) Press the Reset Config (SW10) switch to configure the FPGA with the User configuration data stored in 0x600000. If no valid user configuration is found, then the FPGA will be configured with the Safe image. To erase sectors in the flash memory, issue the e command from the GERMS monitor: e00600000 e00610000 B) Writing the Web Server Program in C 1) Use the template program nedk_example_web_server.c in the directory: D:\My_Programs\Altera\Nios Board\standard_32\cpu_sdk\src\plugs\webpage 2) Edit the c program using a text editor. The memory map, Nios I/O device pin names (e.g. na_led_pio) are defined in the file <CPU_name>_sdk/inc/excalibur.h. For example, F:\Nios\standard_32\cpu_sdk\inc\excalibur.h. 3) Start the Nios SDK Shell from Windows Start menu. The following commands are issued from this Shell. 4) Compile the web server program from.c to.srec. [SOPC Builder]$ nios-build wosfs.c nedk_example_web_server.c 5) (optional) convert the web server program from.srec to.flash. The C program is stored in flash starting at location 0x40000. [SOPC Builder]$ srec2flash nedk_example_web_server.srec 6) Start the GERMS monitor (Nios terminal mode) on the Nios board by pressing SW0 and CPU Reset on the Nios board. All the LEDs on the 7-segment should lit. 7) Download the web server program to SRAM and run it (if you performed just step (4)) [SOPC Builder]$ nios-run nedk_example_web_server.srec or download to flash (if you performed step (5)) [SOPC Builder]$ nios-run nedk_example_web_server.flash 8) Press Reset Config (SW10) to run the program. The program that is stored in flash will first be copied to SRAM before it is run. C) Creating the Webpages 1) The sample directory is in: D:\My_Programs\Altera\Nios Board\standard_32\cpu_sdk\src\plugs\webpage
2) Edit wosfs_maker.pl first line should be #!/bin/perl 3) To change the location where the webpages are stored in flash: Edit wosfs_maker.pl. Change the two lines in the file to the address that you want my $kwosfs_flashbegin = 0x200000; my $kwosfs_flashend = 0x400000; 4) The definition in the web server program for where the webpages are stored is found in wosfs.h. Edit the two lines #define nk_wosfs_flash_begin (nasys_main_flash + 0x200000) #define nk_wosfs_flash_end (nasys_main_flash + 0x400000) 5) Create standard webpages. 6) Convert webpages to wosfs format Run wosfs_maker.pl from the Nios II SDK Shell. (First change directory to the directory containing the webpages.) [SOPC Builder]$./wosfs_maker.pl index.html static_page.html exc-nios.gif template_page.html.template control_page.html LSU.gif 404_page.html monkey.jpg > pages.flash 7) Connect a serial cable between COM1 on the computer and the Console port on the Nios board. 8) Start terminal mode on the Nios board by pressing sw0 and cpu reset on the Nios board. 9) Download the webpages to flash using the Nios SDK Shell prompt. Type nios-run from the Nios II SDK Shell [SOPC Builder]$ nios-run pages.flash or [SOPC Builder]$ perl -x c:/altera/kits/nios/bin/nios-run.pl pages.flash 10) Press cpu reset button (or Reset Config button) to run the server program. If you have connected a serial cable between the COM1 port on the PC and the Console port on the Nios board, and you have started the nios-run in terminal mode nios-run t You should see a message in the terminal window saying what the IP address is and the port number.
11) Test web server by browsing to http://192.168.1.31:81 12) Several ways to change the IP address: i. Start up the Safe configuration. Browse to it and click on the link that says IP Address. ii. Run the hello_plugs.srec program located in standard_32\cpu_sdk\src\plugs from the SDK Shell nb hello_plugs.c nr hello_plugs.srec 13) To change the port number: Edit the file nedk_example_web_server.c and change the line #define k_http_port 81 Follow the instructions in section B) to re-compile and download the program. 14) To find out the IP information, type xip from the GEMS SDK Shell + xip To disable DHCP + xdhcp:off To change the IP address + xip:10.1.31.23 To erase a flash sector: e60000 Flash Memory Map Address (hex) Flash Allocation 000000 040000 User Web server program 100000 200000 User Web pages (2 MB) 300000 400000
500000 600000 User FPGA Configuration Data (1 MB) 700000 Safe FPGA Configuration Data (1 MB) 7B0000 Safe Web server program 7F0000 Network settings