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.

CC2340R5: UART overrun event has occurring

Part Number: CC2340R5
Other Parts Discussed in Thread: CC2640R2F

Hi,

      I am using CC2340R5 basic_ble peripheral  code with ANCS and I have added the  UART code as follows.

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)
        {
        }
    }
    // Setup an initial read
     UART2_read(uart, &uartReadBuffer, UART_MAX_READ_SIZE, 0);

}
void eventcallbackFxn(UART2_Handle handle, uint32_t event, uint32_t data, void *userArg)
{
    if (event == UART2_EVENT_OVERRUN) //check if the event is overrun event 
    {
		UART2_flushRx(uart);
    }
}
void UARTCallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
    uartPacketSize = count;
    BLEAppUtil_invokeFunction(HandlingFunction,buffer);
}

void HandlingFunction(char *pData)
{
    UART2_write(uart,pData,uartPacketSize,0);
    UART2_read(uart, uartReadBuffer, UART_MAX_READ_SIZE, 0);
}

Now iPhone has connected to the peripheral and doing continuous call and SMS (info will print on uart) and parallelly doing an connection disconnection in mobile Bluetooth settings. And an interval of 100ms pushing an data via serial to the peripheral while these test case uart overrun event has occurring.

when overrun occurs In eventcallbackFxn calling an UART2_flushRx(uart) function and after 5 sec HAL_ASSERT_CAUSE_ICALL_TIMEOUT.

So how to avoid from uart overrun and why UART2_flushRx(uart) function causing an HAL_ASSERT_CAUSE_ICALL_TIMEOUT.

SDK Version : simplelink_lowpower_f3_sdk_7_40_00_64 (peripheral)

CCS version: CCS 12.5.0

Thanks.

Vignesh.

  • Hi Vignesh,

    Thank you for reaching out.

    Overrun error occurs when the CPU has not enough time to read the content of the UART buffer before the next chunk of data arrives.
    I would suggest to try increasing the size of the RX ring buffer to see if it helps. I recommend the RX ring buffer to be at least larger than the UART messages expected to be received. The screenshot below shows how to do this:

    Additionally, I recommend referring to the UART2 example synopsis: https://software-dl.ti.com/simplelink/esd/simplelink_lowpower_f3_sdk/7.40.00.64/exports/docs/drivers/doxygen/html/_u_a_r_t2_8h.html#ti_drivers_UART2_Synopsis
    If not already done, try to call UART2_rxEnable prior to UART2_read().

    With regards to the HAL_ASSERT_CAUSE_ICALL_TIMEOUT, I think it is caused by the execution of UART2_flushRx() disabling the interrupts longer than accepted by the BLEStack.

    I hope this will help,

    Best regards,

  • Hi clement,

    I would suggest to try increasing the size of the RX ring buffer to see if it helps. I recommend the RX ring buffer to be at least larger than the UART messages expected to be received.

    I have tried increasing the size of the RX ring buffer (above 32,64,300,1024) larger than the UART messages(20 bytes) and calling  UART2_rxEnable in UART _Init() function still when sending 20 bytes of data in a interval of 100ms UART overrun is occurring.

    Thanks,

    Vignesh.

  • Hi Vignesh,

    Thank you for telling me.

    In the code you have shared, what is the value of UART_MAX_READ_SIZE? Can you please ensure it is only 20 bytes (because of the size of the UART messages).

    If the previous does not help, could you try to cancel the read operations after receiving the read callback? To do so, you could consider calling the function UART2_readCancel within the UARTCallback function.

    Best regards,

  • Hi clement,

            The value of UART_MAX_READ_SIZE has 300.

     I have tried calling the function UART2_readCancel within the UARTCallback function uart overrun issue has not observed till now.

    But when sending 20 bytes of data in a interval of 100ms UART overrun is occurring while going for an pairing with mobile.

    Thanks,

    Vignesh.

  • Hi Vignesh,

    Great to see some progress.

    Pairing operations require complex computation to generate encryption keys. As mentioned before, this leave the CPU with very little processing power left and could explain the issue observed.

    Regards,

  • Hi clement,

             An interval of 100ms continuously pushing an data (Approx. 20 bytes) via UART to the peripheral. Now I have connected my mobile with peripheral device in link layer when trying to go for  pairing  I can pair successfully with the peripheral device(Just works). But UART overrun is occurring. 

    We didn't faced these issues with CC2640R2F but in CC2340R5.could you please give any solution to prevent from occurring UART overrun while pairing.

    Thanks,

    Vignesh.

  • Hi Vignesh,

    Could you please guide us to reproduce the same on the basic_ble example (i.e. without the ANCS code)?

    In your case, are you running the UART operations in the same thread as the ANCS?

    Regards,

  • Hi clement, 

         With basic ble example can able to reproduce with adding uart where the code provided in first and sending data Continuously  in uart now going for an pairing uart over run occurs. 

    In the case of basic ble peripheral with ANCS, peripheral Rx is not working when uart overrun occurs. 

    Yes, UART operations where running in same thread as the ANCS.

    Can you just guide me to implement UART in different thread. 

    Thanks, 

    Vignesh. 

  • Hi Vignesh,

    You can find all the information about implementing UART in a different thread in the Merge "drivers" examples into basic_ble SLA.

    I hope this help,

    Tanguy

  • Hi clement,

           We have tried implementing UART in a different thread and didn't help to prevent from UART overrun event.

    After we started analyzing the UART initialize and enabling the read callback there we found that BLEAppUtil_invokeFunction causing the UART overrun event.

    Can you please try to recreate an issue by adding BLEAppUtil_invokeFunction in read callback and send data with the delay of 100ms on UART then parallelly try to pair, then UART overrun will occur.

    Thanks,

    Vignesh.

  • Hi Vignesh,

    The data sent to the function with BLEAppUtil_invokeFunction need to be allocated with BLEAppUtil_malloc, could you try again with the following UARTCallback ?

    #include <ti/bleapp/ble_app_util/inc/bleapputil_internal.h>
    void UARTCallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
    {
        uartPacketSize = count;
        void *data = BLEAppUtil_malloc(count);
        memcpy(data, buffer, count);
        BLEAppUtil_invokeFunction(HandlingFunction, data);
    }
    

    Let me know if this fix the UART overrun.

    Regards

    Tanguy

  • Hi,

        I have tried by allocating BLEAppUtil_malloc in the UARTCallback function but still Overrun occurring.

    Thanks,

    Vignesh.

  • Hi Vignesh,

    I manage to reproduce the issue by doing the following:

    1. I imported the basic_ble project
    2. I added the function you provided in app_main.c
      1. I defined UART_MAX_READ_SIZE as 32
      2. uartReadBuffer is an array of UART_MAX_READ_SIZE bytes.
    3. I called UART_init before Menu_start in App_StackInitDoneHandler
    4. I use the following python script to send data to the device
      import serial
      import time
      
      ser = serial.Serial ("COM8", 115200)
      while True:
          time.sleep(0.1)
          ser.write(b'a' * 32)
          print(ser.read_all())
      
    5. On my phone, I connected to the device and tried to read characteristic 0xFFF5 while sending data with the python script.
    6. I observed an UART overrun error

    During my testing I noticed that the interval between 2 call to HandlingFunction when the pairing is started is approximately 500ms. So, I increased the size of the RX ring buffer to 192 bytes (32 x 6) and the UART overrun error disappeared.

    Regards,

    Tanguy

  • Hi Tanguy,

        I defined UART_MAX_READ_SIZE as 300. So I increased the size of the RX ring buffer 1800(300x6) and the UART overrun error has not occurred.

    But RAM consumption has increased to 98% where using Multirole Profile with  ANCS and need to implement AMS also. Can you please suggest any other solution to prevent UART overrun error.

    Thanks,

    Vignesh.  

  • Hi Vignesh

    I am glad to hear that increasing the size of the buffer solve the overrun error. Concerning the memory usage, you can try with a smaller buffer (x4, x5) maybe it is enough to avoid the overrun. The others way to avoid the problem would be to reduce the number of bytes sent or to increase the interval between 2 transmissions.

    Concerning the memory usage, could you tell me what was the total memory consumption before increasing the size of the buffer?

    To reduce the ram usage, you can check the max heap usage in the ROV and reduce the heap accordingly.

    Regards,

    Tanguy