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.

RM48L952: RM48L952

Part Number: RM48L952
Other Parts Discussed in Thread: DP83640

Hi,

 

I have Lwip driver, how to make use of it for tcp/ip?

 Can you please share me the demo application code for tcp/ip.

 

Regards,

Immanuel

  • Hello Immanuel,

    Here is the link to download the LWIP demo project for Hercules MCU:

    processors.wiki.ti.com/.../HALCoGen_Ethernet_Driver_and_lwIP_Integration_Demonstration
  • Hi Wang,

    Thanks for your reply.

    I have downloaded that already. but  need a demo code for using TCP/IP in that driver code.

    Regards,

    Immanuel

  • Hello Immanuel,

    LWIP is a TCP/IP stack. This demo is HTTP server (Ethernet application).
  • Hi Wang,

    I don't want to use http server in my application, how can I use it for TCP/IP or UDP.

    Regards,
    Immanuel
  • hello Immanuel,

    We don'y have this kind of examples, for example tcp echo server demo.
  • Hi Wang,

    we are not getting any clue for it.Please give your suggestions for the implementation of UDP communication using this lwip driver.

    Regards,
    Immanuel

  • Hello Immanuel,

    I posted an simple example for using LWIP UDP.
  • Hello Wang.

    The UDP code whatever you have given is showing many errors, the NETCONUDP macro is disabled. If I enable its showing lot of errors in the driver functions.

    Can you please send the UDP working example.

    Regards,
    immanuel
  • Hi immanuel,

    I don't have a working UDP example. You need include the following header files:
    #include "lwip/udp.h"
    #include "lwip/ip_addr.h"
  • Hi Wang,

    The Functions 

    EMAC_LwIP_Main(emacAddress);; is making many server configurations.

    we have included the header as you mentioned.

    int main()

    {

    struct pbuf *Tx;
    uint16_t length=0;
    char msg[5],error,pcb;

    _enable_IRQ();
    EMAC_LwIP_Main(emacAddress);
    IP4_ADDR(&src, 162, 192, 37, 29);
    IP4_ADDR(&dst, 162, 192, 37, 28);
    IP4_ADDR(&snet, 255, 255, 255, 0);
    IP4_ADDR(&nnet, 0, 0, 0, 0);
    pcb=udp_new();

    error=udp_bind(pcb,&src,6031);
    error=udp_connect(pcb,&dst,49668);
    length = 5;
    Tx=pbuf_alloc(PBUF_TRANSPORT,length, PBUF_RAM);
    Tx->next=0;
    Tx->len=Tx->tot_len=length;
    memcpy (Tx->payload, msg, Tx->len);
    udp_sendto(pcb, Tx, &dst, 49668);
    pbuf_free(Tx);

    }

    void EMAC_LwIP_Main (uint8_t * macAddress)
    {
    unsigned int ipAddr;
    uint8_t testChar;
    struct in_addr devIPAddress;

    //iommUnlock();
    //iommMuxEnableMdio();
    //iommMuxEnableMii();
    //iommLock();
    sciInit();

    /* Enable the interrupt generation in CPSR register */
    IntMasterIRQEnable();
    _enable_FIQ();

    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    sciDisplayText(scilinREG, txtTitle, sizeof(txtTitle));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    sciDisplayText(scilinREG, txtTI, sizeof(txtTI));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    #ifdef __little_endian__
    sciDisplayText(scilinREG, txtLittleEndian, sizeof(txtLittleEndian));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    #else
    sciDisplayText(scilinREG, txtBigEndian, sizeof(txtBigEndian));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    #endif

    /* Initialze the lwIP library, using DHCP.*/
    sciDisplayText(scilinREG, txtEnetInit, sizeof(txtEnetInit));
    ipAddr = lwIPInit(0, macAddress,0xA2C0251C,0xFFFF0000, 0, IPADDR_USE_STATIC);
    sciDisplayText(scilinREG, (uint8_t*)"..DONE", sizeof("..DONE"));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));

    if (0 == ipAddr) {

    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    sciDisplayText(scilinREG, txtErrorInit, sizeof(txtErrorInit));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    } else {
    /* Convert IP Address to string */
    devIPAddress.s_addr = ipAddr;
    txtIPAddrItoA = (uint8_t *)inet_ntoa(devIPAddress);
    LocatorConfig(macAddress, "HDK enet_lwip");

    /* Initialize the sample httpd server. */
    sciDisplayText(scilinREG, (uint8_t*)"Starting Web Server", sizeof("Starting Web Server"));
    httpd_init();
    sciDisplayText(scilinREG, (uint8_t*)"..DONE", sizeof("..DONE"));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));

    /* Loop forever. All the work is done in interrupt handlers. */
    //while(1)
    {
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));

    sciDisplayText(scilinREG, txtTitle, sizeof(txtTitle));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));

    sciDisplayText(scilinREG, txtTI, sizeof(txtTI));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    #ifdef __little_endian__
    sciDisplayText(scilinREG, txtLittleEndian, sizeof(txtLittleEndian));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    #else
    sciDisplayText(scilinREG, txtBigEndian, sizeof(txtBigEndian));
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));
    #endif
    sciDisplayText(scilinREG, txtIPAddrTxt, sizeof(txtIPAddrTxt));
    sciDisplayText(scilinREG, txtIPAddrItoA, 16);
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));

    sciDisplayText(scilinREG, txtNote1, sizeof(txtNote1));
    sciDisplayText(scilinREG, txtIPAddrItoA, 16);
    sciDisplayText(scilinREG, txtCRLF, sizeof(txtCRLF));


    /* Before printing the next set, wait for a character on the terminal */
    // sciReceive(scilinREG, 1, &testChar);
    }
    }
    }

    The UDP is not working . The DP83640 is generating ARP with both src and dst IP as same address.

    we are not getting any idea about it,kindly give your suggestions.

    Regards,

    Immanuel

  • Hello, 

    My comments are in blue:

    int main()

    {

    extern unsigned int len,Tot_len;

    struct udp_pcb *pcb;

    struct ip_addr ipaddr, netmask, gw,Src,Dst;

    struct pbuf *Tx;
    uint16_t length=0;
    char msg[5],error,pcb;

    _enable_IRQ();
    EMAC_LwIP_Main(emacAddress);

    //The IP address should be the IP address of your boards
    IP4_ADDR(&src, 162, 192, 37, 29);
    IP4_ADDR(&dst, 162, 192, 37, 28);
    IP4_ADDR(&snet, 255, 255, 255, 0);
    IP4_ADDR(&nnet, 0, 0, 0, 0);

    //This is for gatway

    IP4_ADDR(&gw, 192, 168,   0, 1);


    pcb=udp_new();

    //are those numbers valid for you?

    error=udp_bind(pcb,&src,6031);
    error=udp_connect(pcb,&dst,49668);   //not a valid number for UDP
    length = 5;
    Tx=pbuf_alloc(PBUF_TRANSPORT,length, PBUF_RAM);
    Tx->next=0;
    Tx->len=Tx->tot_len=length;
    memcpy (Tx->payload, msg, Tx->len);
    udp_sendto(pcb, Tx, &dst, 49668); //not a valid number for UDP
    pbuf_free(Tx);

    }

  • Hello,


    int main()
    {
    extern unsigned int len,Tot_len;
    struct udp_pcb *pcb;
    struct ip_addr ipaddr, netmask, gw,Src,Dst;
    struct pbuf *Tx;
    uint16_t length=0;
    char msg[5],error,pcb;
    _enable_IRQ();

    EMAC_LwIP_Main(emacAddress);// what this fuction is doing many configuration is it mandatory to do all inside


    //The IP address should be the IP address of your boards ---Source and destination both should be board's??
    IP4_ADDR(&src, 162, 192, 37, 29);
    IP4_ADDR(&dst, 162, 192, 37, 28);
    IP4_ADDR(&snet, 255, 255, 255, 0);
    IP4_ADDR(&nnet, 0, 0, 0, 0);
    //This is for gatway
    IP4_ADDR(&gw, 192, 168, 0, 1); // The PC IP??

    pcb=udp_new();

    //are those numbers valid for you?-- That's the number the PC is generating
    error=udp_bind(pcb,&src,6031);
    error=udp_connect(pcb,&dst,49668); //not a valid number for UDP
    length = 5;
    Tx=pbuf_alloc(PBUF_TRANSPORT,length, PBUF_RAM);
    Tx->next=0;
    Tx->len=Tx->tot_len=length;
    memcpy (Tx->payload, msg, Tx->len);
    udp_sendto(pcb, Tx, &dst, 49668); //not a valid number for UDP
    pbuf_free(Tx);
    }
  • I think that 49668 is out of the range of UDP port number. The maximum is 49151.

    en.wikipedia.org/.../List_of_TCP_and_UDP_port_numbers
  • Hi Wang,

    EMAC_LwIP_Main(emacAddress);// what this fuction is doing many configuration.Is it mandatory to do all inside

    Source and destination both should be board's??
    IP4_ADDR(&src, 162, 192, 37, 29);
    IP4_ADDR(&dst, 162, 192, 37, 28);
    IP4_ADDR(&snet, 255, 255, 255, 0);
    IP4_ADDR(&nnet, 0, 0, 0, 0);
    //This is for gatway
    IP4_ADDR(&gw, 192, 168, 0, 1); // This should be PC IP??

    Kindly give yours suggestions.

    Regards,
    Immanuel
  • Hello,

    Below is a link to some udp example.
    www.ultimaserial.com/avr_lwip_udp.html