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連結已複製
--- Quote Start --- I haven't had much luck getting this to port on the BemicroSDK... do you have any pointers on the changes you needed to make to get it to work? --- Quote End --- If an Arrow FAE will comp me a BemicroSDK kit or if you want to send me one, I'll get lwIP running on it. I don't use Cyclone IV at work so have no access to this kit (nor the need to ask the boss to get me one). You will have to get lwIP hooked into the TSE driver used on the IV and configure lwIP for accessing the PHY. Not trivial if you've not done an lwIP port, and it even might not be so trivial if you have. :) BillA
--- Quote Start --- Please stop sending the same question multiple times. It won't get you more answers. I rarely use the debugger so I can't be of much help here. For starters is 0xe11fc a valid program address, i.e. an address in your main RAM region? IF the address is complete bogus, it could indicate a memory corruption or a head/stack collision. --- Quote End --- Dear Daixiwen I'm so sorry about it,and I will not do that any more.and sorry about reply lately.first I think i should check the hardware as billa said,and run the sss project to test the board!thank you for your reply,and best wishes to you
--- Quote Start --- This kind of error typically means the hardware definition is wrong. Something is wrong with memory, clocks, speeds or something. In the past I've told people that have problems with this example to get a standard Altera example running - like Simple Socket Server as-is on your hardware (create app and BSP with that template). If the Simple Socket Server won't run, this lwIP example will never run either. It's pretty hard to test and debug software with unstable hardware. BillA --- Quote End --- Hi Billa thanks for your reply my board can ping it,and my hardware have sth wrong? I will check the hardware with the SSS project. best wishes to you!
Dear BillA
I'm using niosii 9.0+quartus 9.0 to build the project.when i can ping the board and get the packages using the tool wireshark.and i can send the package by using the function tse_mac_raw_send(&alteraTseNetif,psend);also test the packages.but I can't run the function udp_send(UdpPcbS,psend);so I test step by step.when i arrive to the code of the function ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif) ,the problem appear.warning " <symbol is not available> 0x877e11ff".maybe I lost something important,could you give me advices.thanks a lot,and best wishes to you! here is the code: IPH_TTL_SET(iphdr, ttl); IPH_PROTO_SET(iphdr, proto); ip_addr_set(&(iphdr->dest), dest); IPH_VHLTOS_SET(iphdr, 4, ip_hlen / 4, tos); IPH_LEN_SET(iphdr, htons(p->tot_len)); IPH_OFFSET_SET(iphdr, 0); IPH_ID_SET(iphdr, htons(ip_id)); ++ip_id;Dear daixiwen
I'm using niosii 9.0+quartus 9.0 to build the project.when i can ping the board and get the packages using the tool wireshark.and i can send the package by using the function tse_mac_raw_send(&alteraTseNetif,psend);also test the packages.but I can't run the function udp_send(UdpPcbS,psend);so I test step by step.when i arrive to the code of the function ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif) ,the problem appear.warning " <symbol is not available> 0x877e11ff".maybe I lost something important,could you give me advices.thanks a lot,and best wishes to you! here is the code: IPH_TTL_SET(iphdr, ttl); IPH_PROTO_SET(iphdr, proto); ip_addr_set(&(iphdr->dest), dest); IPH_VHLTOS_SET(iphdr, 4, ip_hlen / 4, tos); IPH_LEN_SET(iphdr, htons(p->tot_len)); IPH_OFFSET_SET(iphdr, 0); IPH_ID_SET(iphdr, htons(ip_id)); ++ip_id;zhangjie,
You did not need to double post - or address an individual because everyone sees these posts and might reply if they can help. Sure, you can address the previous replier to a post of yours but no need for a double entry. The error can be caused by compiler optimization. Also, bit 31 is set of the address (being a non-cached pointer) and that may be causing the symbol lookup to fail. udp_send can fail if ARP responses are not working. Packets cannot be sent until the address is resolved by ARP. However, I think a ping causes ARP to be resolved so UDP should work too. Can you receive UDP and just not send? Wireshark will show you the ARP resolution (Who has?). Also check your firewall - I'm not sure which side of it Wireshark is watching. Regards, BillACan you share reference design of simple socket server(TCP/IP NicheStack program) in which SMSC LAN91c111 is used as the hardware MAC/PHY.
My main requirement is how to drive this SMSC LAN91c111 using MicroC/OS-II from Nios II EDS.This thread is about lwIP. Both it and Interniche are based on the Altera TSE. Why use an external MAC?
Anyway, you should create a new thread for your topic as it's mostly off-topic here. BillAJust to recap for those not too familiar with networking..
The uIP and it's bigger brother lwIP are TCP/IP stacks originally created by Adam Dunkels that are often used for the bemicro-sdk (EngineeringSpirit FreeLwIP, minsoc.com uses uIP I believe, etc). Altera also used that stack, but dropped it after version 6.1 in favor of the other open source stack , NicheStack. Either way, on the bemicrosdk the low-level physical layer is done by TI's DP83848C chip, and the Data Link / MAC layer is done on the FPGA via Altera's drop-in Triple Speed Ethernet megafunction. Is this correct? http://www.alteraforum.com/forum/showthread.php?t=33812 http://www.alteraforum.com/forum/showthread.php?t=32429 http://www.alteraforum.com/forum/showthread.php?p=93638very very unfortunately,billa and every one,my problem also exists.
so I describe my question again: my fpga is ep3c120f484 and epcs64,have not supply extern sdram by using quartus 9.0+nios 9.0 i do the project as the "readme txt",and the sopc builder system and nios libirary properties will upload in the picture. my ip and mac set: # define STATIC_IP IP4_ADDR(&lwipStaticIp,219,245,66,185) # define STATIC_NM IP4_ADDR(&lwipnetmask,255,255,255,0) # define STATIC_GW IP4_ADDR(&lwipgw,219,245,66,254) # define STATIC_DA IP4_ADDR(&destAddr,219,245,66,112) alteraTseNetif.hwaddr[0] = 0x00; alteraTseNetif.hwaddr[1] = 0x1C; alteraTseNetif.hwaddr[2] = 0x23; alteraTseNetif.hwaddr[3] = 0x17; alteraTseNetif.hwaddr[4] = 0x4A; alteraTseNetif.hwaddr[5] = 0xCB; and the udpsend: char udpdata[] = "UDP has Initialed successfully, begin to transfer!\r\n"; struct pbuf *psend; struct udp_pcb *UdpPcbS; psend = pbuf_alloc(PBUF_RAW, sizeof(udpdata), PBUF_RAM); psend->payload = (void *)udpdata; if (!psend) { printf("Can't allocate buffer.\n"); } UdpPcbS = udp_new(); if (!UdpPcbS) { printf("udp_new() failed.\n"); } udp_bind(UdpPcbS, &lwipStaticIp, 67); if (udp_bind(UdpPcbS, &lwipStaticIp, 67) != ERR_OK) { printf("udp_bind() failed.\n"); } udp_connect(UdpPcbS, &destAddr, 67); if (udp_connect(UdpPcbS, &destAddr, 67) != ERR_OK) { printf("udp_connect() failed.\n"); } while(1) { udp_send(UdpPcbS,psend); mSdelay(1000); mSdelay(1000); mSdelay(1000); } when I debug step by step,the error will be appear in the code in "ip.c" IPH_TTL_SET(iphdr, ttl); if (ip_addr_isany(src)) { ip_addr_copy(iphdr->src, netif->ip_addr); } else { (iphdr->src).addr = (*src).addr; } and return error. and it is not caused by compiler optimization. I can not receive and send any packets. Regards, zhangjie--- Quote Start --- NO! NOT CORRECT!!! NicheStack IS NOT OPEN SOURCE! http://www.alterawiki.com/wiki/nichestack BillA --- Quote End --- Oops, yes, the FreeRTOS home page links to the InterNiche stack.. I didn't notice it was a "Buy Now"! Perhaps their webserver example using FreeTCPIP (on a Actel A2F-EVAL-KIT fpga) is a better start for porting to Altera. I imagine any FPGA port (like fNET) is a closer than starting with EtherSex/uhttpd-avr/NutOS-NutNet, or something else originally targeting a microcontroller.
--- Quote Start --- The following optimization can be applied to lwip_tse_mac.c: In function tse_sgdmaRx_isr: Replace the init_tset_descriptor function call (spans 6 or 7 lines) just after label _dump: with the following: IOWR_32DIRECT(&tse_ptr->desc[ALTERA_TSE_FIRST_RX_SGDMA_DESC_OFST].write_addr, 0, (u32_t) ethernetif->lwip_rx_pbuf[ethernetif->lwipRxIndexIsr]->payload); IOWR_8DIRECT(&tse_ptr->desc[ALTERA_TSE_FIRST_RX_SGDMA_DESC_OFST].control, 0, ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK); I don't claim credit for this - I see they did this in the NIOS 12.1 TSE driver and it makes a lot of sense. Bill A --- Quote End --- Bill, There is no init_tset_descriptor function in the driver. Should it be the alt_avalon_sgdma_construct_stream_to_mem_desc function call in tse_mac_rcv? Igor
--- Quote Start --- I removed (all?) the bugs (The 4 byte SGDMA bug is available in code, but I didn't enable it yet, because I haven't seen any problems) and added multiple PHY support. If you are interested in using this BSP you will have to read the README and the lwip_main.h file to see how you can implement it. Please have a look at : https://github.com/engineeringspirit/freelwip-nios-ii if you're interested in an FreeRTOS with LwIP BSP for in your Nios II IDE (tested with 11.0 till 12.0sp1) --- Quote End --- Is there an off-the-shelf development kit (altera, terasic, etc) that this will work out of the box with? I understand a TSE must be instantiated, but what kind of PHY chip? I think BillA used the Marvell 88E1119R in the lwip port, but I believe it was a custom cyclone3 board. If no COTS, is there any tips on the thought process involved in porting the design to different phys?
Igor,
It's (init_tse_descriptor) is in lwip_tse_mac.c. Happy, You can add a custom or non-default PHY using the run-time add function alt_tse_phy_add_profile. I use this now and use a common lwIP/TSE driver in 4 products so they can all share the same code. I also deleted the defaults in the Altera code - I won't be switching and don't use any of them. The individual NIOS II projects each include the BSP for the board but they reference the same common code. Fortunately, 12.x fixes the bug in 10.x that prevented referencing common code. Yes, we used the 88E119R. I've also moved 3 of the 4 Cyclone III projects to NIOS 12.x and have had no trouble with the TSE or with lwIP, which was also upgraded to 4.1. Fortunately lwIP is very portable. BillA--- Quote Start --- Igor, It's (init_tse_descriptor) is in lwip_tse_mac.c. Happy, You can add a custom or non-default PHY using the run-time add function alt_tse_phy_add_profile. I use this now and use a common lwIP/TSE driver in 4 products so they can all share the same code. I also deleted the defaults in the Altera code - I won't be switching and don't use any of them. The individual NIOS II projects each include the BSP for the board but they reference the same common code. Fortunately, 12.x fixes the bug in 10.x that prevented referencing common code. Yes, we used the 88E119R. I've also moved 3 of the 4 Cyclone II projects to NIOS 12.x and have had no trouble with the TSE or with lwIP, which was also upgraded to 4.1. Fortunately lwIP is very portable. BillA --- Quote End --- BillA, is there an updated set of instructions for the example project in 12.x? I need to leverage a solution that is royalty free, hooray lwIP, but am having trouble following the instructions found in post# 1 for Nios IDE 8.1. Any help?
What is the trouble? The concepts in the original instructions still apply: Create a NIOS II library, base it on your BSP, add lwIP and the ethernet driver. Also, make the changes that fix the bugs mentioned many posts back.
I agree and admit that this original post and ZIP is really stale. I'll see what I can do, but in the meantime, let me know where you're stuck (if you still are). BillA--- Quote Start --- Hi BillA, May I know how much throughput the 1000M Ethernet can achieve for RX and TX on your Cyclone III board? Thanks. Twenty --- Quote End --- This is tough to answer because it's application dependent and very dependent on available memory. I can say for our products that send a lot of data (images) we used a custom UDP protocol because TCP was under 100MBS while UDP can get upwards of 500MBS. (these are bits per second) For our product that receives a lot of data and sends very little, we set the MAC for 100MBS because at 1000MBS the packet rate is so fast the Cyclone III cannot keep up with the interrupt rate. So it drops packets and actually slows down the link. We found at 100MBS there are no dropped packets and we can run the product at its max speed. It was probably faster at 1000MBS but I prefer an error-free transport and 100MBS is enough. It also spread out the receive over more time which I thought was better. Take care, Bill
