This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] UART2_writeCancel ()/UART2_CLOSE ()在外设断开连接时挂起

Guru**** 2341720 points
Other Parts Discussed in Thread: CC1312R7
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/1505577/uart2_writecancel-uart2_close-hangs-when-peripheral-is-disconnected

器件型号:CC1312R7

工具/软件:

您好、

我们正在成功使用 CoreSDK 8.30.02.00和 UART2与我们 CC1312R7的外设进行通信。 我们使用`UART2_Mode_Blocking`写入。  但是、如果外设断开连接、使 TX、RX、CTS 和 RTS 引脚保持悬空、对`UART2_CLOSE ()`的调用将挂起、永远不会返回。 研究一个位后、发现这是对 `UART2_writeCancel ()`的内部调用正在挂起-我尚未对其进行调试、但我假设这是 UART2.c:824处 等待 活动 TX 完成的 while 循环。 我本来不希望出现这种问题、因为我们对写入使用阻塞模式。

在 TX:

  1. 初始化 UART (writeMode = UART2_Mode_blocking)
    1. 好的
  2. TX 6字节使用 UART2_writeTimeout ()
    1. 令人惊讶的是、这始终返回 UART2_STATUS_SUCCESS (0)
  3. UART2_writeCancel ()
    1. 好的
  4. UART2_CLOSE ()
    1. 好的

再添加一个 TX 以引发问题:

  1. 初始化 UART (writeMode = UART2_Mode_blocking)
    1. 好的
  2. TX 6字节使用 UART2_writeTimeout ()
    1. 令人惊讶的是、这总是会返回成功
  3. TX 6字节使用 UART2_writeTimeout ()
    1. 采用 UART2_STATUS_ETIMEOUT (-9)时按预期失败
  4. UART2_writeCancel ()
    1. 挂起

这是预料之中的吗?


此致、

Andreas

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Andreas:

    让我来看看、今天晚些时候我会回来给您。

    此致、

    Arthur

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Andreas:

    您使用的超时值是多少? 使用以下代码时似乎无法重现此问题:

    /*
     * Copyright (c) 2020, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *  ======== uart2echo.c ========
     */
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART2.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        char input;
        const char sixBytes1[6] = "Hello";
        const char sixBytes2[6] = " you!";
        UART2_Handle uart;
        UART2_Params uartParams;
        size_t bytesRead;
        size_t bytesWritten = 0;
        uint32_t status     = UART2_STATUS_SUCCESS;
    
        /* Call driver init functions */
        GPIO_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        UART2_Params_init(&uartParams);
        uartParams.baudRate = 115200;
        uartParams.writeMode = UART2_Mode_BLOCKING;
    
        /* Turn on user LED to indicate successful initialization */
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    
        /* Loop forever echoing */
        while (1)
        {
            uart = UART2_open(CONFIG_UART2_0, &uartParams);
    
            if (uart == NULL)
            {
                /* UART2_open() failed */
                while (1) {}
            }
    
            status = UART2_writeTimeout(uart, sixBytes1, 6, &bytesWritten, 1000);
    
            if (status != UART2_STATUS_SUCCESS)
            {
                /* UART2_write() failed */
                while (1) {}
            }
    
            #if 1
            status = UART2_writeTimeout(uart, sixBytes2, 6, &bytesWritten, 1000);
    
            if (status != UART2_STATUS_SUCCESS)
            {
                /* UART2_write() failed */
                while (1) {}
            }
    
            UART2_writeCancel(uart);
            #endif
            
    
            UART2_close(uart);
            sleep(1);
        }
    }

    可以看到、我使用1000超时、UART 配置为在115200波特下运行。

    我现在将尝试使用硬件流控制引脚(RTS、CTS)。

    此致、

    Arthur

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Arthur:

    我正在使用2s 超时。 我的周期为10us、因此超时值为200000

    /**< Timeout when TXing, in ticks. 200000 = 2 s (1 tick = 10 us on cc13xx NoRTOS). */
    #define TX_TIMEOUT        200000
    如果您无法重现、我也可以尝试制作一个最小的示例。 您的写入是否成功或超时?
    我使用的波特率为460800。
    以下是我的硬件属性(如果相关):
      {
        .baseAddr           = UART1_BASE,
        .intNum             = INT_UART1_COMB,
        .intPriority        = (~0),
        .rxPin              = CONFIG_GPIO_UART2_MODEM_RX,
        .txPin              = CONFIG_GPIO_UART2_MODEM_TX,
        .ctsPin             = CONFIG_GPIO_UART2_MODEM_CTS,
        .rtsPin             = CONFIG_GPIO_UART2_MODEM_RTS,
        .flowControl        = UART2_FLOWCTRL_HARDWARE,
        .powerId            = PowerCC26XX_PERIPH_UART1,
        .rxBufPtr           = uart2RxRingBuffer1,
        .rxBufSize          = sizeof(uart2RxRingBuffer1),
        .txBufPtr           = uart2TxRingBuffer1,
        .txBufSize          = sizeof(uart2TxRingBuffer1),
        .txPinMux           = IOC_PORT_MCU_UART1_TX,
        .rxPinMux           = IOC_PORT_MCU_UART1_RX,
        .ctsPinMux          = IOC_PORT_MCU_UART1_CTS,
        .rtsPinMux          = IOC_PORT_MCU_UART1_RTS,
        .dmaTxTableEntryPri = &dmaUart1TxControlTableEntry,
        .dmaRxTableEntryPri = &dmaUart1RxControlTableEntry,
        .rxChannelMask      = 1 << UDMA_CHAN_UART1_RX,
        .txChannelMask      = 1 << UDMA_CHAN_UART1_TX,
        .txIntFifoThr       = UART2CC26X2_FIFO_THRESHOLD_1_8,
        .rxIntFifoThr       = UART2CC26X2_FIFO_THRESHOLD_4_8
      },
    我现在注意到我配置了 TX 振铃缓冲区、我想在仅使用阻塞写入时并不是绝对必要的。 在任何情况下、该长度都是32个字节。
    Andreas
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Andreas:

    没有必要,我设法重现的行为。 停止 RX 器件、可以达到与您相同的目的:

    我将进一步研究这一点。  

    此致、

    Arthur

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Andreas:

    顺便说一下、您是否已经制定了解决方案? 请告诉我、然后我可以尝试找到一个

    此致、

    Arthur

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    没有。  在我们的应用中不应该出现这种情况(在本例中为外设断开连接)、我们也没有在现场遇到过这种情况、因此我没有优先考虑。 因此、无需匆忙寻找权变措施、但在某个时候关闭这个临界情况会很好。

    Andreas