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.

TCP/UDP socket usin LwIp

Dear all

I'm try to perform a socket UDP using LwIP TCP/IP stack on TiVa TM4c129X microcontroller.

The cose is in the follow:

int main(void)
{
    uint32_t ui32User0, ui32User1;
    uint8_t pui8MACArray[8];
    uint32_t my_udp_rx[10];
    char msg[]="testing";

    struct pbuf *p;

    // Run from the PLL at 120 MHz.
    g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                         SYSCTL_OSC_MAIN |
                                         SYSCTL_USE_PLL |
                                         SYSCTL_CFG_VCO_480), 120000000);


    // Configure the device pins.
    PinoutSet();

    // Initialize the display driver.
    Kentec320x240x16_SSD2119Init(g_ui32SysClock);


    // Initialize the graphics context.
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);


    // Draw the application frame.
    FrameDraw(&g_sContext, "enet-lwip");


    // Configure SysTick for a periodic interrupt.
    ROM_SysTickPeriodSet(g_ui32SysClock / SYSTICKHZ);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();


    // Configure the hardware MAC address for Ethernet Controller filtering of
    // incoming packets.  The MAC address will be stored in the non-volatile
    // USER0 and USER1 registers.
    //
    ROM_FlashUserGet(&ui32User0, &ui32User1);
    if((ui32User0 == 0xffffffff) || (ui32User1 == 0xffffffff))
    {
        //
        // We should never get here.  This is an error if the MAC address has
        // not been programmed into the device.  Exit the program.
        //
        GrContextForegroundSet(&g_sContext, ClrRed);
        GrStringDrawCentered(&g_sContext, "MAC Address", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2,
                             (GrContextDpyHeightGet(&g_sContext) / 2) - 4,
                             false);
        GrStringDrawCentered(&g_sContext, "Not Programmed!", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2,
                             (GrContextDpyHeightGet(&g_sContext) / 2) + 16,
                             false);
        while(1)
        {
        }
    }

    //
    // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
    // address needed to program the hardware registers, then program the MAC
    // address into the Ethernet Controller registers.
    //
    pui8MACArray[0] = ((ui32User0 >>  0) & 0xff);
    pui8MACArray[1] = ((ui32User0 >>  8) & 0xff);
    pui8MACArray[2] = ((ui32User0 >> 16) & 0xff);
    pui8MACArray[3] = ((ui32User1 >>  0) & 0xff);
    pui8MACArray[4] = ((ui32User1 >>  8) & 0xff);
    pui8MACArray[5] = ((ui32User1 >> 16) & 0xff);


    // Initialze the lwIP library, using DHCP.

    lwIPInit(g_ui32SysClock, pui8MACArray, 0, 0, 0, IPADDR_USE_DHCP);

    IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY);
    IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);


     g_upcb = udp_new();

     udp_bind(g_upcb, IP_ADDR_ANY, 777);

     udp_recv(g_upcb, &my_udp_rx, (void *)0);


     while (1){

     p = pbuf_alloc(PBUF_TRANSPORT,sizeof(msg),PBUF_RAM);
     memcpy (p->payload, msg, sizeof(msg));
     udp_sendto(g_upcb, p, SENDER_IP_ADDR, 1234);
     pbuf_free(p); //De-allocate packet buffer

     SysCtlDelay(2000000);

     cnt++;

     if(cnt== 1000) break;

   }

}

The client board obtain correctly the IP from the server by means DHCP then perform the loop for send the UDP packet end finsh corretly.

But I'm not able to see data trasmitted from the board using WireShark to analize the network.

Have you same example of TCP or UDO comunications.

I need to upgrade the old communications with RS232 with a TCP or UDO client server communication, but I'not able to find exemple on the net.

Thanks in advanced

Marco