Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 12 months ago.
Fixing missing Rx serial chars on the K64F
Hello,
Here is a quick fix when using the USB serial port at higher speeds (e.g. 230400). This current problem is that back-to-back characters get missed when multiple characters are sent to the K64F. Typical examples are Enter (CR LF) and up-arrow (ESC [ A), etc. The ISR cannot respond fast enough to receive all characters. This can be fixed by enabling the UART's Rx FIFO on the K64F. Example:
RawSerial pc(USBTX, USBRX); int main() { // init code.... pc.baud(230400); pc.printf("Hello World!!\r\n"); // enable the usb uart rx fifo UART_PFIFO_REG(UART0) |= 0x08; // enable the UART Rx callback interrupt pc.attach(&PcRxIRQ, pc.RxIrq); // more code }
The default UART Rx FIFO depth is 8 characters. This seems fine to me.
...kevin
1 Answer
9 years, 12 months ago.
It might be better to use the more careful Freescale UART HAL routines:
#include "mbed.h" #include "fsl_uart_hal.h" static void enable_rx_fifo(int instance) { uart_hal_disable_receiver(instance); uart_hal_disable_transmitter(instance); uart_hal_enable_rx_fifo(instance); uart_hal_enable_receiver(instance); uart_hal_enable_transmitter(instance); uart_hal_flush_rx_fifo(instance); uart_hal_flush_tx_fifo(instance); } int main() { // USBTX/USBRX is connected to UART0 RawSerial pc(USBTX, USBRX); enable_rx_fifo(0); // rest of program... }
Also, in your interrupt handler you may have to handle more than one character from the FIFO.
I think it is a bit weird if it wouldn't be fast enough to handle that, even at that baudrate it is slow compared to other interfaces.
Although if there is a FIFO it should be enabled by default.
posted by Erik - 08 May 2014Currently, it is not enabled
...kevin
posted by Kevin Braun 08 May 2014