How to recover after framing and overrun error?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to recover after framing and overrun error?

Jump to solution
635 Views
ristomustonen
Contributor II

Hi!

I'am using KV56 microcontroller with UART3 connected to Lantronix ethernet port. Everything works well until Lantronix boots itself. It keep UART RX line down so KV56 gets FE and OR errors. It also possibly detects the LIN break condition. I can reset both error flags by calling fsl_uart.c UART_ClearStatusFlags() function.

But after reset those bits KV56 cannot receive anything by UART3, although the RX data is now OK (measured with oscilloscope). If I then restart the KV56 it begins to receive characters again.

Have someone had similar kind of issues and can someone tell how can I recover from this state by software?

Best Regards,

Risto Mustonen

0 Kudos
1 Solution
393 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Risto Mustonen,

   Thanks a lot for your updated information.

   Yes, actually, UARTX_S2[LBKDE] is the LIN Break Detection Enable, it is the control bit, not the status bit.

   But, you can know it from the reference manual, and configure it.

  Anyway, if you still have question about this topic, please kindly let me know.


Have a great day,
Kerry

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
9 Replies
393 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Risto Mustonen ,

  Please try to call UART_Deinit and then initialize the UART again.

  Whether this problem still exist or not?

 If you enable the interrupt, please also disable the interrupt at first.

About the deinit code, please check the official sdk code, which can be downloaded from this link:

Welcome | MCUXpresso SDK Builder 

If you still have questions about it, please kindly let me know.
Have a great day,
Kerry

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
393 Views
ristomustonen
Contributor II

Hi Kerry,

After UART_Deinit and UART_Init the problem still exist. Every transmission attempt triggers the Receiver Overrun Flag.

I noticed that same time the S2[LBKDIF] is asserted too. According the reference manual LBKDIF can be cleared by writing '1', but write has no effect, the bit keeps on '1' state?

BR,

Risto

0 Kudos
393 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Risto Mustonen,

   You said, you called: UART_ClearStatusFlags().

This API is :

  status_t UART_ClearStatusFlags(UART_Type *base, uint32_t mask);

What's the mask you are using? Do you |kUART_RxOverrunFlag?

status_t UART_ClearStatusFlags(UART_Type *base, uint32_t mask)
{
    uint8_t reg = base->S2;
    status_t status;

#if defined(FSL_FEATURE_UART_HAS_LIN_BREAK_DETECT) && FSL_FEATURE_UART_HAS_LIN_BREAK_DETECT
    reg &= ~(UART_S2_RXEDGIF_MASK | UART_S2_LBKDIF_MASK);
#else
    reg &= ~UART_S2_RXEDGIF_MASK;
#endif

    base->S2 = reg | (uint8_t)(mask >> 8);

#if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
    base->SFIFO = (uint8_t)(mask >> 24);
#endif

    if (mask & (kUART_IdleLineFlag | kUART_NoiseErrorFlag | kUART_FramingErrorFlag | kUART_ParityErrorFlag))
    {
        /* Read base->D to clear the flags. */
        (void)base->S1;
        (void)base->D;
    }

    if (mask & kUART_RxOverrunFlag)
    {
        /* Read base->D to clear the flags and Flush all data in FIFO. */
        (void)base->S1;
        (void)base->D;
#if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
        /* Flush FIFO date, otherwise FIFO pointer will be in unknown state. */
        base->CFIFO |= UART_CFIFO_RXFLUSH_MASK;
#endif
    }

    /* If some flags still pending. */
    if (mask & UART_GetStatusFlags(base))
    {
        /* Some flags can only clear or set by the hardware itself, these flags are: kUART_TxDataRegEmptyFlag,
        kUART_TransmissionCompleteFlag, kUART_RxDataRegFullFlag, kUART_RxActiveFlag, kUART_NoiseErrorInRxDataRegFlag,
        kUART_ParityErrorInRxDataRegFlag, kUART_TxFifoEmptyFlag, kUART_RxFifoEmptyFlag. */
        status = kStatus_UART_FlagCannotClearManually;
    }
    else
    {
        status = kStatus_Success;
    }

    return status;
}

You need to really clear the related errors which you already have.

Wish it helps you!

If you still have questions about it, please kindly let me know.
Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
393 Views
ristomustonen
Contributor II

Hi Kerry,

I can see two types of errors:

- kStatus_UART_FramingError

- kUART_RxOverrunFlag

And yes, I clear both by calling:

UART_ClearStatusFlags(UART3, kStatus_UART_FramingError);

UART_ClearStatusFlags(UART3, kUART_RxOverrunFlag);

If I don't clear errors the UART is not responding any more (no errors, no nothing). When I clear errors the receiver seems to do something and continuously result with the kUART_RxOverrunFlag set. So the UART is stuck and cannot receive characters any more. Is there any other registers that I should handle to get UART back to operational state after OR flag?

BR, Risto

0 Kudos
393 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Risto,

   Thanks a lot for your updated information.

   If you continuously result with the kUART_RxOverrunFlag set.  It means you didn't read the receive buffer in time.

  When you meet the problem, can you test this point, your another UART just send the data slowly, make sure your KV56 can receive the data and clean the buffer in time.

 Any updated information, just let me know.


Have a great day,
Kerry

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
393 Views
ristomustonen
Contributor II

Hi Kerry,

The Framing Error Flag caused by external port device stopped UART transfer IRQ operation. So there was no routine to receive incoming characters. Therefore the second incoming character triggers the Overrun Flag.

The solution I found by chance was that the S2[LBKDE] bit must be set to zero after OR flag was detected. After zeroing the LIN Break Detection Enable the receiver was able to get data again. The register S2 is a little bit confusing because it is status register and that kind of registers are often read only. Also the LBKDE description of its function is a little bit confusing.

But, anyway now I know how to recover these kind of UART errors.

Have a great day,

Risto

0 Kudos
394 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Risto Mustonen,

   Thanks a lot for your updated information.

   Yes, actually, UARTX_S2[LBKDE] is the LIN Break Detection Enable, it is the control bit, not the status bit.

   But, you can know it from the reference manual, and configure it.

  Anyway, if you still have question about this topic, please kindly let me know.


Have a great day,
Kerry

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
393 Views
amerzater
Contributor III

I didnt get it right clear 

so why would I clear the control bit LBKDE after OF is issued?

did you mean the status interrupt flag bit LBKDIF?

0 Kudos
393 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Amer Zater,

  If you have the question, it's better to create your own question post, then we will help you in your own question post directly.

   Please don't answer question in the closed post, thank you.

   If you want I to reply, you also can @kerry zhou in your new question post.


Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos