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-CC1352P: Uart2_callback read error

Part Number: LAUNCHXL-CC1352P
Other Parts Discussed in Thread: SYSCONFIG

Hi:

     SDK: simplelink_cc13x2_26x2_sdk_4_40_00_44 

     Example :zed_sw_ota_client 

     MCU:CC1352P-2 LP    

     CCS version : 10

     I used Uart2_callback mode,when received data,I set an evevt in my loop,and write a string.

     Now,when I sent short data ,it's normal.But  when I send long buffer(31 bytes),my loop will run twice occasionally 

     

    I have changed the RX ring buffer to 128.

    Here is my code

     

uint8_t ch_uart;
// write a string
void hl_print_string(char *buffer)
{
    char symbol[2] = "\r\n";
    UART2_write(UartHandle,buffer,strlen(buffer),NULL);
    UART2_write(UartHandle,symbol,2,NULL);
}
//open && init
void hl_uart_open(void)
{

    UART2_Params_init(&UartParams);
    UartParams.baudRate = 115200;
    UartParams.readMode = UART2_Mode_CALLBACK;
    UartParams.readCallback = AtProcess_processingLoop;

    UartHandle = UART2_open(CONFIG_UART2_0, &UartParams);
    if(UartHandle == NULL)
    {
        hl_print_string("Error opening the UART");
    }
    else
    {
        hl_print_string("UART open success");
        status = UART2_read(UartHandle, &ch_uart, 1,NULL);
    }
}
//read callback 
void AtProcess_processingLoop(UART2_Handle _handle, void *_buf, size_t _size, void *userArg, int_fast16_t status)
{
    if (status != UART2_STATUS_SUCCESS)
    {
        hl_print_string("Error");
    }
    UART2_read(UartHandle, &ch_uart, 1,NULL);
    hlAppLoopEvents |= HL_ZED_UART_EVT;
    Semaphore_post(appSemHandle);
}
//my loop in zcl_samplesw.c
void hlApp_event_loop(void)
{
    if(hlAppLoopEvents & HL_ZED_1_EVT)
    {

        hlAppLoopEvents &= (~HL_ZED_HEART_EVT);
    }
    if(hlAppLoopEvents & HL_ZED_UART_EVT)
    {
        hl_print_string("uart");

        hlAppLoopEvents &= (~HL_ZED_UART_EVT);
    }
}

  • Hi Invoker,

    Please review the uart2callback example and UART2.h TI Drivers Runtime APIs.  The code excerpt appears to include a race condition based on how many callbacks can be invoked before the event is serviced.  I recommend using UART2_read in your HL_ZED_UART_EVT handler instead of the AtProcess_processingLoop callback, and using a UART2_read size equal to your expected number of incoming bytes or readReturnMode of UART2_ReadReturnMode_PARTIAL.  You could also use a custom end byte to determine when the loop should process the packet and return a response.

    Regards,
    Ryan

  • Hi Ryan

         I changed my code as follow, It is strange.

       1、  I change readReturnMode to UART2_ReadReturnMode_PARTIAL, and I onle set my event in the read_calback function,

       2、  In my event,I write the received byte,then read one byte. 

       3、  The length of our uart cmd is not  fixed,so I can't read a fixed number of bytes

        Now,It's normal when I send one byte.But it only write the first byte once ,when I sent 2 bytes..

    void hl_uart_write(uint8_t *inBuf,uint8_t inLen)
    {
        UART2_write(UartHandle,inBuf,inLen,NULL);
    }
    void hl_uart_read(void *buffer, size_t size)
    {
        UART2_read(UartHandle, buffer, size,NULL);
    }
    // uart init
    void hl_uart_open(void)
    {
        UART2_Params_init(&UartParams);
        UartParams.baudRate = 115200;
        UartParams.readReturnMode = UART2_ReadReturnMode_PARTIAL;
        UartParams.readMode = UART2_Mode_CALLBACK;
        UartParams.readCallback = AtProcess_processingLoop;
    
        UartHandle = UART2_open(CONFIG_UART2_0, &UartParams);
        if(UartHandle == NULL)
        {
            hl_print_string("Error opening the UART");
        }
        else
        {
            hl_print_string("UART open success");
            status = UART2_read(UartHandle, &ch_uart, 1,NULL);
        }
    }
    void AtProcess_processingLoop(UART2_Handle _handle, void *_buf, size_t _size, void *userArg, int_fast16_t status)
    {
        hlAppLoopEvents |= HL_ZED_UART_EVT;
        Semaphore_post(appSemHandle);
    }
    //my loop
    void hlApp_event_loop(void)
    {
        if(hlAppLoopEvents & HL_ZED_1_EVT)
        {
    //        hl_print_string("test");
            hlAppLoopEvents &= (~HL_ZED_1_EVT);
        }
        if(hlAppLoopEvents & HL_ZED_UART_EVT)
        {
            hl_uart_write(&ch_uart,1);
            hl_uart_read(&ch_uart,1);
            hlAppLoopEvents &= (~HL_ZED_UART_EVT);
        }
    }

  • Hi Ryan

       4、I review the uart2callback example,it call uart2read() in "while (1)", I call it at the beging of the forever loop "zclSampleSw_process_loop()",   It does work, But I don't think it's reasonable for zed.

       5、I can't add pictures by "Insert—>Image/Video/file",No URL button is selected

  • 4. Do you wake up CC1252P before you start receiving UART message?

    5. You can drag and drop image to reply box area to attach image.

  • 4. Set an event inside the UART callback to be serviced by the main process loop after the semaphore has been posted.  Or handle the UART command directly inside the callback (if the instruction is brief enough).  Refer to the TI-RTOS section of the Z-Stack User's Guide, or the ZED switch UI which already incorporates UART for a sleepy node.

    5. YK has the right idea, content insertion has changed since the E2E interface update and is still being improved upon.

    Regards,
    Ryan

  • The customer tried your suggestion, but it did not succeed.

    The length of uart commands varies, some are more than ten bytes, and some are more than thirty bytes.

    The reception is very unstable, when receiving long data in callback mode ,like:

    But  when I send long buffer(31 bytes),my loop will run twice occasionally 

  • Make sure that the RX/TX ring buffer sizes have been increased in SysConfig -> UART2, also refer to this other E2E thread: https://e2e.ti.com/f/1/t/994971 

    Regards,
    Ryan