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.

[参考译文] CC1352R:UART 期间阻止程序

Guru**** 2482225 points


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

https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/1213802/cc1352r-program-is-blocked-during-uart

器件型号:CC1352R

我正在编写一个程序、在其中实施2个 UART 连接。 第一个是在带有 CC1352的电路板和用户控制台(PC)之间。  第二个 是在带有 CC1352的电路板和 外部器件(激光)之间。  

UART 声明:

/* UART */
UART2_Handle uart, uartLaser;
UART2_Params uartParams, uartParamsLaser;
char buf[30]; // Buffer to read from UART

/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    (...)
    
    /* UART2 to communicate between laser and Mars */
    uint32_t status = UART2_STATUS_SUCCESS;
    UART2_Params_init(&uartParams);
    uartParams.baudRate = 115200;
    uartParams.readMode = UART_MODE_BLOCKING;
    uartParams.writeMode = UART_MODE_BLOCKING;
    uart = UART2_open(CONFIG_UART2_1, &uartParams);

    /* UART2 to communicate between laser and Mars */
    UART2_Params_init(&uartParamsLaser);
    uartParamsLaser.baudRate = 115200;
    uartParamsLaser.readMode = UART_MODE_BLOCKING;
    uartParamsLaser.writeMode = UART_MODE_BLOCKING;
    uartLaser = UART2_open(CONFIG_UART2_0, &uartParamsLaser);
    
    (...)
}

我在 UART 中使用的函数:

*
 *  ======== readAndPrintUart ========
 *
 *  Read from one uart (for example Laser)
 *  And print to another uart (for example console)
 */
void readAndPrintUart (UART2_Handle uartRead, UART2_Handle uartPrint) {
    uint32_t status = UART2_STATUS_SUCCESS;
    status = UART2_read(uartRead, &buf, 30, NULL);
    if (status != UART2_STATUS_SUCCESS)
    {
        LED_setOn(ledHandle[1], 100);
        /* UART2_read() failed */
        while (1) {}
    }
    writeToUart(buf, uartPrint);
}

/*
 *  ======== writeToUart ========
 */
void writeToUart (char* text, UART2_Handle uart2handle) {
    size_t bytesWritten = 0;
    uint32_t status     = UART2_STATUS_SUCCESS;
    bytesWritten = 0;
    while (bytesWritten == 0) {
        //LED_setOn(ledHandle[0], 100);
        status = UART2_write(uart2handle, text, strlen(text), &bytesWritten);
//        if (status != UART2_STATUS_SUCCESS) {
//            /* UART2_write() failed */
//            while (1) {}
//        }
    }
}

不幸的是、当我使用readAndPrint()函数时、程序被阻止。 当我按 Suspend 键时、Programs (程序)会转至:

/*
 *  ======== Error_policyMin ========
 */
/* REQ_TAG(SYSBIOS-855) */
Void Error_policyMin(Error_Block *eb, Types_ModuleId mod, CString file,
    Int line, Error_Id id, IArg arg1, IArg arg2)
{
    /* REQ_TAG(SYSBIOS-852) */
    if (eb == NULL || (UInt)Error_policy == (UInt)Error_TERMINATE) {
        for(;;) {
        }
    }
    else {
        if (eb != &xdc_runtime_Error_IgnoreBlock) {
            eb->id = id;
        }
    }
}
 

在第10行。

仅当我在两个循环中使用 readAndPrint()时才会发生(这是程序中所要求的),但它仅发生在该函数的第三次调用上。例如:

for (...) {
    for (...) {
        (...)
        readAndPrint(uartLaser, uart);
        readAndPrint(uartLaser, uart);
        readAndPrint(uartLaser, uart);
        readAndPrint(uartLaser, uart);
    }
}

我尝试清除缓冲区、但它没有任何变化。

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

    您好!

    我想你的意思是 readAndPrintUart()在你的代码中是 readandPrint()。 我没有看到 readAndPrint

    我会测试较小的代码块以识别问题。 您的 readandPrintuart()函数是独立运行的吗?

    是否可以连续3次调用(不使用循环)?

    如果线程中发生的事情太多,可能是堆栈溢出? 在 main_tirtos 中增加线程堆栈大小。

    此致、
    SID