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.

[参考译文] LAUNCHXL-F2800137:printf () 影响执行

Guru**** 2519530 points
Other Parts Discussed in Thread: LAUNCHXL-F2800137

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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1559682/launchxl-f2800137-printf-affecting-excecution

器件型号:LAUNCHXL-F2800137


工具/软件:

我正在 LAUNCHXL-F2800137 上测试 SCI 通信。

我注意到当使用 printf () 语句时,它会影响程序的执行方式。

包含以下 printf() 语句将阻止 SCI_readCharBlockingFIFO() 读取更多字符。

if( xMBPortSerialInit( 0, 115200, 8, MB_PAR_NONE ) == FALSE )
    {
        printf("error: com init failed");
    }
    else
    {
        /* Enable the transmitter. */ 
        vMBPortSerialEnable( TRUE, FALSE);
        //Block Execution
        for (;;)
        {
            uint16_t receivedChar = SCI_readCharBlockingFIFO(SCIA_BASE);
            
            uint16_t rxStatus = SCI_getRxStatus(SCIA_BASE);
            if((rxStatus & SCI_RXSTATUS_ERROR) != 0)
            {
                //
                //If Execution stops here there is some error
                //Analyze SCI_getRxStatus() API return value
                //
                ESTOP0;
            }
            printf("%c\n", receivedChar);
            SCI_writeCharBlockingFIFO(SCIA_BASE, receivedChar);
        }
    }

当计算机发送“123"时“时、带有 printf() 语句的 SCI_writeCharBlockingFIFO() 将在 1ò 处停止。

删除 printf() 语句将允许代码按预期运行。

    if( xMBPortSerialInit( 0, 115200, 8, MB_PAR_NONE ) == FALSE )
    {
        printf("error: com init failed");
    }
    else
    {
        /* Enable the transmitter. */ 
        vMBPortSerialEnable( TRUE, FALSE);
        //Block Execution
        for (;;)
        {
            uint16_t receivedChar = SCI_readCharBlockingFIFO(SCIA_BASE);
            
            uint16_t rxStatus = SCI_getRxStatus(SCIA_BASE);
            if((rxStatus & SCI_RXSTATUS_ERROR) != 0)
            {
                //
                //If Execution stops here there is some error
                //Analyze SCI_getRxStatus() API return value
                //
                ESTOP0;
            }
            //printf("%c\n", receivedChar);
            SCI_writeCharBlockingFIFO(SCIA_BASE, receivedChar);
            //fflush(stdout);
        }
    }

删除 printf () 语句将允许在发送“123"时“时回显“123"。“。

为什么 printf () 会影响执行?

谢谢、

Allan

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

    嗨、Allan、

    我会 在 1-2 天内回复您。

    此致、

    Delaney

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

    嗨、Allan、

    对长时间的延误表示歉意。 如果连接调试器并运行出错工程、CPU 是卡在 printf 线路上、还是能够跳过它? 另请参阅以下有关 printf 的文档: 使用 printf 的提示 、并确保没有提到的潜在问题存在可能的因素。

    此致、

    Delaney