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/TM4C1294KCPDT: Hard fault tnside lwip tcp_output()

Part Number: TM4C1294KCPDT

Tool/software: Code Composer Studio

Hello!

I work on project where custom board based on TM4C129K MCU is connecting to external device via TCP/IP. The traffic is rather big - device sends me data at up to 125kb/sec, but controlling traffic from my board to device is not big. 

Rarely (about once per couple of days) I got hard fault inside tcp_output() function:

    if (TCP_TCPLEN(seg) > 0) {
      seg->next = NULL;
      /* unacked list is empty? */
      if (pcb->unacked == NULL) {
        pcb->unacked = seg;
        useg = seg;
      /* unacked list is not empty? */
      } else {
        /* In the case of fast retransmit, the packet should not go to the tail
         * of the unacked queue, but rather somewhere before it. We need to check for
         * this case. -STJ Jul 27, 2004 */
        if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))) {
          /* add segment to before tail of unacked list, keeping the list sorted */
          struct tcp_seg **cur_seg = &(pcb->unacked);
          while (*cur_seg &&
            TCP_SEQ_LT(ntohl((*cur_seg)->tcphdr->seqno), ntohl(seg->tcphdr->seqno))) {
              cur_seg = &((*cur_seg)->next );
          }
          seg->next = (*cur_seg);
          (*cur_seg) = seg;
        } else {
          /* add segment to tail of unacked list */
          useg->next = seg;
          useg = useg->next; // <---- HERE!
        }
      }
    /* do not queue empty segments on the unacked list */
    } else {
      tcp_seg_free(seg);
    }
    seg = pcb->unsent;

in the line 

useg = useg->next;

and useg here is ether 0 of corrupt.

Asked on lwip support forum, but they said the version of lwip is old and is a port by TI, so I should ask TI engineers.

Currently device is stopped in debug state right after hard fault, so I can browse any variables or memory.

The heap state at time of fault is ok, as I embedded heap checking in hard fault ISR.

  • Hi Oleg,

     Can you check your stack size? Is it possible that you have a stack overflow? Here is an app note that will help you diagnose hard faults. 

    https://www.ti.com/lit/pdf/spma043

     Another thing to check is the below options in the lwipopts.h file. In the TivaWare ethernet examples (e.g. enet_io, enet_lwip) the below memory and tcp options are used. I don't know what your configurations are. You might want to try with larger MEM_SIZE, MEMP_NUM_PBUF and  MEMP_NUM_TCP_PCB to see if they make any differences.   

    Since you said the problem will only occur after many days, I will close the thread for now and you can update this post again if you have new findings.    

                  

    //*****************************************************************************
    //
    // ---------- 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                  16    // Default 5
    //#define MEMP_NUM_TCP_PCB_LISTEN         8
    //#define MEMP_NUM_TCP_SEG                16
    //#define MEMP_NUM_REASSDATA              5
    //#define MEMP_NUM_ARP_QUEUE              30
    //#define MEMP_NUM_IGMP_GROUP             8
    #define MEMP_NUM_SYS_TIMEOUT              8
    //#define MEMP_NUM_NETBUF                 2
    //#define MEMP_NUM_NETCONN                4
    //#define MEMP_NUM_TCPIP_MSG_API          8
    //#define MEMP_NUM_TCPIP_MSG_INPKT        8
    #define PBUF_POOL_SIZE                    48    // Default 16