Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

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.

CC2642R: Device getting hanged during sending data through ble

Part Number: CC2642R

Hi,

As per my use-case i am receiving 10 KB of data in 27 bytes chunks from UART, After receiving data, I am writing 20 bytes data back on UART as an acknowledgement,  then sending 20 byte from UART received data to all connected BLE central devices (MAX devices = 8) though BLE notification. But sometimes in this scenario ble device getting hanged or all connected central devices got disconnected.

UART BAUD_RATE is 115200,

/*********************************************************************
* @fn UART_Configuration
*
* @brief function for initializing UART.
*
* @param None.
*
* @return None.
*/
bool UART_Configuration(void)
{
UART_init();
UART_Params_init(&SbpUartParams);
SbpUartParams.readMode = UART_MODE_CALLBACK;
SbpUartParams.writeMode = UART_MODE_BLOCKING;
SbpUartParams.readCallback = &uart_readcallback;

SbpUartHandle = UART_open(Board_UART0, &SbpUartParams);
if( SbpUartHandle == NULL ) {
return false;
}

memset(send_data_buff, 0, sizeof(send_data_buff));
memset(read_buff, 0, sizeof(read_buff));

rx_data_len = PACKET_HEADER_INFO_LEN;
UART_read(SbpUartHandle, read_buff, rx_data_len);

return true;
}

this is my uart intialization code.

void uart_readcallback(UART_Handle handle, void *ptr, size_t size)
{
// Copy UART RX data to buffer
memcpy(&read_data[rd_index], read_buff, rx_data_len);

// Cancel uart read
UART_readCancel(SbpUartHandle);

// Post event to wake up the application
SimplePeripheral_enqueueMsg(UART_TX_EVT, NULL);

// notifing data here.
// length of 20 bytes

// Enable uart read.
UART_read(SbpUartHandle, read_buff, rx_data_len);
}

Above is my Uart read callback function and in UART_TX_EVT i am calling  UART_Write function;

Please help me why my device getting hanged/disconnected and how to resolve this issue?



  • Hi,

    I am facing one more issue with above if i connect/ disconnect ble mutiple times(4-5 times) with multiple central devices, CC2642 chipset getting hanged. I am using simplelink_cc26x2_sdk_2_30_00_34 sdk and setting below parameters on my devices.

    -DMAX_NUM_BLE_CONNS=8

    // Minimum connection interval (units of 1.25ms, 6 = 7.5ms) for parameter update request
    #define DEFAULT_DESIRED_MIN_CONN_INTERVAL 6
    // Maximum connection interval (units of 1.25ms, 24 = 30ms) for parameter update request
    #define DEFAULT_DESIRED_MAX_CONN_INTERVAL 24
    // Slave latency to use for parameter update request
    #define DEFAULT_DESIRED_SLAVE_LATENCY 0
    // Supervision timeout value (units of 10ms, 300=3s) for parameter update request
    #define DEFAULT_DESIRED_CONN_TIMEOUT 300
  • Hi,

    With the connection interval you use and max connection you want to have it's not possible to accomplish.

    In our BLE STACK, the minimum time span between 2 connections are 5ms. So in order to have 8 connections, you need more than 40 ms as minimum connection interval or else the device will not even have time to advertise after 4 ~6 connections.

    When you said it gets hangs, can you follow our debugging guide and provide more information.
    The debug guide can be found here:
    dev.ti.com/.../ble-index.html
  • Hi Christin,

    There  is no luck with the above solution device is getting stuck if we are trying to connect/disconnect multiple ble device.

    Say for one connected and other disconnected and new connected( we can’t put limitation for user that please connect new device after 1 min as per our use case)

    We tried increasing size of heap and checked with different configuration as suggested on forums but we are facing this on base code of simple peripheral even with 3 device connection. Can you see this on your launch pad with base code?

  • Please provide the debug information first. Where is the program counter at this point? Is there hardware exception?
    Please follow our debug guide and provide the needed info.
  • Hi Christin,

    Please find the attached images with Program counter Screenshot, File where PC is stuck, Register values and screenshot fro hardware exception when the device is hanged.

  • Hi,

    I will be off the following days for holidays, will continue working on this thread when I get back.
  • Hi Christin,

    Do we have any update on this?

  • Gentle Reminder

  • Hi,

    First you should not using blocking mode since this will break the BLE connection.
    You can take a look our github example simple_serial_socket_client/server project to see how to integrate uart functionality with BLE projects.

    github.com/.../readme.md

    github.com/.../simple_serial_socket_client.c
  • Hi Christin,

    We have tried above method changed the write mode to callback instead of blocking mode as mentioned in above code. But we are still getting same hanged issue.
  • Hi Christin,

    Thanks for sharing Github codes.

    I have gone through your codes and the way UART is implemented it's completely different what we did in our code. Let me explain you my implementation.

    1. We are using callback function for reading: i.e. UARTReadCallBack whenever there is something to read from UART then we are reading that using a uart_read_data function.

    2. And we have one event handler running at an interval of 40 seconds i.e. for UARTWRITE (if we have read something using a reading call back) using a uart_write_data function.

    However in your code its completely different using UARTWriteCallback() and maintaining a LIST of UART data(We actually don't understand how we can embed this in our code). 

    Please find the attached code file that we are using for UART Read and Write functions.

    /* In UART Task Function */

    // If RTOS queue is not empty, process app message.
    if (events & UART_WRITE_EVT)
    {
    events &= ~UART_WRITE_EVT;
    //write data to uart
    uart_write_data(command);
    }

    // If RTOS queue is not empty, process app message.
    if (events & UART_READ_EVT)
    {
    events &= ~UART_READ_EVT;
    //read data from uart
    uart_read_data();
    }

    ---- Maine UART READ WRITE functions

    /*********************************************************************
    * @fn uart_readcallback
    *
    * @brief function for read callback.
    *
    * @param None.
    *
    * @return None.
    */
    static void uartReadCallback(UART_Handle handle, void *ptr, size_t size)
    {
    //Queue uart data
    uart_setEvent(UART_READ_EVT);
    }

    /*********************************************************************
    * @fn uart_tx_packet_format
    *
    * @brief function for transmit data to host through UART.
    *
    * @param Packet_Type.
    *
    * @return None.
    *
    */
    void uart_tx_packet_format(uint16_t PacketType)
    {
    uint8_t tx_data[256] = { 0x00 };

    switch (PacketType)
    {
    #ifdef STATISTICS_ENABLE
    case STATISTICS_CODE:
    memset(tx_data, 0, sizeof(tx_data));
    tx_data[0] = PACKET_HEADER_TX;
    // Packet Type
    tx_data[1] = HI_UINT16(STATISTICS_CODE);
    tx_data[2] = LO_UINT16(STATISTICS_CODE);
    // Length
    tx_data[3] = (STATISTICS_CODE_LEN - PACKET_HEADER_INFO_LEN);
    // Data
    tx_data[4] = HI_UINT16(UARTRX_Bytes);
    tx_data[5] = LO_UINT16(UARTRX_Bytes);
    tx_data[6] = HI_UINT16(UARTTX_Bytes);
    tx_data[7] = LO_UINT16(UARTTX_Bytes);
    tx_data[8] = HI_UINT16(BLERX_Bytes);
    tx_data[9] = LO_UINT16(BLERX_Bytes);
    tx_data[10] = HI_UINT16(BLETX_Bytes);
    tx_data[11] = LO_UINT16(BLETX_Bytes);

    // Send Data To HOST.
    UART_write(SbpUartHandle, tx_data, STATISTICS_CODE_LEN);

    host_ack_evt |= STATISTICS_ACK;
    // Restart Clock
    Util_restartClock(&uart_ackn_clock, UART_ACKN_CLOCK_TIMER);
    break;
    #endif

    default:
    break;
    }
    }

    /*********************************************************************
    * @fn uart_rx_packet_format
    *
    * @brief function for receiving data from host.
    *
    * @param Packet_Type.
    *
    * @return None.
    *
    */
    void uart_rx_packet_format(uint16_t Packet_Type)
    {
    switch (Packet_Type)
    {
    case HOST_ACKNOWLEDGEMENT:
    if (host_ack_evt)
    {
    #ifdef STATISTICS_ENABLE
    // STATISTICS ACK
    if (host_ack_evt & STATISTICS_ACK)
    {
    if (ackn.statistics_bit == true)
    {
    ackn.statistics_bit = false;
    ackn.statistics_bit_cnt = 0;
    host_ack_evt &= ~STATISTICS_ACK;

    // Clear counters
    UARTTX_Bytes -= UART_TX_BACKUP;
    UARTRX_Bytes -= UART_RX_BACKUP;
    BLETX_Bytes -= BLE_TX_BACKUP;
    BLERX_Bytes -= BLE_RX_BACKUP;
    }
    else
    {
    if (ackn.statistics_bit_cnt++ >= UART_TX_RETRY_COUNT)
    {
    ackn.statistics_bit_cnt = 0;
    host_ack_evt &= ~STATISTICS_ACK;
    }
    else
    {
    command = STATISTICS_CODE;
    uart_setEvent(UART_WRITE_EVT);
    }
    }
    }
    #endif
    }
    else
    {
    if (Util_isActive(&uart_ackn_clock))
    {
    // Stop Clock
    Util_stopClock(&uart_ackn_clock);
    }
    }
    break;

    default:
    break;
    }
    }

    /*********************************************************************
    * @fn SimplePeripheral_processAppMsg
    *
    * @brief Process an incoming callback from a profile.
    *
    * @param pMsg - message to process
    *
    * @return None.
    */

    static void uart_write_data(uint16_t data)
    {
    // Write data to uart
    uart_tx_packet_format(data);
    }


    /*********************************************************************
    * @fn SimplePeripheral_processAppMsg
    *
    * @brief Process an incoming callback from a profile.
    *
    * @param pMsg - message to process
    *
    * @return None.
    */
    static void uart_read_data(void)
    {
    uint8_t status = SUCCESS;

    // Copy UART RX data to buffer
    memcpy(&read_data[rd_index], read_buff, rx_data_len);

    if (read_data[0] == 0x01)
    {
    rd_index += rx_data_len;
    if (Util_isActive(&uart_recv_clock))
    {
    // Stop Periodic Clock.
    Util_stopClock(&uart_recv_clock);
    }

    if (read_data[3] != NULL)
    {
    rx_data_len = read_data[3];
    uart_data_len = (rx_data_len + PACKET_HEADER_INFO_LEN);

    if (rd_index >= uart_data_len)
    {
    UART_readCancel(SbpUartHandle);
    if ((read_data[0] == host_data_feed_cmd[0])
    && (read_data[1] == host_data_feed_cmd[1])
    && (read_data[2] == host_data_feed_cmd[2]))
    {
    #ifdef STATISTICS_ENABLE
    // UART RX Count
    UARTRX_Bytes += uart_data_len;
    #endif
    memcpy(&send_data_buff[queue_index], (read_data + 3),
    (uart_data_len - 3));
    queue_index = queue_index + QUEUE_SAMPLE_LEN;

    if (queue_index >= (QUEUE_SAMPLE_LEN * QUEUE_SAMPLE_COUNT))
    {
    queue_index = 0;
    }

    memset(&send_data_buff[queue_index], 0,
    (QUEUE_SAMPLE_LEN * QUEUE_DEL_COUNT));
    memset(read_data, 0, sizeof(read_data));
    memset(read_buff, 0, sizeof(read_buff));
    rd_index = 0;

    if(!Util_isActive(&uart_tx_clock))
    {
    Util_startClock(&uart_tx_clock);
    }

    if (noti_enable)
    {
    data_send = true;
    data_transferEvent();
    }
    }

    else if ((read_data[0] == host_fw_ver_req_cmd[0])
    && (read_data[1] == host_fw_ver_req_cmd[1])
    && (read_data[2] == host_fw_ver_req_cmd[2])
    && (read_data[3] == host_fw_ver_req_cmd[3])
    && (read_data[4] == host_fw_ver_req_cmd[4]))
    {
    #ifdef STATISTICS_ENABLE
    // UART RX Count
    UARTRX_Bytes += uart_data_len;
    #endif
    uart_rx_packet_format(BLE_FW_VERSION_REQ);
    memset(read_data, 0, sizeof(read_data));
    }

    // Enable UART RX
    memset(read_buff, 0, sizeof(read_buff));
    rd_index = 0;
    rx_data_len = PACKET_HEADER_INFO_LEN;

    status = UART_read(SbpUartHandle, read_buff, rx_data_len);
    if (status != SUCCESS)
    {
    UART_read(SbpUartHandle, read_buff, rx_data_len);
    }
    return;
    }
    else
    {
    status = UART_read(SbpUartHandle, read_buff, rx_data_len);
    if (status != SUCCESS)
    {
    UART_read(SbpUartHandle, read_buff, rx_data_len);
    }
    }

    // Check clock
    if (!Util_isActive(&uart_recv_clock))
    {
    // Start Clock.
    Util_restartClock(&uart_recv_clock, UART_RECV_CLOCK_TIMER);
    }
    }
    }
    }


    /*********************************************************************
    * @fn uart_setEvent
    *
    * @brief Set an event
    *
    * @param event - event to be set
    *
    * @return none
    */
    void uart_setEvent(uint32_t event)
    {
    // Wake up the application thread when it waits for clock event
    Event_post(syncEvent, event);
    }

    #ifdef STATISTICS_ENABLE
    /*********************************************************************
    * @fn uart_setEvent
    *
    * @brief Set an event
    *
    * @param event - event to be set
    *
    * @return none
    */
    static void uart_statistic_clockHandler(UArg arg)
    {
    // Wake up the application thread when it waits for clock event
    Event_post(syncEvent, UART_STATISTICS_EVT);
    }
    #endif

    /*********************************************************************
    * @fn uart_setEvent
    *
    * @brief Set an event
    *
    * @param event - event to be set
    *
    * @return none
    */
    static void uart_ackn_clockHandler(UArg arg)
    {
    // Wake up the application thread when it waits for clock event
    Event_post(syncEvent, UART_ACKN_EVT);
    }

    /*********************************************************************
    * @fn uart_setEvent
    *
    * @brief Set an event
    *
    * @param event - event to be set
    *
    * @return none
    */
    static void uart_recv_clockHandler(UArg arg)
    {
    // Wake up the application thread when it waits for clock event
    Event_post(syncEvent, UART_RECV_EVT);
    }

    #ifdef FEED_ACK
    /*********************************************************************
    * @fn uart_setEvent
    *
    * @brief Set an event
    *
    * @param event - event to be set
    *
    * @return none
    */
    static void uart_tx_clockHandler(UArg arg)
    {
    // Wake up the application thread when it waits for clock event
    Event_post(syncEvent, UART_TX_EVT);
    }

    Please have a look to the above code and let me know how can i fix this issue?

    Thanks:)

  • Gentle Reminder

  • Hi Vidushi,

    It is hard to say what could be wrong in your code as it lacks the bigger context. One small thing to consider is looking into lengths passed into "memcpy "and "memset" and verifying that these do not go out of bounds.

    As for the excepttion, you would need to do a deeper fault tracing of your initial hardware exception by following the debug guide:

    dev.ti.com/.../

    Note that the debug guide even contains a chapter on how to get the ROV view to work (as you had issues reading this out) which is important when figuring out the reason you are receiving hardware exceptions.