This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Confused trying to use LwIP

I am trying to do a simple UDP send/receive operation using the TM4C1294XL and have looked at other posts but  am still confused when I look at various examples provided in the code.  There appears to be numerous paradigms for setting up and using a UDP scenario and I don't see the big picture how these fit together, or, possibly represent multiple ways to do the same thing.

When I look at lwiplib.c in TivaWare /utils directory it provides functions for initialization (lwIPInit, lwIPPrivateInit), background interrupt task (lwIPInterruptTask) and background timer (lwIPServiceTimers).  But I also see other example code that uses fdOpenSesion(), socket(), bind(), recv() and sendto() calls.  Are these two distinct ways of doing the same thing or do they work together somehow?  

Which set of functions do I care about?  I am using tirtos tasking in my project and will need to incorporate the solution into that.

What I want to do is incredibly simple (Send a string over UDP to a fixed IP address on a dedicated wire and get a string response).  I was hoping not to require weeks of studying various examples to do this, so if you could suggest the shortest path and if there is an example for it that would help me out greatly.

Roger

  • Hello Roger

    The simplest code and the simplest answer is the locator.c which uses a PC to query Connected LaunchPads on the same subnet using UDP.

    Now the tough part is to integrating it into an application, which we can help you with if you have a template code to start with.

    Regards
    Amit
  • Okay. That code looks simple enough. When I try to cut and paste this code into my baseline including the #include for "utils/lwiplib.h" it fails to find all of the includes in that file such as lwip.api.h and the others which are deep down in a third_party directory.

    Am I supposed to copy all of this third_pary/lwip-1.4.1 code so that it is native in my project? Also I noticed that there is a "ports" directory in there with a tive-tm4c129.c file. Do I incorporate that into my code somehow?

    R
  • Hello Roger

    You can use the base code project to begin with and only call the API's required directly to your main application.

    Regards
    Amit
  • Okay. I was almost able to build with the lwip code by including three lines in the include path of the build project:

    "C:\ti\TivaWare_C_Series-2.1.0.12573\third_party\lwip-1.4.1\src\include"
    "C:\ti\TivaWare_C_Series-2.1.0.12573\third_party\lwip-1.4.1\ports\tiva-tm4c129\include"
    "C:\ti\TivaWare_C_Series-2.1.0.12573\third_party\lwip-1.4.1\src\include\ipv4"

    However, I still get a couple of errors that seem to be a problem with:
    C:\ti\TivaWare_C_Series-2.1.0.12573\third_party\lwip-1.4.1\ports\tiva-tm4c129\include\arch\sys_arch.h.

    It wants to typedef sem_t and mbox_t which use things like xQueueHandle which are only defined if RTOS_FREERTOS is enabled. But I am using tirtos, so this is not enabled. These typedef's are not defined within the scope of RTOS_FREERTOS and there is no alternative definition provided for people using something besides FREERTOS. So, if I comment them out there are errors because they are missing, but if I leave them I get errors on xQueueHandle and other things that are only defined within the range of RTOS_FREERTOS.

    R
  • Hello Roger

    Can you please check the enet_lwip example code by compiling the same for the options and paths?

    Regards
    Amit
  • Good new and bad news.
    I found the enet_lwip example code very useful and incorporated it into my project.
    When I exercise the ethernet code, as long as my ethernet cable is *not* plugged in I can see it working through the code properly to build a UDP packet and then attempt to ARP to find the remote target. But when I attach the cable to a router or directly to another target (via cross over) I get what appears to be infinite EMAC interrupts that never clear out.

    The stack looks like:
    EMACSnow_hwIntFxn -> EMACSnow_processPhyInterrupt -> EMACPHYRead

    In the EMACSnow_processPhyInterrupt function it reads 'value' at EPHY_MISR1 and 'status' at EPHY_STS.
    Both return 0xFFFF and the foreground code does not really get a chance to run because it immediately returns the the EMAC interrupts again. Even if I then detach the ethernet cable it still stays in the infinite interrupt loop as if it cannot clear the interrupt.
    I did not modify the provided emac code.

    Not sure why this would make a difference but for the record my initialization is:
    lwIPInit(gSysClock, pui8MACArray, htonl(mIPAddr.addr), htonl(mIPNetMask.addr), htonl(mIPGateway.addr), IPADDR_USE_STATIC);
    udpInit(&m_pcb);

    Roger
  • Hello Roger,

    I am curious as to the choice of using lwIP TCP/IP stack with TI-RTOS, when TI-RTOS already has a TCP/IP stack called NDK that is tightly integrated and offers lot of scalability.

    The lwIP in TivaWare is ported to work only with FreeRTOS (no porting for TI-RTOS is available currently). So what you are trying to achieve will not be straight forward and not sure if we can answer these questions without actually trying them on our side.

    If you still want to go down this route, maybe the following information will help -The lwIP port in TivaWare creates two tasks when the label "RTOS_FREERTOS" is defined (and when FreeRTOS is used). One task handles the Ethernet packets and the other task handles the lwIP TCP/IP layer. Not sure how the TI-RTOS driver layer is architected - you will need to identify this working and see how it can tie back to lwIP.

    Hope this information helps!

    Thanks,
    Sai