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.

AM2634-Q1: AM2634-ethernet dual mac - udp client - nortos

Part Number: AM2634-Q1

Hi,

My requirement is to run UDP client on two ethernet ports with dual mac. Each ethernet port is connected to its own network. This means the device would get two separate IP addresses, subnet and gateway.

I read some other queries related to dual mac. I am trying the example cpsw_rawhttpserver from MCU-SDK-V11.00.00.19. I modified the App_setupNetif() code as below to suit my requirement.

------------------------------------

static void App_setupNetif()
{
    // ip4_addr_t ipaddr, netmask, gw;

    // ip4_addr_set_zero(&gw);
    // ip4_addr_set_zero(&ipaddr);
    // ip4_addr_set_zero(&netmask);
    ip4_addr_t ipaddr[2], netmask[2], gw[2];

    ip4_addr_set_zero(&gw[0]);
    ip4_addr_set_zero(&ipaddr[0]);
    ip4_addr_set_zero(&netmask[0]);

    ip4_addr_set_zero(&gw[1]);
    ip4_addr_set_zero(&ipaddr[1]);
    ip4_addr_set_zero(&netmask[1]);

    DebugP_log("Starting lwIP, local interface IP is dhcp-enabled\r\n");
    // hlwipIfApp = LwipifEnetApp_getHandle();    
    for (uint32_t i = 0U; i < ENET_SYSCFG_NETIF_COUNT; i++)
    {
        hlwipIfApp[i] = LwipifEnetApp_getHandle();
        /* Open the netif and get it populated*/
        // g_pNetif[i] = LwipifEnetApp_netifOpen(hlwipIfApp, NETIF_INST_ID0 + i, &ipaddr, &netmask, &gw);
        g_pNetif[i] = LwipifEnetApp_netifOpen(hlwipIfApp[i], NETIF_INST_ID0 + i, &ipaddr[i], &netmask[i], &gw[i]);
        netif_set_status_callback(g_pNetif[i], App_netifStatusChangeCb);
        netif_set_link_callback(g_pNetif[i], App_netifLinkChangeCb);
        netif_set_up(g_pNetif[NETIF_INST_ID0 + i]);
#if LWIP_NETIF_HOSTNAME
        g_pNetif[i]->hostname = "HBL-BBU";
#endif        
    }
    // LwipifEnetApp_startSchedule(hlwipIfApp, g_pNetif[ENET_SYSCFG_DEFAULT_NETIF_IDX], &hEvent);
    LwipifEnetApp_startSchedule(hlwipIfApp[0], g_pNetif[NETIF_INST_ID0], &hEvent);
    LwipifEnetApp_startSchedule(hlwipIfApp[0], g_pNetif[NETIF_INST_ID1], &hEvent);
}
----------------------------------
The result is that only one port shows up with the IP Address. This is same whether I call LwipifEnetApp_startSchedule() twice or once.
 
I am of the impression that I am not following the proper sequence. 
Looking for guidance on this.
 
Thanks & Regards
Varma
  • Hi,

    Thank you for your questions, allow us to get back on this by early next week latest

  • Hi Varma,

    1. Can you please let me know if you have both the MAC Ports enabled in the example.syscfg file. And Can you also check if the PHY alive logs come up for 2 PHYs (im assuming you do have 2 ethernet cables connected to the device). Can you share the exact logs that you see in your console

    2. Incase you want static IP allocation, make sure you follow this guide: . The example by default will allocate DHCP based IP address.(https://software-dl.ti.com/mcu-plus-sdk/esd/AM263X/latest/exports/docs/api_guide_am263x/NETWORKING_LWIP_STATIC_IP.html)

    3. Since your final use-case involves UDP client, you can start directly with the enet_cpsw_udpclient example. (https://software-dl.ti.com/mcu-plus-sdk/esd/AM263X/latest/exports/docs/api_guide_am263x/EXAMPLES_ENET_LWIP_CPSW_UDPCLIENT.html)

    Regards,
    Shaunak

  • Hi Shaunak,

    Thanks for your reply.

    I did configure the settings in syscfg to enable both ports in MAC mode. For this I followed the example ENET_LWIP_CPSW. I understood about enabling both ports.

    My problem here is that the examples are with FREERTOS where as I need only bare metal NORTOS variant. For this the only example is the ENET_LWIP_RAWHTTPSERVER. I imported this example, it works with one mac port enabled. When I modified the syscfg to enable both ports, it still makes only one port working. That too the second port with NETIF_INST_ID1, not the first one with index NETIF_INST_ID0. 

    I looked at the udp client example, that also is with FREERTOS. My requirement is mandatory bare metal. We are not using the FREERTOS as the FREERTOS is not safety complied. Else, I would have used that same. I tried the udp client example and the tcp server example as well. with the tcp server example I am able to get both ports working in MAC mode and got a ping response for both of them.

    I spent a week trying get the dual port enabled with no-rtos. I am not sure if there is support for dual mac with nortos sdk. 

    I am out of office for Sankranthi festival. So I do not have the logs ready to share. But if you still need them I can send it to you.

    Please let me know if there is support for dual mac working in nortos and also confirm if the FREERTOS is safety complied,

    Regards

    Varma

  • HI Varma,

    Please let me know if there is support for dual mac working in nortos

    Let me check this locally on my setup.

    also confirm if the FREERTOS is safety complied,

    FreeRTOS is compiled as is in the SDK infra and is not adhering to any safety standards (by default FreeRTOS Is not safety certified).

    If you are looking at safety certified version of FreeRTOS, that is something that the SDK does not provide as it is not Free. SafeRTOS Is pre-certified safety RTOS that is based on FreeRTOS. You will have to reach out to some vendors who can provide the SafeRTOS port.

    You can find more details about the IEC compliance levels of SafeRTOS here:

    www.freertos.org/.../Safety

    Regards,
    Shaunak

  • Hi Shaunak,

    Thanks for clearing up on the safety certification of FreeRTOS. We have decided to go with bare metal no rtos approach. 

    Please let me know when can provide the inputs on the dual mac support with no rtos.

    Thanks

    Varma

  • Hi Varma,

    I tried reproducing the error and was able to reproduce it finally. I have filed a bug internally for the team to take a look at. I'll share an update once I have new findings

    Regards,
    Shaunak

  • Hi Shaunak,

    Thank you.

    Appreciate if can give any timeline estimate for the solution. Have to convey the timelines to a client.

    Regards

    Varma

  • Sure, will let you know the plan.

    Regards,
    Shaunak

  • Hi Varma,

    Can you please try the below patch and see if it helps:

    Just modify your app_main.c file and call the periodic_polling API for both NetIFs instead of just one. The second MAC Port was active and alive but the LwIP API was not periodically polling for changes and thus even though DHCP server tries assigning IP address to it, it did not detect it.

    Regards,
    Shaunak

  • Hi Shaunak,

    Thanks a lot. I got both ports working. 

    Below is the working image.

    I have a follow up question. Present http server works on both instances similarly. How can I send different messages from different mac ports. For example, from port 1, i have to send "Hello 1" to an external UDP Server 1 and have to send "Hello 2" to another UDP server 2. 

    Thanks & Regards

  • Ignore the follow up question. I found the answer

  • Hi Shaunak,

    Follow up on the previous. I made udp echo server to receive on both ports as below. The issue is that again only the second port receives & echoes the data. The first port receives the data but the echoed data is lost.

    I presumed it to be again a App_handleEvent issue and added the new lines as below.

    Still the behavior is same. Any ideas on this, please?

    Regards

    Varma

  • HI Varma,

    Can you try and let me know if:

    1. Ping works on both IPs together?

    2. What type of traffic are you testing with (Uni-cast, broadcast, etc)

    3. Can you let me know where exactly the data gets lost (since you mentioned the data is received, is it overwritten by other port's data?, is it getting corrupted at the application level? What stage do you check the buffer and confirm that correct data is received, but later lost)

    4. Can you try creating a new LWIP thread for the second port. Generally what I have seen is, if you are running two independent clients without RTOS, you should have two different lwip threads if you get correct data but lose when echoing back using udp_sendto, you will have to use a diff API to make sure lwip routing happens properly..

    5. Is port-2 your default netif (the one that is able to correctly echo back data)

    Regards,
    Shaunak

  • Hi Shaunak,

    I got it working on both ports. However please see the answers for your queries.

    1. Ping works on both IPs

    2. It's basic udp server running on different ports 

    3. Tested by sending the udp messages from a windows machine using PacketSender application. It would send periodic udp data to the server.

    4. Using bare metal C I created two UDP echo server applications, each with separate receive callback functions.

    5. That was not the default port. It is supposed to work on both.

    I made a echo server as below, which worked. I had use separate netif instances. The key was also to use two different networks with separate netmasks.

    void udp_dual_server(void){
    
        err_t err;
        udpServer[NETIF_INST_ID0] = udp_new_ip_type(IPADDR_TYPE_V4);
        udpServer[NETIF_INST_ID1] = udp_new_ip_type(IPADDR_TYPE_V4);
    
        err = udp_bind(udpServer[NETIF_INST_ID0], &g_pNetif[NETIF_INST_ID0]->ip_addr, 9929);
        if(err == ERR_OK){
    
            udp_recv(udpServer[NETIF_INST_ID0], udpecho_raw_recv_id1, NULL);        
        }
        err = udp_bind(udpServer[NETIF_INST_ID1], &g_pNetif[NETIF_INST_ID1]->ip_addr, 9927);
        if(err == ERR_OK){
    
            udp_recv(udpServer[NETIF_INST_ID1], udpecho_raw_recv_id2, NULL);        
        }
    }

    My target application is to use both UDP server and client on both ports and send / receive data from an external unit. 

  • HI Varma,

    Thanks for sharing the information, glad to know it worked.

    Can i mark this E2E thread closed if the issue is resolved?

    Regards,
    Shaunak

  • Yes, please. I have another query related to multicast for which I will open another query

    Thanks 

    Varma