UART4 K64F Issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART4 K64F Issue

Jump to solution
921 Views
aes_mike
Contributor III

Hello,

 

We are using UART4 on the K64F (MK64FX512VLL112) in a RS422 situation.  The RTS from the UART4 is used to control the RS422 transmitter.  The problem we are experiencing is that we are getting RX overruns and don't understand why.

 

We are using KSDK 1.2.0 and KDS 3.0.0.  This is a bare metal project.

 

We have reviewed this thread UART FIFO appears empty even though it is not (K64 & MQX 4.1)  and have implemented those changes, see attached fsl_uart_driver.c, line 632 through 674.   We are experiencing the condition of a bogus byte being received at the beginning which led us to the thread above.  The Testbed_Event() function is a function we wrote that writes the event ID (first parameter) along with two other parameters to an array of data structures which are read out at a later time creating an event log or trace buffer of sorts.

 

In our application code we call the UART_DRV_ReceiveData() indicating we need four bytes of data.  For some reason the first byte received is a byte that is not in the packet at all.  We are observing the data with both a 'scope and we have another computer monitoring the data and indeed we are only receiving four bytes, but they are not as claimed by the K64F.  We have seen that the RX_OVERRUN occurs approximately 27uS after the UART_DRV_ReceiveData() has been called; this is hardly 3-bit times into the first character (at 115200 baud).

 

Our timing is measured using the cycle counter found in the CoreSight module of the Cortex-M4.  CPU clock at 100MHz.  We are rounding the time to uS as that is close enough.

 

The serial baud rate is 115200.

 

Also, added test code at line 711 through 716 as we are occasionally losing transmit data for some unknown reason; maybe these two issues are related, not sure.

 

For the serial receive problem, I am wondering if the UART receiver is actually restarted so to speak when UART_DRV_ReceiveData() is issued or is there a way to restart or ignore any pre-existing data sitting in the UART?   Or is there another angle to resolving this issue? 

 

Any suggestions would be great!

Original Attachment has been moved to: fsl_uart_driver.c.zip

0 Kudos
1 Solution
653 Views
aes_mike
Contributor III

We resolved the issue.

What we found is that calling the UART_DRV_ReceiveData() does not clear the UART the FIFO or UART RX data register prior to the start of receiving.   Adding the following code in the UART_DRV_StartReceiveData() function resolves this issue.   Of course, this will not work if you don't know when your receive data arrives; in that case you need to implement a software FIFO and use the driver callbacks and continuously receive data.

    /* Initialize the module driver state struct to indicate transfer in progress
     * and with the buffer and byte count data */
    uartState->rxBuff = rxBuff;
    uartState->rxSize = rxSize;
    uartState->isRxBusy = true;

//new code here

#if FSL_FEATURE_UART_HAS_FIFO
    /* Read out all data from RX FIFO */
    while(UART_HAL_GetRxDatawordCountInFifo( base ) )
    {
#endif
        UART_HAL_Getchar( base, uartState->rxBuff );
#if FSL_FEATURE_UART_HAS_FIFO
    }
#endif
    UART_HAL_Getchar( base, uartState->rxBuff );

//end of new code

View solution in original post

0 Kudos
1 Reply
654 Views
aes_mike
Contributor III

We resolved the issue.

What we found is that calling the UART_DRV_ReceiveData() does not clear the UART the FIFO or UART RX data register prior to the start of receiving.   Adding the following code in the UART_DRV_StartReceiveData() function resolves this issue.   Of course, this will not work if you don't know when your receive data arrives; in that case you need to implement a software FIFO and use the driver callbacks and continuously receive data.

    /* Initialize the module driver state struct to indicate transfer in progress
     * and with the buffer and byte count data */
    uartState->rxBuff = rxBuff;
    uartState->rxSize = rxSize;
    uartState->isRxBusy = true;

//new code here

#if FSL_FEATURE_UART_HAS_FIFO
    /* Read out all data from RX FIFO */
    while(UART_HAL_GetRxDatawordCountInFifo( base ) )
    {
#endif
        UART_HAL_Getchar( base, uartState->rxBuff );
#if FSL_FEATURE_UART_HAS_FIFO
    }
#endif
    UART_HAL_Getchar( base, uartState->rxBuff );

//end of new code

0 Kudos