mbed lpc1768 serial FIFO bug + fix

30 Aug 2013

Reposting as a new topic rather than a post on an old thread :)

The FIFO is critical because at high baud rates (e.g., 460800) firing one interrupt per received character causes too many context switches, especially when multiple serial streams are being received.

However, in the current implementation, interrupt driven serial communications (e.g., with MODSERIAL library) hangs whenever UART FIFO depth is greater than 1, because the CTI (character timeout indication) interrupt is unhandled in serial_api.c . The CTI interrupt should be fired whenever the FIFO is partially filled for longer than a few 'character times'. From the datasheet, exactly [(word length) × 7 - 2] × 8 + [(trigger level - number of characters) × 8 + 1] RCLKs. Because there is valid data in the buffer this interrupt should be handled as if it was a normal read.

So, adding support for the CTI interrupt (for 1768 at least) is a one line fix

serial_api.c snippet

switch (iir) {
        case 1: irq_type = TxIrq; break;
        case 2: irq_type = RxIrq; break;
+      case 6: irq_type = RxIrq; break;
        default: return;
}

Because the exact number of bytes read into the FIFO is unknown, interrupt based serial drivers (e.g., MODSERIAL) must also ensure they loop on .readable() to ensure all bytes are read out to empty the buffer.

An associated feature request would be to add FIFO depth control to the API and document the default initialization to 1 byte length.

Thanks, Matt

25 Sep 2013

I notice this fix isn't yet in http://mbed.org/users/mbed_official/code/mbed-src/

Could we get some feedback on this fix, and whether you will be committing it?

Ashley

14 Jan 2015

I can confirm the problem and the solution,

Can someone patch it? Is really important.

03 Mar 2015

@emuboy, can you add this to issues on github https://github.com/mbedmicro/mbed. You can then send a pull request with a solution. Thanks