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.

CC2652P7: UART bytes written and buffer length don't match

Part Number: CC2652P7

Hello,

I am using a custom designed board based on CC2652P7 chip.

SDK used: simplelink_cc13xx_cc26xx_sdk_7_10_00_98

API used: UART2_write(uart, data, len,&bytesWritten);

The data printed on serial terminal is incomplete. The 'bytesWritten'(50 bytes) is less than the 'len' bytes( 59 bytes).

Why would that happen? What should I cross check?

Thanks

Karthik

  • Hello Karthik,

    Please provide additional information:

    • Can you replicate this behavior with LP-CC1352P7-4 hardware?
    • Are you operating a RF stack solution consecutively?
    • Is there an error code returned from UART2_write?
    • Can you connect the UART TX line to an oscilloscope or logic analyzer to further evaluate what bytes are being transmitted?
    • Does the bytes actually written scale with the length of bytes you intend to send (i.e. is there always a disparity of 9 bytes)? 

    Regards,
    Ryan

  • Hi Ryan,

    Here are the inline replies:

    (2) Custom RF stack in syscfg.

    (3) No error code.

    (5) There is no such pattern of 9 bytes thing. The 'bytesWritten' is always seen as 50 bytes while the 'len' increased. The more parameters I add to print statement, there is trouble. Looks like data gets chopped.

    Also, the UART baud is 230400. Tried with lower baud rates too but no use.

    Thanks

    Karthik

  • Please provide code snippets, or a simplified application file, that you know will replicate the issue.

    Regards,
    Ryan

  • Here it is:

    The following printf runs in a loop of 4 iterations.

    uart_printf("\n\r\t:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:\n\r\xff",
                                                                        radio,
                                                                        lastPacket[radio].len,
                                                                        //lastPacket[radio].lastSeqNo,
                                                                        lastPacket[radio].seqNo,
                                                                        rxPktCount[radio],
                                                                        otherPktCount[radio],
                                                                        crcErrorCount[radio],
                                                                        pristinePktCount[radio],
                                                                        noiseInPktCount[radio],
                                                                        noiseOutPktCount[radio],
                                                                        reflectionInPktCount[radio],
                                                                        reflectionOutPktCount[radio],
                                                                        interferenceInPktCount[radio],
                                                                        interferenceOutPktCount[radio],
                                                                        obstructionInPktCount[radio],
                                                                        obstructionOutPktCount[radio],
                                                                        lastPacket[radio].rssi,
                                                                        lastPacket[radio].lqi,
                                                                        lastPacket[radio].syncDelta,
                                                                        lastPacket[radio].missedAcks,
                                                                        (channel_number_table_last[radio] - 11)*5 + 2405,
                                                                        lastASN);

    void uart_printf(const char *format, ...)
    {
        va_list args;
        va_start(args, format);

        char buffer[128]; // Adjust buffer size as needed
        vsnprintf(buffer, sizeof(buffer), format, args);

        va_end(args);

        uart_send_data((const uint8_t *)buffer, strlen(buffer));
    }

    void uart_send_data(const uint8_t *data, uint32_t len)
    {
        size_t bytesWritten = 0;
        int16_t return_status;
        return_status = UART2_write(uart, data, len,&bytesWritten);

        //Karts[15-02-2024]: error handling
        if(return_status == UART2_STATUS_EINUSE)
        {
            uart_printf("\n uart error UART2_STATUS_EINUSE \n\r");
            while(1);
        }
        else
        {
            ;
        }
    }

    Thanks

    Karthik

  • Hi Karthik,

    You should debug uart_send_data at UART2_write to ensure that the parameters are always correct and have not been incorrectly altered by vsnprintf.  You have also displayed an incomplete monitoring of the return status, as many more are available.  Also monitor the value of bytesWritten to see if it matches your expectations.  Please determine whether using uart_printf with a single parameter which contains >50 bytes (i.e. string) displays similar behavior.  To save time and work around your current problem, you could simply expand uart_printf into multiple calls with less parameters of each.

    Regards,
    Ryan

  • Hi Ryan,

    The bytesWritten is always 50.

    Example with string greater than 50 byes:

    uart_printf("\r\n qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm");

    Please see the snapshot:

    Thanks

    Karthik

  • The following code snippet resolved the issue:

    void uart_send_data(const uint8_t *data, uint32_t len) {
        int16_t return_status;

        for (uint32_t i = 0; i < len; i++) {
            return_status = UART2_write(uart, &data[i], 1, NULL);

            // Karts[15-02-2024]: error handling
            if (return_status == UART2_STATUS_EINUSE) {
                uart_printf("\n uart error UART2_STATUS_EINUSE \n\r");
                while (1);
            }
            // Add other error handling conditions if needed
        }
    }

    Also, in the syscfg the Tx ring buffer was configured to 50. Guess that caused this issue.

    Thanks

    Karthik