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.

TM4C1294NCPDT: Ethernet TCP Communication Lost and Device Hang

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL

Tool/software:

Hello,

We are using TM4C1294NCPDT Tivaware Controller in one of our application.

Having compiler Version below :

CCS Version - 7.4.0

As our application is based on Ethernet TCP Protocol, using LWIP Stack - 1.4.1.

It is TCP Client. We are facing issue of Ethernet communication, at one point communication stops, device get hang and it is not recovering or reconnecting ever. Ethernet Link Status LEDs - OFF , and there is no ping. In code we have also used Watch Dog timer , it seems it is also not Resetting controller,

We are facing this issue at our client site. please guide on same.

Below is the lwipiopt.h configurations we are using :

//*****************************************************************************
//
// lwipopts.h - Configuration file for lwIP
//
// Copyright (c) 2014-2015 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.0.12573 of the EK-TM4C1294XL Firmware Package.
//
//*****************************************************************************
//
// NOTE:  This file has been derived from the lwIP/src/include/lwip/opt.h
// header file.
//
// For additional details, refer to the original "opt.h" file, and lwIP
// documentation.
//
//*****************************************************************************

#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__

//*****************************************************************************
//
// ---------- Stellaris / lwIP Port Options ----------
//
//*****************************************************************************
#define HOST_TMR_INTERVAL               10         // default is 0
//#define DHCP_EXPIRE_TIMER_MSECS         (10 * 1000)
#define LWIP_HTTPD_SSI                  1
#define LWIP_HTTPD_CGI                  1
#define LWIP_HTTPD_MAX_CGI_PARAMETERS   20          // default is 16
#define LWIP_HTTPD_DYNAMIC_HEADERS      1
//#define HTTPD_DEBUG                     LWIP_DBG_ON
#define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_INTERNAL | EMAC_PHY_INT_MDIX_EN |      \
                         EMAC_PHY_AN_100B_T_FULL_DUPLEX)
#define PHY_PHYS_ADDR      0
#define NUM_TX_DESCRIPTORS 24
#define NUM_RX_DESCRIPTORS 8

//*****************************************************************************
//
// ---------- Platform specific locking ----------
//
//*****************************************************************************
#define SYS_LIGHTWEIGHT_PROT            1           // default is 0
#define NO_SYS                          1           // default is 0
#if !NO_SYS
#define LWIP_COMPAT_MUTEX               1
#define RTOS_FREERTOS                   1
#endif /* !NO_SYS */
//#define MEMCPY(dst,src,len)             memcpy(dst,src,len)
//#define SMEMCPY(dst,src,len)            memcpy(dst,src,len)

//*****************************************************************************
//
// ---------- Memory options ----------
//
//*****************************************************************************
//#define MEM_LIBC_MALLOC                 0
#define MEM_ALIGNMENT                     4
#define MEM_SIZE                          (64 * 1024)
//#define MEMP_OVERFLOW_CHECK             0
//#define MEMP_SANITY_CHECK               0
//#define MEM_USE_POOLS                   0
//#define MEMP_USE_CUSTOM_POOLS           0

//*****************************************************************************
//
// ---------- Internal Memory Pool Sizes ----------
//
//*****************************************************************************
#define MEMP_NUM_PBUF                     48    // Default 16
#define MEMP_NUM_RAW_PCB                4
#define MEMP_NUM_UDP_PCB                4
#define MEMP_NUM_TCP_PCB                  40    // Default 5
//#define MEMP_NUM_TCP_PCB_LISTEN         8
#define MEMP_NUM_TCP_SEG                48      // Default 16
//#define MEMP_NUM_REASSDATA              5
#define MEMP_NUM_ARP_QUEUE              15      // Default 30
//#define MEMP_NUM_IGMP_GROUP             8
//#define MEMP_NUM_SYS_TIMEOUT              8
#define MEMP_NUM_NETBUF                 0           // default is 2
#define MEMP_NUM_NETCONN                0           // default is 4
#define MEMP_NUM_TCPIP_MSG_API          0           // default is 8
#define MEMP_NUM_TCPIP_MSG_INPKT        0           // default is 8
#define PBUF_POOL_SIZE                    48    // Default 16

//*****************************************************************************
//
// ---------- ARP options ----------
//
//*****************************************************************************
#define LWIP_ARP                        1
#define ARP_TABLE_SIZE                  10
#define ARP_QUEUEING                    1
#define ETHARP_TRUST_IP_MAC             1

//*****************************************************************************
//
// ---------- IP options ----------
//
//*****************************************************************************
//#define IP_FORWARD                      0
//#define IP_OPTIONS_ALLOWED              1
#define IP_REASSEMBLY                   0           // default is 1
#define IP_FRAG                         0           // default is 1
//#define IP_REASS_MAXAGE                 3
//#define IP_REASS_MAX_PBUFS              10
//#define IP_FRAG_USES_STATIC_BUF         1
//#define IP_FRAG_MAX_MTU                 1500
//#define IP_DEFAULT_TTL                  255

//*****************************************************************************
//
// ---------- ICMP options ----------
//
//*****************************************************************************
#define LWIP_ICMP                       1
//#define ICMP_TTL                       (IP_DEFAULT_TTL)

//*****************************************************************************
//
// ---------- RAW options ----------
//
//*****************************************************************************
#define LWIP_RAW                        1
//#define RAW_TTL                        (IP_DEFAULT_TTL)

//*****************************************************************************
//
// ---------- DHCP options ----------
//
//*****************************************************************************
#define LWIP_DHCP                       1           // default is 0
#define DHCP_DOES_ARP_CHECK             ((LWIP_DHCP) && (LWIP_ARP))

//*****************************************************************************
//
// ---------- UPNP options ----------
//
//*****************************************************************************
#define LWIP_UPNP                       1

//*****************************************************************************
//
// ---------- PTPD options ----------
//
//*****************************************************************************
//#define LWIP_PTPD                       0

//*****************************************************************************
//
// ---------- AUTOIP options ----------
//
//*****************************************************************************
#define LWIP_AUTOIP                     1           // default is 0
#define LWIP_DHCP_AUTOIP_COOP           ((LWIP_DHCP) && (LWIP_AUTOIP))
                                                    // default is 0
#define LWIP_DHCP_AUTOIP_COOP_TRIES     3           // default is 9

//*****************************************************************************
//
// ---------- SNMP options ----------
//
//*****************************************************************************
//#define LWIP_SNMP                       0
//#define SNMP_CONCURRENT_REQUESTS        1
//#define SNMP_TRAP_DESTINATIONS          1
//#define SNMP_PRIVATE_MIB                0
//#define SNMP_SAFE_REQUESTS              1

//*****************************************************************************
//
// ---------- IGMP options ----------
//
//*****************************************************************************
//#define LWIP_IGMP                       0

//*****************************************************************************
//
// ---------- DNS options -----------
//
//*****************************************************************************
//#define LWIP_DNS                        0
//#define DNS_TABLE_SIZE                  4
//#define DNS_MAX_NAME_LENGTH             256
//#define DNS_MAX_SERVERS                 2
//#define DNS_DOES_NAME_CHECK             1
//#define DNS_USES_STATIC_BUF             1
//#define DNS_MSG_SIZE                    512

//*****************************************************************************
//
// ---------- UDP options ----------
//
//*****************************************************************************
#define LWIP_UDP                        1
//#define LWIP_UDPLITE                    0
//#define UDP_TTL                         (IP_DEFAULT_TTL)

//*****************************************************************************
//
// ---------- TCP options ----------
//
//*****************************************************************************
#define LWIP_TCP                        1
//#define TCP_TTL                         (IP_DEFAULT_TTL)
#define TCP_WND                         4096   // default is 2048
//#define TCP_MAXRTX                      12
//#define TCP_SYNMAXRTX                   6
//#define TCP_QUEUE_OOSEQ                 1
#define TCP_MSS                        1500        // default is 536
//#define TCP_CALCULATE_EFF_SEND_MSS      1
#define TCP_SND_BUF                     (4 * TCP_MSS)
                                                    // default is 256, was 6 *
#define TCP_SND_QUEUELEN                (4 * (TCP_SND_BUF/TCP_MSS))
//#define TCP_SNDLOWAT                    (TCP_SND_BUF/2)
//#define TCP_LISTEN_BACKLOG              0
//#define TCP_DEFAULT_LISTEN_BACKLOG      0xff

//*****************************************************************************
//
// ---------- API options ----------
//
//*****************************************************************************
//#define LWIP_EVENT_API                  0
//#define LWIP_CALLBACK_API               1

//*****************************************************************************
//
// ---------- Pbuf options ----------
//
//*****************************************************************************
#define PBUF_LINK_HLEN                  16          // default is 14
#define PBUF_POOL_BUFSIZE               512
                              // PBUF_POOL_BUFSIZE default is
                              // LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)
#define ETH_PAD_SIZE                    0           // default is 0

//*****************************************************************************
//
// ---------- Network Interfaces options ----------
//
//*****************************************************************************
//#define LWIP_NETIF_HOSTNAME             0
//#define LWIP_NETIF_API                  0
//#define LWIP_NETIF_STATUS_CALLBACK      0
//#define LWIP_NETIF_LINK_CALLBACK        0
//#define LWIP_NETIF_HWADDRHINT           0

//*****************************************************************************
//
// ---------- LOOPIF options ----------
//
//*****************************************************************************
//#define LWIP_HAVE_LOOPIF                0
//#define LWIP_LOOPIF_MULTITHREADING      1

//*****************************************************************************
//
// ---------- Thread options ----------
//
//*****************************************************************************
//#define TCPIP_THREAD_NAME              "tcpip_thread"
//#define TCPIP_THREAD_STACKSIZE          1024
//#define TCPIP_THREAD_PRIO               3
//#define TCPIP_MBOX_SIZE                 32
//#define SLIPIF_THREAD_NAME             "slipif_loop"
//#define SLIPIF_THREAD_STACKSIZE         0
//#define SLIPIF_THREAD_PRIO              1
//#define PPP_THREAD_NAME                "pppMain"
//#define PPP_THREAD_STACKSIZE            0
//#define PPP_THREAD_PRIO                 1
//#define DEFAULT_THREAD_NAME            "lwIP"
//#define DEFAULT_THREAD_STACKSIZE        0
//#define DEFAULT_THREAD_PRIO             1
//#define DEFAULT_RAW_RECVMBOX_SIZE       0
//#define DEFAULT_UDP_RECVMBOX_SIZE       0
//#define DEFAULT_TCP_RECVMBOX_SIZE       0
//#define DEFAULT_ACCEPTMBOX_SIZE         0

//*****************************************************************************
//
// ---------- Sequential layer options ----------
//
//*****************************************************************************
//#define LWIP_TCPIP_CORE_LOCKING         0
#define LWIP_NETCONN                    0           // default is 1

//*****************************************************************************
//
// ---------- Socket Options ----------
//
//*****************************************************************************
#define LWIP_SOCKET                     0           // default is 1
//#define LWIP_COMPAT_SOCKETS             1
//#define LWIP_POSIX_SOCKETS_IO_NAMES     1
//#define LWIP_TCP_KEEPALIVE              1
//#define LWIP_SO_RCVTIMEO                1
//#define LWIP_SO_RCVBUF                  0
//#define SO_REUSE                        0

//*****************************************************************************
//
// ---------- Statistics options ----------
//
//*****************************************************************************
//#define LWIP_STATS                      1
//#define LWIP_STATS_DISPLAY              0
//#define LINK_STATS                      1
//#define ETHARP_STATS                    (LWIP_ARP)
//#define IP_STATS                        1
//#define IPFRAG_STATS                    (IP_REASSEMBLY || IP_FRAG)
//#define ICMP_STATS                      1
//#define IGMP_STATS                      (LWIP_IGMP)
//#define UDP_STATS                       (LWIP_UDP)
//#define TCP_STATS                       (LWIP_TCP)
//#define MEM_STATS                       1
//#define MEMP_STATS                      1
//#define SYS_STATS                       1

//*****************************************************************************
//
// ---------- PPP options ----------
//
//*****************************************************************************
//#define PPP_SUPPORT                     0
//#define PPPOE_SUPPORT                   0
//#define PPPOS_SUPPORT                   PPP_SUPPORT

#if PPP_SUPPORT
//#define NUM_PPP                         1
//#define PAP_SUPPORT                     0
//#define CHAP_SUPPORT                    0
//#define MSCHAP_SUPPORT                  0
//#define CBCP_SUPPORT                    0
//#define CCP_SUPPORT                     0
//#define VJ_SUPPORT                      0
//#define MD5_SUPPORT                     0
//#define FSM_DEFTIMEOUT                  6
//#define FSM_DEFMAXTERMREQS              2
//#define FSM_DEFMAXCONFREQS              10
//#define FSM_DEFMAXNAKLOOPS              5
//#define UPAP_DEFTIMEOUT                 6
//#define UPAP_DEFREQTIME                 30
//#define CHAP_DEFTIMEOUT                 6
//#define CHAP_DEFTRANSMITS               10
//#define LCP_ECHOINTERVAL                0
//#define LCP_MAXECHOFAILS                3
//#define PPP_MAXIDLEFLAG                 100

//#define PPP_MAXMTU                      1500
//#define PPP_DEFMRU                      296
#endif

//*****************************************************************************
//
// ---------- checksum options ----------
//
//*****************************************************************************
#define CHECKSUM_GEN_IP                 0
#define CHECKSUM_GEN_ICMP               0
#define CHECKSUM_GEN_UDP                0
#define CHECKSUM_GEN_TCP                0
#define CHECKSUM_CHECK_IP               0
#define CHECKSUM_CHECK_UDP              0
#define CHECKSUM_CHECK_TCP              0

//*****************************************************************************
//
// ---------- Debugging options ----------
//
//*****************************************************************************
#if 0
#define U8_F "c"
#define S8_F "c"
#define X8_F "x"
#define U16_F "u"
#define S16_F "d"
#define X16_F "x"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
extern void UARTprintf(const char *pcString, ...);
#define LWIP_DEBUG
#endif

//#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_OFF
#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_OFF
//#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_WARNING
//#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_SERIOUS
//#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_SEVERE

//#define LWIP_DBG_TYPES_ON               LWIP_DBG_ON
#define LWIP_DBG_TYPES_ON               (LWIP_DBG_ON|LWIP_DBG_TRACE|          \
                                         LWIP_DBG_STATE|LWIP_DBG_FRESH)

//#define ETHARP_DEBUG                    LWIP_DBG_ON     // default is OFF
//#define NETIF_DEBUG                     LWIP_DBG_ON     // default is OFF
//#define PBUF_DEBUG                      LWIP_DBG_OFF
//#define API_LIB_DEBUG                   LWIP_DBG_OFF
//#define API_MSG_DEBUG                   LWIP_DBG_OFF
//#define SOCKETS_DEBUG                   LWIP_DBG_OFF
//#define ICMP_DEBUG                      LWIP_DBG_OFF
//#define IGMP_DEBUG                      LWIP_DBG_OFF
//#define INET_DEBUG                      LWIP_DBG_OFF
//#define IP_DEBUG                        LWIP_DBG_ON     // default is OFF
//#define IP_REASS_DEBUG                  LWIP_DBG_OFF
//#define RAW_DEBUG                       LWIP_DBG_OFF
//#define MEM_DEBUG                       LWIP_DBG_OFF
//#define MEMP_DEBUG                      LWIP_DBG_OFF
//#define SYS_DEBUG                       LWIP_DBG_OFF
//#define TCP_DEBUG                       LWIP_DBG_OFF
//#define TCP_INPUT_DEBUG                 LWIP_DBG_OFF
//#define TCP_FR_DEBUG                    LWIP_DBG_OFF
//#define TCP_RTO_DEBUG                   LWIP_DBG_OFF
//#define TCP_CWND_DEBUG                  LWIP_DBG_OFF
//#define TCP_WND_DEBUG                   LWIP_DBG_OFF
//#define TCP_OUTPUT_DEBUG                LWIP_DBG_OFF
//#define TCP_RST_DEBUG                   LWIP_DBG_OFF
//#define TCP_QLEN_DEBUG                  LWIP_DBG_OFF
//#define UDP_DEBUG                       LWIP_DBG_ON     // default is OFF
//#define TCPIP_DEBUG                     LWIP_DBG_OFF
//#define PPP_DEBUG                       LWIP_DBG_OFF
//#define SLIP_DEBUG                      LWIP_DBG_OFF
//#define DHCP_DEBUG                      LWIP_DBG_ON     // default is OFF
//#define AUTOIP_DEBUG                    LWIP_DBG_OFF
//#define SNMP_MSG_DEBUG                  LWIP_DBG_OFF
//#define SNMP_MIB_DEBUG                  LWIP_DBG_OFF
//#define DNS_DEBUG                       LWIP_DBG_OFF


#endif /* __LWIPOPTS_H__ */
  • It is TCP Client. We are facing issue of Ethernet communication, at one point communication stops, device get hang and it is not recovering or reconnecting ever. Ethernet Link Status LEDs - OFF , and there is no ping. In code we have also used Watch Dog timer , it seems it is also not Resetting controller,

    Can you provide more information? Your answers to these questions will help narrow down the problem area.

    Was the MCU running the TCP client application fine for a while before it hung? 

    If you use the debugger to examine the processor, where is it stuck?

    Is the problem happening on only one board or all boards you have running the same application?

    Does a power cycle restore the device?

    If you load a different application, will it hang or only this particular TCP client application will hang?

    Can you try some TivaWare Ethernet examples. If you try these examples, will it also hang?

    Having compiler Version below :

    CCS Version - 7.4.0

    As our application is based on Ethernet TCP Protocol, using LWIP Stack - 1.4.1.

    Although no issue with using CCS 7.4.0, this is an extremely old version.

    What TivaWare version are you using? The latest version is 2.2.0.295 which can be downloaded from https://www.ti.com/tool/SW-TM4C

  • Was the MCU running the TCP client application fine for a while before it hung?

    Yes ,Normally it is working fine ,We don't know due to high data traffic or other reason it hung, As this issue we have observed at client site,

    If you use the debugger to examine the processor, where is it stuck?

    We are not able to replicate the same issue using our set up in the lab, communication is working as intended, 

    Is the problem happening on only one board or all boards you have running the same application?

    At site our 26 devices( TCP Telnet Server - Modbus TCP) are used to communicate with SCADA system(TCP Telnet Client - Modbus TCP). Same Application is running on all devices and issue observed on any random device 

    Does a power cycle restore the device?

    Yes , After giving power cycle , device works fine 

    If you load a different application, will it hang or only this particular TCP client application will hang?

    We have not checked on any other application.

    Can you try some TivaWare Ethernet examples. If you try these examples, will it also hang?

    Yes , we can try, however issue is not getting replicate at test lab with existing firmware

    What TivaWare version are you using? 

    TivaWare Version  - 2.1.4.178 ,  Can we port our existing firmware to Version 2.2.0.195 without changing Application layer.

    Please suggest solution or work around for this problem.

  • Thanks for your clarification. In the future, please describe your problem as clearly as possible like you just did. Your original post has not much information beside the the client is somehow stuck. 

    At site our 26 devices( TCP Telnet Server - Modbus TCP) are used to communicate with SCADA system(TCP Telnet Client - Modbus TCP). Same Application is running on all devices and issue observed on any random device 

    Is Tiva MCU a Modbus client or a Modbus server? You seem to suggest the 26 devices are Tiva MCU but you said the problem is on the client for the SCADA system. 

     I will suggest you use the wireshark to see if it will provide some hints. TivaWare 2.2.0.295 also uses lwIP 1.4.1. I doubt it will produce any difference as far as your problem is concerned. 

    We are not able to replicate the same issue using our set up in the lab, communication is working as intended, 

    So the problem only happens on the field? If you can't even replicate the problem in your lab, I really don't know what to suggest. Perhaps, check your cables and as suggested use Wireshark for some hints as to when and where it fails. 

  • Hello Charles ,

    All 26 devices are Modbus TCP Servers, not Clients. Sorry, that’s my mistake. These devices are connected to a SCADA system, which acts as the Modbus TCP Client.

    We have tried a couple of things on our end to intentionally disable the PHY and read its status:

    We attempted to disable EMAC0 and PHY0 using the EMAC and PHY disable commands on a push button event. After executing the instructions MAP_SysCtlPeripheralDisable(SYSCTL_PERIPH_EMAC0) and MAP_SysCtlPeripheralDisable(SYSCTL_PERIPH_EPHY0), the MCU hangs, serial debugging stops, no further code execution occurs, and a WatchDog Reset happens. These instructions should simply disable EMAC and PHY and then execute the next instructions. What could be causing the MCU to hang and the WatchDog Reset to occur?
    The purpose of this exercise is to implement a workaround for when the PHY is not working, we want to soft reset the MCU and reinitialize the PHY.

    Please suggest a way to get the status of the PHY at runtime when the PHY is not working or has any issues.

  • I will suggest you reset EMAC and PHY instead. Calling lwIPInit again will do reset both EMAC and PHY and initiate lwIP stack again. See below snippet.

    void
    lwIPInit(uint32_t ui32SysClkHz, const uint8_t *pui8MAC, uint32_t ui32IPAddr,
    uint32_t ui32NetMask, uint32_t ui32GWAddr, uint32_t ui32IPMode)
    {
    //
    // Check the parameters.
    //
    #if LWIP_DHCP && LWIP_AUTOIP
    ASSERT((ui32IPMode == IPADDR_USE_STATIC) ||
    (ui32IPMode == IPADDR_USE_DHCP) ||
    (ui32IPMode == IPADDR_USE_AUTOIP));
    #elif LWIP_DHCP
    ASSERT((ui32IPMode == IPADDR_USE_STATIC) ||
    (ui32IPMode == IPADDR_USE_DHCP));
    #elif LWIP_AUTOIP
    ASSERT((ui32IPMode == IPADDR_USE_STATIC) ||
    (ui32IPMode == IPADDR_USE_AUTOIP));
    #else
    ASSERT(ui32IPMode == IPADDR_USE_STATIC);
    #endif

    //
    // Enable the ethernet peripheral.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EMAC0);
    MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_EMAC0);

    //
    // Enable the internal PHY if it's present and we're being
    // asked to use it.
    //
    if((EMAC_PHY_CONFIG & EMAC_PHY_TYPE_MASK) == EMAC_PHY_TYPE_INTERNAL)
    {
    //
    // We've been asked to configure for use with the internal
    // PHY. Is it present?
    //
    if(MAP_SysCtlPeripheralPresent(SYSCTL_PERIPH_EPHY0))
    {
    //
    // Yes - enable and reset it.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EPHY0);
    MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_EPHY0);
    }
    else
    {
    //
    // Internal PHY is not present on this part so hang here.
    //
    while(1)
    {
    }
    }
    }

    //
    // Wait for the MAC to come out of reset.
    //
    while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_EMAC0))
    {
    }

    //
    // Configure for use with whichever PHY the user requires.
    //
    EMACPHYConfigSet(EMAC0_BASE, EMAC_PHY_CONFIG);

    //
    // Initialize the MAC and set the DMA mode.
    //
    MAP_EMACInit(EMAC0_BASE, ui32SysClkHz,
    EMAC_BCONFIG_MIXED_BURST | EMAC_BCONFIG_PRIORITY_FIXED,
    4, 4, 0);

    //
    // Set MAC configuration options.
    //
    MAP_EMACConfigSet(EMAC0_BASE, (EMAC_CONFIG_FULL_DUPLEX |
    EMAC_CONFIG_CHECKSUM_OFFLOAD |
    EMAC_CONFIG_7BYTE_PREAMBLE |
    EMAC_CONFIG_IF_GAP_96BITS |
    EMAC_CONFIG_USE_MACADDR0 |
    EMAC_CONFIG_SA_FROM_DESCRIPTOR |
    EMAC_CONFIG_BO_LIMIT_1024),
    (EMAC_MODE_RX_STORE_FORWARD |
    EMAC_MODE_TX_STORE_FORWARD |
    EMAC_MODE_TX_THRESHOLD_64_BYTES |
    EMAC_MODE_RX_THRESHOLD_64_BYTES), 0);

    //
    // Program the hardware with its MAC address (for filtering).
    //
    MAP_EMACAddrSet(EMAC0_BASE, 0, (uint8_t *)pui8MAC);

    //
    // Save the network configuration for later use by the private
    // initialization.
    //
    g_ui32IPMode = ui32IPMode;
    g_ui32IPAddr = ui32IPAddr;
    g_ui32NetMask = ui32NetMask;
    g_ui32GWAddr = ui32GWAddr;

    //
    // Initialize lwIP. The remainder of initialization is done immediately if
    // not using a RTOS and it is deferred to the TCP/IP thread's context if
    // using a RTOS.
    //
    #if NO_SYS
    lwIPPrivateInit(0);
    #else
    tcpip_init(lwIPPrivateInit, 0);
    #endif
    }

  • Hello Charles ,

    Thank you for your suggestion , but question here is , till I get what is status of my PHY, how and exactly where I can re-initialize it. In this case, there is Link Status bit from which I will get the status of physical link only, suppose physical connection is fine, and still there is problem with communication, so what are that registers from which I can get to know that there is issue with PHY or EMAC. 

  • Hi,

      In lwIP there is the link timer that will check for link status periodically. Please refer to the lwIPServiceTimers() function in lwiplib.c file. 

    #if NO_SYS
    static void
    lwIPServiceTimers(void)
    {
    //
    // Service the host timer.
    //
    #if HOST_TMR_INTERVAL
    if((g_ui32LocalTimer - g_ui32HostTimer) >= HOST_TMR_INTERVAL)
    {
    g_ui32HostTimer = g_ui32LocalTimer;
    lwIPHostTimerHandler();
    }
    #endif

    //
    // Service the ARP timer.
    //
    #if LWIP_ARP
    if((g_ui32LocalTimer - g_ui32ARPTimer) >= ARP_TMR_INTERVAL)
    {
    g_ui32ARPTimer = g_ui32LocalTimer;
    etharp_tmr();
    }
    #endif

    //
    // Service the TCP timer.
    //
    #if LWIP_TCP
    if((g_ui32LocalTimer - g_ui32TCPTimer) >= TCP_TMR_INTERVAL)
    {
    g_ui32TCPTimer = g_ui32LocalTimer;
    tcp_tmr();
    }
    #endif

    //
    // Service the AutoIP timer.
    //
    #if LWIP_AUTOIP
    if((g_ui32LocalTimer - g_ui32AutoIPTimer) >= AUTOIP_TMR_INTERVAL)
    {
    g_ui32AutoIPTimer = g_ui32LocalTimer;
    autoip_tmr();
    }
    #endif

    //
    // Service the DCHP Coarse Timer.
    //
    #if LWIP_DHCP
    if((g_ui32LocalTimer - g_ui32DHCPCoarseTimer) >= DHCP_COARSE_TIMER_MSECS)
    {
    g_ui32DHCPCoarseTimer = g_ui32LocalTimer;
    dhcp_coarse_tmr();
    }
    #endif

    //
    // Service the DCHP Fine Timer.
    //
    #if LWIP_DHCP
    if((g_ui32LocalTimer - g_ui32DHCPFineTimer) >= DHCP_FINE_TIMER_MSECS)
    {
    g_ui32DHCPFineTimer = g_ui32LocalTimer;
    dhcp_fine_tmr();
    }
    #endif

    //
    // Service the IP Reassembly Timer
    //
    #if IP_REASSEMBLY
    if((g_ui32LocalTimer - g_ui32IPReassemblyTimer) >= IP_TMR_INTERVAL)
    {
    g_ui32IPReassemblyTimer = g_ui32LocalTimer;
    ip_reass_tmr();
    }
    #endif

    //
    // Service the IGMP Timer
    //
    #if LWIP_IGMP
    if((g_ui32LocalTimer - g_ui32IGMPTimer) >= IGMP_TMR_INTERVAL)
    {
    g_ui32IGMPTimer = g_ui32LocalTimer;
    igmp_tmr();
    }
    #endif

    //
    // Service the DNS Timer
    //
    #if LWIP_DNS
    if((g_ui32LocalTimer - g_ui32DNSTimer) >= DNS_TMR_INTERVAL)
    {
    g_ui32DNSTimer = g_ui32LocalTimer;
    dns_tmr();
    }
    #endif

    //
    // Service the link timer.
    //
    #if LWIP_AUTOIP || LWIP_DHCP
    if((g_ui32LocalTimer - g_ui32LinkTimer) >= LINK_TMR_INTERVAL)
    {
    g_ui32LinkTimer = g_ui32LocalTimer;
    lwIPLinkDetect();
    }
    #endif
    }
    #endif

  • Hello Charles,

    Using this link status I already  checked and I am getting status of physical link that is fine. other than that is there any way or registers by reading that we can identify that there is some issue with PHY / EMAC so Reset controller. 

  • I was checking different registers , found Remote Fault Bit in EPHYBMSR register and read that bit before Ethernet Initialization and after communication established , getting same value 0x00000040, indicates that , this bit is high ( Verified by disconnecting ethernet cable and Mod Poll connection)

    one more register EPHYCONFIG1 having TDR and LLR bit. Can DMA or EMAC registers be useful to detect reception or transmission error , can you please suggest exact registers. 

  • is there any way or registers by reading that we can identify that there is some issue with PHY / EMAC so Reset controller. 

    I was checking different registers , found Remote Fault Bit in EPHYBMSR register and read that bit before Ethernet Initialization and after communication established , getting same value 0x00000040, indicates that , this bit is high ( Verified by disconnecting ethernet cable and Mod Poll connection)

    one more register EPHYCONFIG1 having TDR and LLR bit. Can DMA or EMAC registers be useful to detect reception or transmission error , can you please suggest exact registers.

    Please note any EMAC status registers or bits that indicate any error can only tell you what is wrong at the EMAC hardware level. If the crashing/hanging is due to software then these EMAC status registers will not help. Your crashing/hanging could be related to the lwIP configuration or your Modbus stack. I don't really have a good hint on how to debug your problem as you mentioned you could not replicate the issue in your lab environment. 

     On the field, how long does the MCU have to run until the problem occurs? Minutes, hours or days? 

     Does the problem only occur from one particular end customer or multiple customers?

     Since you said you cannot replicate the issue on your lab environment, my below suggestion will not help. But if you can replicate the issue then you can enable lwIP debug options that will provide diagnosis information. This is useful if the issue is at the lwIP level. I don't know about your Modbus stack. Check with your Modbus stack vendor if there is such option for diagnosis. At the device level, you might also want to check your stack and heap size. Is it possible that you don't have enough stack or heap allocated that caused the device to crash/hang. Try increasing them and see if they make a difference. I really don't have other tips to offer since your problem only happens randomly and cannot be replicated on your lab environment. 

     I want to also give you a heads-up. I will be OOO for a week. My response will be very much delayed. 

    //*****************************************************************************
    //
    // ---------- Debugging options ----------
    //
    //*****************************************************************************
    #if 0 // CHANGE THIS TO 1 to ENABLE DEBUG OPTIONS
    #define U8_F "c"
    #define S8_F "c"
    #define X8_F "x"
    #define U16_F "u"
    #define S16_F "d"
    #define X16_F "x"
    #define U32_F "u"
    #define S32_F "d"
    #define X32_F "x"
    extern void UARTprintf(const char *pcString, ...);
    #define LWIP_DEBUG
    #endif

    //#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_OFF
    #define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_OFF
    //#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_WARNING
    //#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_SERIOUS
    //#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_SEVERE

    //#define LWIP_DBG_TYPES_ON               LWIP_DBG_ON
    #define LWIP_DBG_TYPES_ON               (LWIP_DBG_ON|LWIP_DBG_TRACE|          \
                                             LWIP_DBG_STATE|LWIP_DBG_FRESH)

    //#define ETHARP_DEBUG                    LWIP_DBG_ON     // default is OFF
    //#define NETIF_DEBUG                     LWIP_DBG_ON     // default is OFF
    //#define PBUF_DEBUG                      LWIP_DBG_OFF
    //#define API_LIB_DEBUG                   LWIP_DBG_OFF
    //#define API_MSG_DEBUG                   LWIP_DBG_OFF
    //#define SOCKETS_DEBUG                   LWIP_DBG_OFF
    //#define ICMP_DEBUG                      LWIP_DBG_OFF
    //#define IGMP_DEBUG                      LWIP_DBG_OFF
    //#define INET_DEBUG                      LWIP_DBG_OFF
    //#define IP_DEBUG                        LWIP_DBG_ON     // default is OFF
    //#define IP_REASS_DEBUG                  LWIP_DBG_OFF
    //#define RAW_DEBUG                       LWIP_DBG_OFF
    //#define MEM_DEBUG                       LWIP_DBG_OFF
    //#define MEMP_DEBUG                      LWIP_DBG_OFF
    //#define SYS_DEBUG                       LWIP_DBG_OFF
    //#define TCP_DEBUG                       LWIP_DBG_OFF
    //#define TCP_INPUT_DEBUG                 LWIP_DBG_OFF
    //#define TCP_FR_DEBUG                    LWIP_DBG_OFF
    //#define TCP_RTO_DEBUG                   LWIP_DBG_OFF
    //#define TCP_CWND_DEBUG                  LWIP_DBG_OFF
    //#define TCP_WND_DEBUG                   LWIP_DBG_OFF
    //#define TCP_OUTPUT_DEBUG                LWIP_DBG_OFF
    //#define TCP_RST_DEBUG                   LWIP_DBG_OFF
    //#define TCP_QLEN_DEBUG                  LWIP_DBG_OFF
    //#define UDP_DEBUG                       LWIP_DBG_ON     // default is OFF
    //#define TCPIP_DEBUG                     LWIP_DBG_OFF
    //#define PPP_DEBUG                       LWIP_DBG_OFF
    //#define SLIP_DEBUG                      LWIP_DBG_OFF
    //#define DHCP_DEBUG                      LWIP_DBG_ON     // default is OFF
    //#define AUTOIP_DEBUG                    LWIP_DBG_OFF
    //#define SNMP_MSG_DEBUG                  LWIP_DBG_OFF
    //#define SNMP_MIB_DEBUG                  LWIP_DBG_OFF
    //#define DNS_DEBUG                       LWIP_DBG_OFF