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.

CCS/TM4C129XNCZAD: TM4C129XNCZAD TIVA UDP example

Part Number: TM4C129XNCZAD

Tool/software: Code Composer Studio

Someone can give a simple example of transferring a UDP packet using the library uip 1.0?

  • Hello Vladimir,

    We don't really have any UDP examples for TivaWare. If you want to use TI-RTOS for TivaC, you could look at their example for UDP Echo which is part of their Network examples for Ethernet.

    Alternatively, you could reference this E2E post which has a strong list of options for implementing your own UDP example: https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/498942/1805878#1805878

  • Ok. i changed enet lwip example: just transmit message. I do not get anything on port 7070 Where I'm wrong? I selected my inserts

    nt
    main(void)
    {
    uint32_t ui32User0, ui32User1;
    uint8_t pui8MACArray[8];

    //
    // Run from the PLL at 120 MHz.
    //
    g_ui32SysClock = MAP_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();

    //
    // Initialize the file system.
    //
    fs_init();

    //
    // 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_AUTOIP);
    void *UDPSock = udp_new();
    udp_recv(UDPSock, NULL, NULL);
    udp_bind(UDPSock, IP_ADDR_ANY, 7070);
    udp_connect(UDPSock, IP_ADDR_ANY, 7070);

    char buf[500] = "HELLO KITTY";
    struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 500, PBUF_RAM);
    //struct ip_addr server;
    // IP4_ADDR(&server, 192, 168, 253, 236);

    //
    //
    // Setup the device locator service.
    //
    //LocatorInit();
    //LocatorMACAddrSet(pui8MACArray);
    //LocatorAppTitleSet("DK-TM4C129X enet_lwip");

    //
    // Initialize the sample httpd server.
    //
    //httpd_init();

    //
    // Set the interrupt priorities. We set the SysTick interrupt to a higher
    // priority than the Ethernet interrupt to ensure that the file system
    // tick is processed if SysTick occurs while the Ethernet handler is being
    // processed. This is very likely since all the TCP/IP and HTTP work is
    // done in the context of the Ethernet interrupt.
    //
    ROM_IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY);
    ROM_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);
    uint32_t ui32Loop;
    //
    // Loop forever. All the work is done in interrupt handlers.
    //
    while(1)
    {
    p=pbuf_alloc(PBUF_TRANSPORT, 500, PBUF_RAM);
    memcpy(p->payload, buf, 500);
    udp_sendto(UDPSock,p,IPADDR_ANY,7070);
    pbuf_free(p);
    for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
    {}

    }
    }

  • Hello Vladimir,

    I'll be honest with that in that we don't have much lwip/udp knowledge here - that's fairly outside of our scope (we are responsible for the IC peripheral - Ethernet in this case - but not all applications that can leverage it). That said, I am going to send this to our Ethernet peripheral expert who may be able to offer some sort of advice. He is out of office until next week though, so not sure if he will get back to you before then. Please excuse any possible delays in reply.
  • Hi,
    Can you try with DHCP first before you use AUTOIP? Use the wireshark to see if you are able to acquire the IP address. Is there any reason that you would not use DHCP for your application?

    First I'm not sure if you are getting an automatic IP address. Secondly, If a network is configured with IP addresses for a different network than 169.254.x.y, then devices with Auto IP addresses may not be able to communicate properly.

    Make sure your LwIP has both #define LWIP_DHCP and #define LWIP_AUTOIP set to 1. If the host is unable to receive a DHCP address and then fall back to the automatic IP, it normally is a sign of network problem.

    On your code I see that you call the udp_new. I think it should return the new PCB in the form of the udp_pcb structure like below. I'm not too sure about void *UDPSock = udp_new();

    struct udp_pcb *pcb;
    pcb = udp_new();

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

    For more LwIP questions, please directly post your questions to LwIP forum.
  • Can you try with DHCP first before you use AUTOIP?

    -Done. Nothink changed. I get IP-adress 169.254.159.146. Network is configured for 169.254.159.1 mask 255.255.0.0

     #define LWIP_DHCP 1  #define LWIP_AUTOIP 1

    -Done.  Nothink changed

    struct udp_pcb *pcb; pcb = udp_new();

    -Done.  Nothink changed

    For more LwIP questions, please directly post your questions to LwIP forum

    link?

  • If your DHCP works then you should get private IP address in the below ranges. 169.254.x.y is an Auto IP address, not DHCP address per my understanding. Try to set LWIP_AUTOIP to 0 and can you acquire DHCP address? Use the wireshark and capture the log. What do you see?

    24-bit block 10.0.0.0 – 10.255.255.255
    20-bit block 172.16.0.0 – 172.31.255.255
    16-bit block 192.168.0.0 – 192.168.255.255

    I'm on vacation and I will be out on the road with no access to the forum in the next 8 hours.
  •  Try to set LWIP_AUTOIP to 0 and can you acquire DHCP address

    Done.I can't get ip. DHCP not working?

  • Hi,
    Can you use filter by MAC address in the wireshark to show only the log pertaining to your MAC address? If the DHCP does not work then it is not related to how you send data using UDP. Can you try the TivaWare ethernet examples? They all use DHCP for acquiring the IP address even though that TCP is used for the stack protocol. Does the TivaWare ethernet example work in your network as far as obtaining the DHCP address? If they work, then you want to reference the example code for your project as far as acquiring the IP address.

    I can't really make out from your wireshark log. It shows the DHCP Discover. Normally this comes from the client. The DHCP is a four phase process from Discovery->Offer->Request->Acknowledge. The DHCP server is supposed to send the DHCP offer to the client. I don't see the Offer frame in the wireshark log. Is it possible that the DHCP server did not receive the discover packet? You might need to check your router too.