Serial Delaying TCP [Explained]


So I had an issue with TCP/HTTP client that I assumed was being caused by CC3000 Patch “not sticking” or rather not working no more. That original post is here.

But without having to go through all that, here are the issues I was experiencing.

  1. The cyan flashing which usually was associated with a device constantly having a “connection fail” using TCP client. Along with this, transmissions would be slow and after 2-5 successful transmissions a series of connection fails would occur.
  2. Hard fault that occurred regularly and was happening when using TCP client as well during regular actions, nothing to crazy happens.

I was able to fix all of these issues, especially the slow/unreliable transmissions, by removing ALL my Serial.print() statements.

Now I knew before hand that having too many print statements could cause sluggish transmissions and connection fails. But I was still experiencing all my described issues even when I was down to ONE print statement, which was just “200” to know when I made a successful transmission.

So I was wondering if anyone knows why this is occurring? Am I using too much memory potentially, are there just general issues with the Serial and TCP right now that don’t make them mesh? I have fixed the issue as I said but just for my own knowledge, also making things easier when developing, any insight would be great :slight_smile:

@UST, I will assume in your “fix” that you also properly flush incoming TCP bytes as per @bko’s instructions in multiple threads. Not doing so causes the CC3000 buffer to overflow and the Core goes into a hard fault.

The thing to remember with Serial ports is that the firmware only creates a 64 byte ring buffer which fills very fast if you are printing a lot of stuff. Once the buffer is full, the print code will block waiting for buffer space. Even at 115Kbaud, that’s 86us per char of delay. So with a full buffer and a 20 char message waiting to print, that’s 1.72ms delay! That blocking will lead to unexpected delays in your code, which in your case, causes obvious problems.

So, the issue is not necessarily the blocking but WHERE the blocking occurs in your code as a result of the Serial prints. Considering the time it takes to flush the buffer between Serial prints helps. If you compile with a local toolchain, you can also increase the ring buffer size. :smile: