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.

CC2340R2: UART read callback not occurring again if UART read buffer exits

Part Number: CC2340R2

Tool/software:

Hi,

  Currently I am working on example basic_ble peripheral profile project.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define UART_MAX_READ_SIZE 248 //MTU exchange value
uint8_t uartReadBuffer[UART_MAX_READ_SIZE];
void UART_Init()
{
/* Create a UART in CALLBACK read mode */
UART2_Params_init(&uartParams);
uartParams.readMode = UART2_Mode_CALLBACK;
uartParams.readCallback = UARTCallback;
uartParams.readReturnMode = UART2_ReadReturnMode_PARTIAL;
uartParams.baudRate = 115200;
uartParams.eventCallback = UARTEventCallback;
uartParams.eventMask = UART2_EVENT_OVERRUN;
uart = UART2_open(CONFIG_UART2_0, &uartParams);
if (uart == NULL)
{
/* UART2_open() failed */
while (1)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

while sending 248 bytes from module to mobile, data receiving in mobile in single chunks 248(MTU exchanged value).If I send 250 bytes from module to mobile, data receiving in mobile 248 bytes in a  single chunks 248(MTU exchanged value) those remaining 2 bytes will not receive. Those 2 bytes will receive on next packet send. Where the UART read callback is not occurring for those 2 bytes.

Upto 16 bytes UART read callback is not occurring.If more than 16 bytes callback is occuring.

SDK Version : simplelink_lowpower_f3_sdk_8_10_01_02 (peripheral)

CCS version: CCS 12.7.1

Thanks,

Vignesh.

  • Hi Vignesh,

    We have a uart2callback example here: https://dev.ti.com/tirex/explore/node?node=A__AKdlpPkvwtCAe6soBzKbpQ__com.ti.SIMPLELINK_LOWPOWER_F3_SDK__58mgN04__LATEST

    For that one, I just modified it so that the input is 248 bytes (UART read buffer).

    I do still see the callback being invoked if fewer than 16 bytes are received (specifically, it is taking keyboard input, so any 1 key press is being registered and printed to serial terminal).

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /*
    * 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,
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    To try this yourself, you can paste the code to the uart2Callback example.

    Can you run your code without BLE? To see if the UART callback is occurring when receiving 16 bytes or fewer.
    If the issue is only occurring when BLE is running, then we'll need to consult the BLE experts.

    Thanks,
    Toby

  • Hi Toby,

    I have tried above code in uart2Callback example. I have sent 250 bytes and data printed on UART was 248 bytes upon sending next 250 bytes, previous packet remaining bytes printing on UART. 

    After I have sent 250 bytes and UART read will happened for 248 bytes and data will print on UART and  for those 2 bytes again callback has to occur. 

    Thanks,

    Vignesh.

  • Hi Vignesh,

    So is this the same issue as with BLE?

    Upto 16 bytes UART read callback is not occurring.If more than 16 bytes callback is occuring.

    ^ have you confirmed the following about 16 bytes too?
    E.g. try to send

    1. 16 bytes or less --> callback occurs?
    2. more than 16 bytes --> callback occurs?

    For your experiment with uart2Callback:

    Is this the same behavior you see in your BLE project?

    Can you confirm if this is what you mean?

    1. Devices: DUT = CC2340R2, UTX = UART transmitter
    2. UTX sends 250 bytes to DUT 
    3. DUT receives bytes and UART callback executes, then DUT prints out 248 bytes
    4. For remaining 2 bytes not printed (call it UTX-step-2-last-2-bytes) sent by UTX in step 2, DUT has no UART callback
    5. UTX sends next 250 bytes to DUT
    6. DUT receives bytes and UART callback executes, then DUT prints out UTX-step-2-last-2-bytes AND also the 246 bytes from step 5 (so 2 + 246 = total of 248 bytes printed out). Meaning last 4 bytes from UTX-step-5 is NOT printed out.

    Thanks,
    Toby

  • Hi Toby,

    So is this the same issue as with BLE?

    Yes, The same issue as with BLE.

    E.g. try to send

    1. 16 bytes or less --> callback occurs?

      -  In BLE code  248 bytes with more than 5 bytes- callback occurs.

    more than 16 bytes --> callback occurs?

      - Yes, callback occurring.

    For your experiment with uart2Callback:

    Is this the same behavior you see in your BLE project?

    Can you confirm if this is what you mean?

    1. Devices: DUT = CC2340R2, UTX = UART transmitter
    2. UTX sends 250 bytes to DUT 
    3. DUT receives bytes and UART callback executes, then DUT prints out 248 bytes
    4. For remaining 2 bytes not printed (call it UTX-step-2-last-2-bytes) sent by UTX in step 2, DUT has no UART callback
    5. UTX sends next 250 bytes to DUT
    6. DUT receives bytes and UART callback executes, then DUT prints out UTX-step-2-last-2-bytes AND also the 246 bytes from step 5 (so 2 + 246 = total of 248 bytes printed out). Meaning last 4 bytes from UTX-step-5 is NOT printed out.

    Correct, The above sequence has happening in both uart2Callback.c and also with BLE code.

    Thanks,

    Vignesh.

  • Hi Vignesh,

    Note that for non-blocking mode, there is a RingBuffer which is used (see <ccs project>/Debug/syscfg/ti_drivers_config.c --> uart2RxRingBuffer0).
    There may be leftover bytes there due to 250 bytes being sent by UTX vs the 248 bytes being requested in UART2_read.

    I think the issue is related to sending more bytes than the buffer can hold.

    I recommend to try increasing size of your UART buffer to be at least as large as the max data you expect to have. In your case, it seems to be 250, so size the buffer to 250 (instead of 248). Note that the BLE transmit should still be limited to 248.

    Thanks,
    Toby