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

Altera TSE driver and example program for lwIP (1.3.2)

Altera_Forum
Honored Contributor II
14,805 Views

After many many requests and complaints about lack of support and/or documentation for support of lwIP for the Altera TSE, I have developed a drop-in TSE driver and example program and made this available to the NIOS II community. This was done for NIOS II 8.1 SP0.01. I don't expect difficulty with version 9.x. 

 

This is for the latest version of lwIP (the latest is as of this post) for a minimal program and HTTP server based on the http server in the lwIP contrib folder. The lwIP TSE driver uses the altera_avalon_tse driver and SGDMA as-is. There is a complete (as in 41-step) set of instructions on creating the project and example program. More information and the link to the driver is available here: 

 

http://lwip.wikia.com/wiki/available_device_drivers#lwip_1.3.2 

 

Please direct any questions, changes for NIOS II 9.1, or comments to this thread. 

 

12-16-2010 update: This example works with NIOS Version 10.0 with some tweaks to the procedure to create the project. Also, a lwIP 1.4 release candidate has been out for a while and it drops into this example (in place of 1.3) without changes. 

 

Bill
0 Kudos
257 Replies
Altera_Forum
Honored Contributor II
1,931 Views

Bill 

This looks great, but the examples zip file is gone 404 

 

3. Download http://softools.com/download/lwip/lwip_nios_ii_example.zip 

 

test1]$ wget http://softools.com/download/lwip/lwip_nios_ii_example.zip 

--2010-06-21 11:40:12-- http://softools.com/download/lwip/lwip_nios_ii_example.zip 

Resolving softools.com... 68.180.151.73, 68.180.151.106, 68.180.151.111 

Connecting to softools.com|68.180.151.73|:80... connected. 

HTTP request sent, awaiting response... 404 Not Found 

2010-06-21 11:40:12 ERROR 404: Not Found. 

 

 

If you have an alternate link it will really help.
0 Kudos
Altera_Forum
Honored Contributor II
1,930 Views

The link on the Wiki is correct. Maybe you need to flush your cache or force a page reload on the Wiki? I just tried it on FireFox and IE and all went OK. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

This link is in the ReadMe.txt, it may have been old directions. I will try to guess and post back

0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

Oh, sorry, i thought you meant the link on the Wiki :mad: 

 

That link is the file you downloaded! If you have the ZIP, you have everything! 

 

The ReadMe has been updated to reflect that it means the file that you downloaded. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

Bill 

Thanks, that worked nicely. I just tested it on Stratix IV GX FPGA Development Kit (4sgx230). There are a couple of problems with the instructions 

 

1) in step 18 It asks to delete the "contib" directory from the lwip, where I think we should be deleting the "test" directory. The "contrib" directory does not exist but the "test" directory does and causes build errors. 

 

2) Even though you have mentioned it, but failing to initialize hwaddr[0-5] results in build error (probably intentional) 

 

All said, eclipse does not play well with home-grown SOPC components, whereas create-this-app script works correctly. I will try to integrate it with the script so I can use my components. I can post it here if you don't mind.
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

Thanks Ira. Is that also under NIOS II 9.x for you? We have not taken the update plunge to 9.x so I couldn't test. 

 

Yes, it's delete test and not contrib from the ZIP. It's the one thing I didn't do since I had 1.3.2 source already. The ZIP is different. 

 

Also, there's a missing "Click Finish" :) 

 

I wanted the errors because there has to be a MAC address to initialize the driver, unless there is a safe "for testing purposes only" MAC we can use. 

 

Thanks for the feedback! 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

You are welcome. I am using 9.1 SP2 Build 350 on GNU/Linux

0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

Hi BillA, 

Have you heard from anyone who has had success getting this running standalone on the EP3C120 Development Board with Quartus 9.1 sp2 (under windows)? I have proven by signal tap that the 88e1111 phy is properly communicating with the TSE_Mac (at 100MHz) , and the application generates the following: 

Running... 

INFO : TSE MAC 0 found at address 0x0c000400 

INFO : PHY Marvell 88E1111 found at PHY address 0x12 of MAC Group[0] 

INFO : PHY[0.0] - Automatically mapped to tse_mac_device[0] 

INFO : PHY[0.0] - Restart Auto-Negotiation, checking PHY link... 

INFO : PHY[0.0] - Auto-Negotiation PASSED 

INFO : PHY[0.0] - Checking link... 

INFO : PHY[0.0] - Link established 

INFO : PHY[0.0] - Speed = 100, Duplex = Half 

Waiting for link...OK 

IP address: 192.168.0.77" 

 

But nothing seems to be received. I place a breakpoint immediately after 

if (p == null) return "ethernetif_input" ... in an attempt to capture a packet being processed but never get there. 

 

Any advice would be useful.  

 

thanks very much for posting this example ... it is really appreciated! 

 

0 Kudos
Altera_Forum
Honored Contributor II
1,930 Views

Note to previous text ... I am using "Network Packet Generator" to generate Echo Requests, and have validated the correct packetand payload have been receivd and the TSE_Mac statisitcs indicate no error packets and the broadcast packets are corectly being received. 

 

I have tried both the example hardware design available for the board and my own design to no success. No optimisation flags and standard NIOS2. KNown good working DDR2 SDRAM interface design ... running all from same memory. 

 

I suspect maybe something going on with the SGDMA.  

 

Any ideas, or things to try would be much appreciated!
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

 

--- Quote Start ---  

Note to previous text ... I am using "Network Packet Generator" to generate Echo Requests, and have validated the correct packetand payload have been receivd and the TSE_Mac statisitcs indicate no error packets and the broadcast packets are corectly being received. 

 

I have tried both the example hardware design available for the board and my own design to no success. No optimisation flags and standard NIOS2. KNown good working DDR2 SDRAM interface design ... running all from same memory. 

--- Quote End ---  

 

 

So... if you run a standard NIOS II Ethernet demo (like simple socket server) from the IDE it won't receive Ethernet packets? If true this would be either SGDMA (as you say below) or the MAC interface within the rest of the design. Be sure to review sample Ethernet designs because the bridging is required. The PHY is clearly working as seen in the debug output. 

 

 

--- Quote Start ---  

I suspect maybe something going on with the SGDMA. 

--- Quote End ---  

Perhaps. If you can get an example to run, then it lets us know it's this lwIP demo not working. Obviously if a NIOS II demo won't run neither will this lwIP demo. 

 

Oh, I forgot this. Does the following link provide anything useful to you? 

 

http://www.alteraforum.com/forum/showthread.php?t=1575 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,930 Views

Hi! 

Enyone can explain me how to execute the points 26 - 39 of the lwIP 1.3.2 Altera TSE driver for lwIP 1.3.2 ReadMe in NiosII 9.1 EDS? 

The points are: 

26. Select C/C++ Build 

27. Select General 

28. Add Include Path ${workspace_loc:/altera.components/Nios II Software Packages/altera_iniche/UCOSII/inc} 

29. Add Include Path ${workspace_loc:/lwIP_NIOS_II_Example/lwIP/src/include} 

30. Add Include Path ${workspace_loc:/lwIP_NIOS_II_Example/lwIP/src/include/ipv4} 

31. Select Configuration Release from the pull-down 

32. Select Preprocessor 

33. Add Undefined Symbols: LWIP_NOASSERT 

34. Add Undefined Symbols: LWIP_ERROR 

35. Select General 

36. Add Include Path ${workspace_loc:/altera.components/Nios II Software Packages/altera_iniche/UCOSII/inc} 

37. Add Include Path ${workspace_loc:/lwIP_NIOS_II_Example/lwIP/src/include} 

38. Add Include Path ${workspace_loc:/lwIP_NIOS_II_Example/lwIP/src/include/ipv4} 

39. Select Configuration Debug from the pull-down 

 

Sorry, but I'm new and thanks for help!
0 Kudos
Altera_Forum
Honored Contributor II
1,930 Views

Well, you need to do step 25 and you'll see "C/C++ Build" mentioned in step 26. 

 

25. right-click project lwip_nios_ii_example and select properties 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,930 Views

Thank you for your reply Bill! 

The point 25 is obvious, but after i don't know shere include this paths: 

28. Add Include Path ${workspace_loc:/altera.components/Nios II Software Packages/altera_iniche/UCOSII/inc} 

29. Add Include Path ${workspace_loc:/lwIP_NIOS_II_Example/lwIP/src/include} 

30. Add Include Path ${workspace_loc:/lwIP_NIOS_II_Example/lwIP/src/include/ipv4} 

 

Under C/C++ option there are many options, and I think that the correct one is the "Path and Symbols". But there are many tabs, like "Includes", "Library path", "References", ... Which is the correct one?! 

And then: where I can find the "Configuration Release" form point 31: 

31. Select Configuration Release from the pull-down? 

And why the points 27-30 are egual to points 35-38? 

 

Thanks!!! Have a nice day!
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

 

--- Quote Start ---  

Thank you for your reply Bill! 

--- Quote End ---  

 

 

You're welcome. 

 

 

--- Quote Start ---  

 

The point 25 is obvious, but after i don't know shere include this paths: 

28. Add Include Path ${workspace_loc:/altera.components/Nios II Software Packages/altera_iniche/UCOSII/inc} 

29. Add Include Path ${workspace_loc:/lwIP_NIOS_II_Example/lwIP/src/include} 

30. Add Include Path ${workspace_loc:/lwIP_NIOS_II_Example/lwIP/src/include/ipv4} 

 

Under C/C++ option there are many options, and I think that the correct one is the "Path and Symbols". But there are many tabs, like "Includes", "Library path", "References", ... Which is the correct one?! 

--- Quote End ---  

Stay on "Tool Settings" tab. 

Use General for Nios II Compiler 

You'll see Include paths. Use the Add button. 

 

 

--- Quote Start ---  

 

And then: where I can find the "Configuration Release" form point 31: 

31. Select Configuration Release from the pull-down? 

 

--- Quote End ---  

Right above the tabs in this same dialog. 

 

 

--- Quote Start ---  

 

And why the points 27-30 are egual to points 35-38? 

 

--- Quote End ---  

Because you need the include paths for Debug and Release builds. 

 

 

--- Quote Start ---  

 

Thanks!!! Have a nice day! 

--- Quote End ---  

Thank you - you do the same. :) 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

Hi guys. 

I am still trying to use the example, which has been uploaded by BillA (thank you very much), but i am in trouble. Finally,i know the port number to connect.But, as i understand,this example is low-level example.I mean,that the packets, which i catch, i catch them not on Transport layer(TCP, UDP).I catch them on IP layer or even ARP.  

Is it correctly? 

Another question. As i understand, i catch the packet in "ethernetif_input" function and i am trying to watch with breakpoints the content of packet, but i do not see nothing. 

What am i doing not correctly? 

 

Thanks,Slava.
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

 

--- Quote Start ---  

Hi guys. 

I am still trying to use the example, which has been uploaded by BillA (thank you very much), but i am in trouble. Finally,i know the port number to connect.But, as i understand,this example is low-level example.I mean,that the packets, which i catch, i catch them not on Transport layer(TCP, UDP).I catch them on IP layer or even ARP.  

Is it correctly? 

--- Quote End ---  

 

 

You're welcome (for the example). You catch the packets you want by specifying the callback. For example, if you call tcp_recv you will be called back with data as it arrives from the connection on the pcb. There is also udp_recv and raw_recv if you want those callbacks. raw has to be enabled with a# define and only it will allow seeing all packets. I've never had reason to use this. 

 

 

--- Quote Start ---  

 

Another question. As i understand, i catch the packet in "ethernetif_input" function and i am trying to watch with breakpoints the content of packet, but i do not see nothing. 

What am i doing not correctly? 

 

--- Quote End ---  

If you put breakpoint on: 

 

ethhdr = p->payload; 

 

and it doesn't stop here, then you are not receiving packets. Run in Debug build and look at the PHY output messages to be sure the PHY initializes OK. If you get through that, I would expect the TSE to be OK but if it won't breakpoint you're not getting any packets. You should see broadcast packets at all times so if you're on a network you should see packets without doing anything. If you are direct to a PC I still think you see a few broadcasts. 

 

BillA
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

Hi! 

 

Many thanks to Bill for useful example and step-by-step pass-throw. I successfully compiled lwIP_NIOS_II_Example in EDS 10.0. A couple of minor issues I faced with: 

1) steps 25-40. I tried to set paths and symbols through the GUI, but this didn't work. The workaround was to edit lwIP_NIOS_II_Example/Makefile manually. Also, to get “INFO” output like in Readme.txt ALT_DEBUG must be defined for lwIP_NIOS_II_Example_bsp project. 

2) TSE-related components in SOPC must have standard names: 'tse_mac', 'sgdma_tx', 'sgdma_rx' and 'descriptor_memory'. If different names are used the code successfully compiles, but does not function. 

 

Without any modifications the example runs on DBM3C40 devboard (Cyclone III + Marvell 88E1119R PHY) at 100Mbit. It gets address via DHCP and serves nice html page from port 80. 

 

Unfortunately the board hangs at DHCP stage if I plug it into 1000M network. The output is following: 

INFO : TSE MAC 0 found at address 0x00002000  

INFO : Multi Channel = No  

INFO : MDIO Shared = No  

INFO : MAC Type = 10/100/1000 Ethernet MAC  

INFO : MAC Address = 0x00002000  

INFO : MAC Device = tse_mac_device[0]  

ERROR : MAC Group[0] - No PHY connected!  

ERROR : PHY[0.0] - No PHY connected! Speed = 100, Duplex = Full  

Waiting for link...OK  

Waiting for DHCP IP address...  

 

I suspect that 1000M operation or autonegotiation must be configured somehow, but I have zero experience in Ethernet development and don't know how to move on. Any help will be appreciated. 

 

Thank you in advance, 

Igor
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

Thank you for your reply.regarding to second question: it works exactly as you have described. 

 

 

--- Quote Start ---  

You're welcome (for the example). You catch the packets you want by specifying the callback. For example, if you call tcp_recv you will be called back with data as it arrives from the connection on the pcb. There is also udp_recv and raw_recv if you want those callbacks. raw has to be enabled with a# define and only it will allow seeing all packets. I've never had reason to use this. 

 

 

--- Quote End ---  

 

Regarding to the first question: 

As i understand, i must to specify the callback function. 

At which stage do i must to do it? 

In your code(example),as i uns=derstand, i must to insert reading function where i put stars.Is it correct? 

 

// Process lwIP timer dependent code 

if(lwipProcessTimerFlag) 

lwipProcessTimers(); 

// Poll lwIP for incoming packets. 

ethernetif_input(&alteraTseNetif);  

*************************** 

Where i puted the stars, do i must to specify the callback function?
0 Kudos
Altera_Forum
Honored Contributor II
1,931 Views

 

--- Quote Start ---  

Hi! 

Unfortunately the board hangs at DHCP stage if I plug it into 1000M network. The output is following: 

INFO : TSE MAC 0 found at address 0x00002000  

INFO : Multi Channel = No  

INFO : MDIO Shared = No  

INFO : MAC Type = 10/100/1000 Ethernet MAC  

INFO : MAC Address = 0x00002000  

INFO : MAC Device = tse_mac_device[0]  

ERROR : MAC Group[0] - No PHY connected!  

ERROR : PHY[0.0] - No PHY connected! Speed = 100, Duplex = Full  

Waiting for link...OK  

Waiting for DHCP IP address...  

 

--- Quote End ---  

 

 

In altera_avalon_tse.h try changing the# define for ALTERA_CHECKLINK_TIMEOUT_THRESHOLD to 5000000 

 

 

--- Quote Start ---  

 

I suspect that 1000M operation or autonegotiation must be configured somehow, but I have zero experience in Ethernet development and don't know how to move on. Any help will be appreciated. 

 

--- Quote End ---  

I think perhaps it's timing out before it negotiates? You can also try increasing the other timeouts in this header file (in the same location of the file). 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,674 Views

 

--- Quote Start ---  

Thank you for your reply.regarding to second question: it works exactly as you have described. 

 

 

Regarding to the first question: 

As i understand, i must to specify the callback function. 

At which stage do i must to do it? 

In your code(example),as i uns=derstand, i must to insert reading function where i put stars.Is it correct? 

 

// Process lwIP timer dependent code 

if(lwipProcessTimerFlag) 

lwipProcessTimers(); 

// Poll lwIP for incoming packets. 

ethernetif_input(&alteraTseNetif);  

*************************** 

Where i puted the stars, do i must to specify the callback function? 

--- Quote End ---  

 

 

This http code in this example is also an example that shows how to handle the callback from accept and how to set the tcp_recv. It also shows how to process received data. You should model any code that will make a connection and send and receive data like this one does. 

 

Bill
0 Kudos
Reply