Community Translation - Handling Error Conditions with UDB UART in PSoC® 3, PSoC 4, PSoC 5LP Designs – KBA221688

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I'd like to translate this KBA221688 into Japanese.

moto

Original KBA: KBA221688

Handling Error Conditions with UDB UART in PSoC® 3, PSoC 4, PSoC 5LP Designs – KBA221688

Being Translated by: MoTa_728816

====================================

タイトル: PSoC 3, PSoC 4, PSoC 5LP 設計での UDB UART のエラーコンディション対応 - KBA221688

質問:

PSoC 3, PSoC 4, PSoC 5LP を使用した設計で、UDB UART を使用時にエラーコンディションを正しく処理するのにはどうしたら良いでしょうか?

回答:

UDB UART はパリティ、ストップビット、オーバーランなどのエラー検出をサポートしています。これらのエラーを確かに検出するためにはコードを正しく処理する必要があります。以下、読みやすさのためにコンポーネントのインスタンス名は UART とします。

UART には2つのオペレーションモードがあります: FIFO モード (RX バッファのサイズが 4 の場合) と バッファモード (RX バッファサイズが 4より大きい場合)。

現行の UART_GetChar() 関数の実装においては:

 ・バッファモードでは RX FIFO を直接読んで、その後 RX FIFO のステータスをクリアします。そのため、RX の割込みは発生されません、

  そして UART_GetChar() の戻り値が 0 の場合には以下のエラーが発生したことを示します。

  ・読むべきデータがない。

  ・UART でなんらかのエラーが発生した。

しかし、これらのケースを区別できる必要があります。もしエラーが発生した場合、その文字または受信したパケットを破棄する必要があります。一方、データが無い場合というのはパケットの終了を意味します。

そのためバッファモードで UART_GetChar() が使用されるとエラーを適切に検出できない可能性があります。ワークアラウンドとしては、バッファにデータがあるか確認後、UART_GetChar()  をコールします。この方法であれば問題を原因となるデータの RX FIFO からの直接読出しが行われないことが保証されます。

問題を回避するために下記のコードをお使いいただけます。

void ReadPacket(void)

{

    uint8 packet[PACKET_SIZE]; /* Rx バッファのサイズ > 4 */

    uint8 idx = 0u;

  

    /* UART バッファからパケットを取得する */ 

    while ((UART_GetRxBufferSize() > 0u) && (idx < PACKET_SIZE))

    {

        packet[idx] = UART_GetChar();

        /* 受信した1バイトをエコーする */

  UART_PutChar(packet[idx]);

        idx++;

    }

  

    /* エラー (例えばフレームエラー等)が発生したかを確認する */

    if (0u != (UART_errorStatus & UART_RX_STS_STOP_ERROR))

    {

        /* パケットを無効にマークする */

        packet[0u] = 0xFF;

              

        UART_DisableRxInt();

        /* RX バッファをクリアする */

        UART_ClearRxBuffer();

      

        /* エラー検出用変数をクリアする */

        UART_errorStatus = 0u;

        UART_EnableRxInt();

      

        /* 以降にフレーミングエラーが発生したことを示す(例えば GPIO ピンを立てる等の)コードを追加できます。 */

    }

}

====================================

2-Apr-2020

Motoo Tanaka

0 Likes
2 Replies
JennaJo
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hello, Tanaka-san

We receive your translation, it will be published to KBA to Community.

After upload, You will receive the points as the word of KBA.

Please bear with me for the delayed the response,

Thanks for your contribution to CDC!

Will keep you update the status.

Thanks,

Jenna Jo

Jenna Jo
JennaJo
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Dear, Tanaka-san

Your translation has been published !

Sorry for the delayed response.

PSoC 3, PSoC 4, PSoC 5LP 設計での UDB UART のエラーコンディション対応 - KBA221688- Community Translated (JA)

As a token of appreciation, you will receive the point.

As we will discuss on update point rule, it will be updated at early of May.

Thanks for your contribution !

Best Regards,

Jenna Jo

Jenna Jo