AnsweredAssumed Answered

Going crazy with UART (witch hunt)

Question asked by biafra on Apr 20, 2018
Latest reply on May 31, 2018 by biafra

Hi everyone,


I'm going crazy using a (simple) UART: I'm spending a lot of hours searching for a bug that corrupts data.

I'm using a custom board with MK66F2M0 device, MCUXpresso 10.1.1, SDK 2.3.0 and UART FreeRTOS driver: the UART is connected to a GSM modem. The UART seems to work fine, the modem answers to several init AT commands: I say seems because the received strings are random corrupted. With a computer using another modem and a serial terminal program, I can establish the connection (ATD command), receiving the CONNECT string on both sides (said that on the embedded side the string can be randomly corrupted).

At this time I send several data all the same (0x01 char repeated 144 times): at the end of the transfer I break the execution to watch the received buffer (2k buffer size), I can see that some of the data are not what I expect them to be (on average 2/3 to 9/10 bytes are corrupted, sometimes even none).


I've made many trials to find the cause, but none of them was useful.

  • Changed board
  • Changed modem
  • Increased priority of the UART interrupt
  • Increased priority of the receiving task
  • Decreased the baud rate (from 57600 to 9600)
  • Verified the line from modem to K66 with an oscilloscope (all data are ok)
  • Added a check every time the data register is read to see if the data is received as I expect it to be:

uint8_t rcfifo1 = base->RCFIFO;
uint8_t a = base->D;
uint8_t rcfifo2 = base->RCFIFO;
*(data++) = a;
if( a != 1 )

a = rcfifo1 + rcfifo2; //an instruction to hit the breakpoint

  • If I put a breakpoint on the last line, the execution stops when there is the error: the corrupted data is read from the UART data register, it's not a buffer related problem; at this time rcfifo1 and rcfifo2 are always 1 and 0 respectively: the data in the RXFIFO was present, the data reading was not done when the FIFO was empty


The same board is used even for another project where there is another serial device instead of the modem: in this case the UART works fine with the same driver.


I ported the UART interrupt example supplied with the SDK (no FreeRTOS), and repeated the test: all the data are ok, no corruption is found.


At this point I suspect that some other task can accidentally access to the UART and produce the problem, but how can I find the cause?

I tried using some watchpoint, but with no success.

Does anyone have some suggestion, some method to use to discover the issue?


Many thanks