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

Altera TSE driver and example program for lwIP (1.3.2)

Altera_Forum
Honored Contributor II
18,634 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,008 Views

Hi rapa, 

 

I am facing the same problem what u hv faced. 

 

I followed whatever mentioned in the link, u provided in last mail for rgmii interface with tse mac. 

I am also using Cyclone III Development Kit board and I am not able to ping the board.  

I do not see any packets from the board in the network(using TCP/IP sniffer) and no activities on TxD line.  

When I tried to connect PC to board(on sniffer I see it as a broadcast at ARP level.) 

Please help. 

 

The output is following: 

Running... 

INFO : TSE MAC 0 found at address 0x10022800 

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 

MARVELL : Mode changed to RGMII/Modified MII to Copper mode 

MARVELL : Enable RGMII Timing Control 

MARVELL : PHY reset 

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

INFO : PHY[0.0] - Link not yet established, restart auto-negotiation... 

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

INFO : PHY[0.0] - Auto-Negotiation PASSED 

INFO : PHY[0.0] - Link established 

INFO : PHY[0.0] - Speed = 1000, Duplex = Full 

Waiting for link...OK 

IP address: 172.194.11.100 

 

is there any other considerations that I hv to take for rgmii interface or any other issues? 

 

please help me out.... 

 

Best regards and many thanks to all the guys for providing lot many info... 

0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

hi all... 

 

I got it working..Just I followed the contents of the earlier post link,correctly. 

 

bye..
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Hi All, 

Went through the build and upon execution I see 

 

Running... 

 

and nothing else. Playing with it (get this) I copied thje printf that puts running on the screen and only get 1 line - removal of the "\n" character gives me 

 

Running...Running... before it hangs. 

 

can anyone give ma an idea of WHAT could be going on here? 

 

Chris
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Chris, 

 

Are you using 10.0 and using the VIC? With a new design using lwIP we're using 10.0SP1 and I'm trying to get some form of this demo running. Right now I'm just getting our configuration side ironed out because it's not running as-is - but it could be the SOPC side of things. 

 

If you have design the VIC in, it might run if you disable it in the BSP editor. A user did report this runs in 9.0 so I suspect there might be a VIC compatibility issue (assuming he didn't use the VIC - if he did then it should run as-is). If there is a problem in the lwIP driver I'll update this demo ASAP as I need lwIP for the new product using 10.0 and the VIC. 

 

Thanks, 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Hi Bill 

I'm in 9.1 SP2 - I am not using the vectored interrupt controller... this is very strange... I did have to jump through hoops to get the image to build, changing paths to point to my .h files explicitly...
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Hi Chris, 

 

I think I need to update this demo to fit the 9/10 SBT model, since the current demo is in CDT mode. 

 

If you create a blank project in 9.x/10.x and import lwip and the files in this example, you'll have an SBT project. Use NIOS II Application Paths in NIOS II Application Properties to add the arch, src/include, and src/include/ipv4 include paths (browse to them if I have it wrong here) and it will build. I've done this already and can build and run the example as-is in 10.0SP1 with a SOPCINFO that does not have the VIC (which is why I think there may be or is a VIC issue). 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Hi Bill, 

 

I have the example building and am farther along (until I started to add the Broadcom switch that I am interfacing to via rgmii I was seeing running... listening............ 

 

I take it that that is a good sign... anyway I am looking to port this demo application to run under ucosII in UDP mode for performance - was wondering if you knew around which time frame Altera moved their socket server example from lwip to the interniche codebase and if it was a ucosII implimentation. I have the url of the altera code dump (having all code from god knows when till now...) I was hoping you could give me a timeframe I might look thru instead of wading thru downloads.  

 

Thanks - best crayner
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Hi Chris, 

 

From memory, version 8.x and later were shipped with InterNiche with "lwIP no longer supported". I've seen posts that lwIP was in version 7.x but I've not seen it - I started with 8. 

 

For best performance, use lwIP in RAW API mode. Since lwIP needs an RTOS for the Netconn and Socket APIs and has to use message posting to exchange data, lwIP is not very efficient with these APIs and an RTOS. In fact, it's a rule that lwIP be used only in one thread. Now, you can put lwIP in one uC/OS-II thread and use raw API mode, but you can't send data without some mechanism for that thread to grab the data to send. As receiving is normally done with callbacks, by default you're in the lwIP thread and the callback can send data directly. 

 

I use a cooperative RTOS which is much safer and because it's cooperative I can have other threads send data to the stack (because the lwIP thread isn't in the lwIP code at those times). Probably with a Mutex around *all* lwIP calls you can use a preemptive RTOS and keep it threadsafe. Once you move to message boxes to get and send data to the stack, it slows way down. 

 

Hope this helps! 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Hi Bill, 

I just wanted to report success on Quartus 10.1, Nios II EDS 10.1, with your driver implementation of lwIP (1.3.2). This is on a custom board. 

 

It almost worked out of the box - steps 25-39 are somewhat different, since the interface is different (either use Makefile to update project Includes manually, or use Nios II Application Paths under Project->Properties). I have to report that for some reason some relative paths no longer work under EDS 10.1, so I've used absolute path to the project directory (otherwise I get errors while compiling - header files under lwip/src/... don't see header files from the project directory (?!?) - this worked nicely on 9.1sp2). 

 

I also had to add the support for Marvell 88E1119 manually, since it's still not supported by Altera. Well, off to integrate RTP/RTSP protocols for it. 

Thanks, best regards, 

 

Ivan
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Thanks Ivan. I will update this example to use the SBT (not CDT as it is for 8.x). I also added a CUSTOM_PHY# define to the example to allow adding an unsupported PHY(e.g. 88E1119 as you pointed out) to the program. Maybe I should just leave it in for all builds since adding PHY is not a problem if it's not used. 

 

You can also replace lwIP with version 1.4 (which is out as a release candidate) and it builds and runs without problems. 

 

By the way, our Cyclone-based products also use the 88E1119 as it was used on the demo board we evaluated. 

 

Thanks again for the feedback. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Thanks for the advice Bill. Seems that other people are getting a bit better speeds with 1.4.0, especially when combined with UDP (which I'll probably use under RTSP/RTP), so will do. The speed is my main concern... and I know lwIP is not exactly a speed champion, but let's hope that it can beat the previous design we had. 

Anyway, thanks for the advice again. I'll be probably using both versions for the first time and check for any major differences. I'll post back if anything important pops out. 

 

Ivan
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Ok, just wanted to post my experience with 1.4.0 rc. 

 

Well, not really a drop in replacement - few things need to be updated in lwipopts.h, since I had an error with NO_SYS_NO_TIMERS (which is defaulted to 0, but should be 1). Other than that, they have split the tcp.h to tcp.h and tcp_impl.h, which both need to be included in your main.c file. 

 

Other than that, it's running better - I don't know for anyone else, but my lwip 1.3.2 UDP implementation had major problems with IP addresses (IP layer did not forward them to the transport layer correctly - ie on callback it always forwarded its own IP instead of the IP from remote host (?!?) ). However, I did change a lot of things and this might have caused this behavior (but than again, 1.4.0 works perfectly with the same changes). 

 

Who knows? Just wanted to update if someone has the same problems. 

 

Ivan
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

Hi bill 

my hw is cyclone3 + lan8700(phy), sw is Quartus 9.0 sp2 ,nios 9.0 , but can not connect to the phy.I debug the MDC ,MDIO ,there is clock about 1M Hz in MDC ,but there is no signal in the MDIO pin , so what should i do?
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

The first thing would be to check the PHY chip pins, mostly the power supplies and the clock. 

But there must be something wrong with your FPGA design, as you should at least get something on the MDIO line coming from the FPGA... Are you sure that the network driver is actually trying to talk to the PHY? Check how you connected the 3 MDIO signals from the TSE to the MDIO pin. You should have a bidirectional buffer, with the output enable at the correct polarity.
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

thanks daixiwen 

I have linked the PHY,for print 

INFO : TSE MAC 0 found at address 0x08003800 

INFO : PHY National lan8700 found at PHY address 0x1f of MAC Group[0] 

INFO : PHY OUI = 0x0001f0 

INFO : PHY Model Number = 0x0c 

INFO : PHY Revision Number = 0x4 

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] - 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 = Full 

 

but can not run for next step, so there is a question. how to set mac ,as your list 

42. Edit alteraTseNetif.hwaddr[0-5] lines 78-83 with your board's MAC address 

so I edit it as follow 

alteraTseNetif.hwaddr[0] = 0x00; 

alteraTseNetif.hwaddr[1] = 0x1C; 

alteraTseNetif.hwaddr[2] = 0x23; 

alteraTseNetif.hwaddr[3] = 0x17; 

alteraTseNetif.hwaddr[4] = 0x4A; 

alteraTseNetif.hwaddr[5] = 0xCB; 

if i missed something?
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

 

--- Quote Start ---  

 

but can not run for next step, so there is a question. how to set mac ,as your list 

42. Edit alteraTseNetif.hwaddr[0-5] lines 78-83 with your board's MAC address 

so I edit it as follow 

alteraTseNetif.hwaddr[0] = 0x00; 

alteraTseNetif.hwaddr[1] = 0x1C; 

alteraTseNetif.hwaddr[2] = 0x23; 

alteraTseNetif.hwaddr[3] = 0x17; 

alteraTseNetif.hwaddr[4] = 0x4A; 

alteraTseNetif.hwaddr[5] = 0xCB; 

if i missed something? 

--- Quote End ---  

 

 

This is all you need to do to set the MAC address. I've advised other users of this example who can't get it to run to create a project based on the Simple Socket Server. If you can get that to run to be able to ping the board, this lwIP example will not run either. If Simple Socket Server doesn't run then search for help or post new a message to this forum about getting SSS to run. When SSS runs, so will this example lwIP program. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,008 Views

 

--- Quote Start ---  

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

 

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 

--- Quote End ---  

 

 

 

I too would like to change the# define to something smaller so my code will not hang so long without a cable attached. Later on in the code, I will periodically jump into tse_mac_init() to negotiate the link and initialize properly instead of blocking in a while loop at the beginning. The problem is the# define is buried in the altera source libraries. This is not a problem if the change is only on my machine, but in my work environment where we're doing configuration management, others have to be able to rebuild the project without modifying their owen altera libraries. 

 

I've tried defining ALTERA_CHECKLINK_TIMEOUT_THRESHOLD 250000 as a symbol in the Properties/C++ Build / Tool Settings / NIOS II Compiler / Preprocessor GUI, hoping it would override the value in altera_avalon_tse.h. This didn't work.  

 

I tried a# undef in one of my local project source files but that didnt' work either. 

 

I suppose I could make a local copy of altera_avalon_tse.c & .h in my local project folder and modify as needed. I was just hoping there was some simple pre-processor "override" capability I was missing. Any tips to modify this# define without touching the original source and not make a local copy of altera_avalon_tse.c & .h?
0 Kudos
Altera_Forum
Honored Contributor II
1,018 Views

Try the following: 

Write another header file altera_avalon_tse.h and put it in a directory earlier on the -I include path list. 

File contents: 

# include <altera_avalon_tse.h># undef ALTERA_CHECKLINK_TIMEOUT_THRESHOLD# define ALTERA_CHECKLINK_TIMEOUT_THRESHOLD <new value> 

 

This should work provided altera_avalon_tse.c contains# include <altera_avalon_tse.h> 

not 

#include "altera_avalon_tse.h"
0 Kudos
Altera_Forum
Honored Contributor II
1,018 Views

hi,i'm a new user.I had download the software and it can run in the nios 9.1.It is really nice.Can i ask you some question? 

 

1)if i wan to use udp format to send image.Can i use this code&#65311; 

2)there is a udp c++ source file in the test folder.I wonder that udp file can be used as the apart of my study for sending udp packet? 

3)Do you have any design example regarding use of udp format to send image? 

 

Thank you  

siang
0 Kudos
Altera_Forum
Honored Contributor II
1,018 Views

I'll answer this one if nobody minds... 

1) Yes you can, you can stream a JPEG (if you use RTP over UDP) or you can just send it and let some application assemble it back (don't know what do you need it for). Anyway, for RTP check out: 

RFC2435, RFC3550 and RFC3551.  

Also, download lwip documentation. 

2) udp.c contains functions for UDP processing. Have a look at the httpd server example included in this Nios II port to get a better picture on how to use the lwip for UDP processing (the HTTPD is built on TCP, but more-less, it's the same principle with UDP, only easier). 

3) Just read all of the above and you should have a good picture on how to use lwip for your particular task. 

Best regards... 

 

Ivan
0 Kudos
Altera_Forum
Honored Contributor II
1,018 Views

Hi,my goal is to send a image from board to pc via udp packet.I face a problem:when i using the wireshark to inspect the ethernet traffic.It can show all the packet is sent.But i have using a high level software to open the picture.i have change the destip,sourceip and port is same as the nios.But there is nothing shown.Can any 1 help me&#65311;thank you.

0 Kudos
Reply