Jump to content

TCP connection faults using Energia

Recommended Posts


I use EK-TM4C1294XL, and I want to make a stable TCP connection between the microcontroller and a computer.

I use Energia's example "TelnetClient" to do it, when the microcontroller is the client and the computer is the server using Telnet.

I succeed to make the connection, but there are a lot of problems with it.


1. Sometimes (I can't diagnose when it happens) the controller enter to infinite loop at tcp_out.c line 937:

for (; useg->next != NULL; useg = useg->next);

When it happens, useg == useg->next.

I try to solve it by change the row to:

for (; (useg->next != NULL)|(useg->next == useg); useg = useg->next);

It seems that the problem solved, but I don't know how it affect on other functions.


2. Sometimes, when i close the computer's listener, the function client.connect don't recognize that there is no connection. So, when the listener reurn, the microcontroller don't retry to connect.


3. Sometimes, the software enter to infinite loop at EthernetClient.cpp at line 216 (in EthernetClient::write(const uint8_t *buf, size_t size)).

i=0, size = 1, and its values don't change in the loop:

// Attempt to write in 1024-byte increments.
    while (i < size) {
        inc = (size - i) < 1024 ? size - i : 1024;
        err_t err = tcp_write(cpcb, buf + i, inc, TCP_WRITE_FLAG_COPY);
        if (err != ERR_MEM) {
            // Keep enqueueing the lwIP buffer until it's full...
            i += inc;
            stuffed_buffer = false;
        } else {
            if (!stuffed_buffer) {
                // Buffer full; force output
                if (cs->mode)
                stuffed_buffer = true;
            } else {
                delay(1); // else wait a little bit for lwIP to flush its buffers


Link to post
Share on other sites

Thanks Robert,

How can I send you the sketch?

If it's short, post it here in the code feature (see the "<>" icon in the formatting toolbar above your entry window, same place where you find the Boldface, Italic, Underline, etc. icons)


If it's long or there's multiple files, zip them up and attach the .zip file to a post.  Hit "More Reply Options" to get an expansive editor window where you can attach files to your post.

Link to post
Share on other sites

I looked at the code but can not spot anything obvious that would cause this issue. Would it be possible for you to reduce the code to a minimal possible while still showing the issue? That will help me a lot to narrow it down and reproduce it here.

A thin code is attached.

There is no command requirement to start.

I saw that almost the 2nd and 3rd problems are still here.

The 1st problem is rare, so it possible that it is still here.EthernetProblems.zip

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...