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.

RTOS/CC2640: BLE device hanging sporadically

Expert 1760 points
Part Number: CC2640

Tool/software: TI-RTOS

Hello all,

I am working on a BLE module using cc2640. I found my device hanging if I make the device WAKEUP/SLEEP pin ON/OFF (not shutting down the entire device) every 100ms simultaneously sending an event through UART every 10ms(After a few seconds not getting any response) I suspect the problem with Uart driver, but I am not sure. Is there any limitation for UART for responding so fastly. Or what could be the reason for this behaviour.

Thanks in advance.

  • Hi Dileep,

    When you say it hangs, does this mean you are hitting an exception handler? What SDK version and IDE are you working in?
  • Hi,

    I mean its not responding to the commands through UART after a few seconds, or the device is completely stuck.

    SDK is 2.2.1 and IAR IDE.

  • Hi Dileep,

    I would need more information then this in order to help you. I assume you are able to debug the device, try checking what state the device is in when it has hanged (where in the code are you).

    If you comment out the usage of UART, do the program work as you expect?
    If this is the case, can you post a snippet showing how you setup and use the UART in your application?
  • Hi,

    If I comment out the UART close function, the program is running as expected.

    When it hangs I am not able to see the program execution handle, to understand where in the code am I. tried by pausing the program but same situation. Sometimes I can see the program breaks in SDI_task_process. I have made some changes in UartOpen and Close functions as needed in my usecase.

    Thanks. Please help.

  • Hi Dileep,

    I would need to see your changes to give any feedback on this. If you say you have made modifications to the open and close functions and that it works if you don't perform your close, I would start to look here for the problem.

    Maybe you can share your code with me?
  • But my doubt is how come its working in normal speed if the modifications made is the cause.
    ill share the uart close snippet.

    if(SDITLUARTgetUARTEnabled() == true)
    {

    ICall_CSState key;

    SDITLUARTsetUARTEnabled(false);

    SDITLUARTsetRxPortClosed(true);

    UART_readCancel(uartHandle);




    UART_writeCancel(uartHandle);

    key = ICall_enterCriticalSection();



    UART_close(uartHandle);

    batterymangmntRelPM();

    ICall_leaveCriticalSection(key);


    SDITLUARTsetUARTbeClosed(false);
    }
  • Hi Dileep,

    Are you basing this on any existing example? I don't know the meaning of for example SDITLUARTsetUARTbeClosed, what does true/false means here?

    Are you using UART from any other place in the code? If it works when you comment out UART_close() and not if you have it there, I suspect you might be trying to the UART from any other place in the code after you have closed it without opening it again. Could this be the case?
  • But I am checking for Uart Enable or Disabled condition whenever it calls Open or Closed function.

    if(SDITLUARTgetUARTEnabled() == true)
    {

    ICall_CSState key;

    SDITLUARTsetUARTEnabled(false);

    SDITLUARTsetRxPortClosed(true);

    UART_readCancel(uartHandle);


    --------------------------------I found some issue here while hanging. its not executing write cancel function. it hangs after readCancel .

    UART_writeCancel(uartHandle);

    key = ICall_enterCriticalSection();



    UART_close(uartHandle);

    batterymangmntRelPM();

    ICall_leaveCriticalSection(key);


    SDITLUARTsetUARTbeClosed(false);
    }

  • If you add "uartCC26XXObjects" you your expression watch list, what is the "opened" state of the UART object when you are seeing the crash?
  • Im not modifying  "uartCC26XXObjects" anywhere in the program, its only declared, but not used.

  • Hi Dileep,

    This is an internal structure of the UART driver. You are not suppose to modify it, however the UART Driver will do this to track the state of the driver (so if you are using the UART driver, then this structure are in use). Did you check the state of "opened" when the crash occurred?
  • Hello M-W,

    Doesn't mean I modified "uartCC26XXObjects". Its state of "opened" when crash occurs is 1.
    I observed sometimes its hitting the Exception Handler, in that case state of "opened" when crash occurs is 0.
  • In the situation where you are hitting the exception handler, where in the code are you?
    Are it while performing any UART_* related APIs?
  • Yes,  it is while performing UART related APIs;

    Eg:      SDITask_Process

                SDITL_writeTL 

      SDITLUART_writeTransport

  • Hi Dileep,

    From what I have gathered here, the problem seems to be that you are trying to use the UART after closing it.
    When calling UART_close, "opened" is set to "0" just like UART_open sets it to "1", if you are trying to do any other UART related APIs when the driver is closed (opened = 0), you would in almost all cases end up in a hardware exception.

    In short, go over your code and make sure to not call UART_close and then use any other UART APIs before calling UART_open again.
  • Hi M-W,

    Thanks I will check the scenario as you mentioned.
    "use any other UART APIs before calling UART_open again" ? For your Info, I'm checking condition before every open and close, to verify if it is closed or open.

    But sometimes state of opened is "1" , I observed. So does that mean it is hanging in multiple places. ?
  • Hi Dileep,

    It could be, it is really hard to tell. As i don't know anything about your complete program and how the flow works, I can only guess you have a logic error in the way you are accessing UART across the program (like the case of the UART API access when the driver is closed).
  • Hi M-W,

    But what Iam doubting is how it is working in normal case(It is perfectly working if I do not make Uart Open Close frequently). The issue is happening only if I make the Uart Open and Close frequently every 100ms or less.

    Is there any speed limit for Uart Output pin (I mean for the Uart to Open and close how much time is needed?) ?
  • Hi Dileep,

    There is no speed limit to the UART pins related to Open and Close.

    A small question, why do you need to close and open the UART all the time?
  • Hi M-W,

    That scenario is an Use case in our project. We have 2 modes, WakeupMode (Uart will communicate , that is Uart_Open ) and SleepMode (Uart should respond to Command, ie Uart_Close). In sleep mode only BLE advertisement should happen and all other functionalities are disabled.

    Sometimes the Bluetooth will(has to) switch between modes, and this issue occurs.
  • Hi Dileep,

    I'm not sure I fully understand this, UART_close() is disabling the UART module as whole, so I don't understand how "UART should respond to command" relates to UART_close.

    You don't have to close the UART to go into standby (sleep mode). The Power driver will automatically disable and re-enable the modules when going in and out of standby. So as long as you are not in an active UART_read/write operation, the device can go into standby (i.e you don't need to close it to save power in standby).

    I recommend looking at the Power Management section for the UART driver:

    dev.ti.com/.../_u_a_r_t_c_c26_x_x_8h.html
  • Hi M-W,

    Sorry, it was a typing mistake from my side, Actually in Sleep Mode UART shouldn't respond to Commands (so we are making the Uart close when the module goes to Sleep mode).

  • Hi Dileep,

    Mistakes happen, I still recommend you to read up on the power management and how it works. As I told you in the previous post, you don't have to close the UART to go into standby, you simple have to make sure there is no active read/write operations.
  • Hi M-W,

    I understand. But how to "make sure there is no active read/write operations". I'm calling these Uart_Open and Uart Close everytime I switch the mode between Wakeup and Sleep. Is there any way I can just Open the Uart once during initialisation and then instead of closing , I can use some other parameter or api to disable the response to command.?
    thanks.
  • Hi Dileep,

    Yes, you can call UART_readCancel and UART_writeCancel to stop any active read/write operations. Running in callback mode, you also need to make sure that the read and write callbacks do not issue another UART_read or UART_write.
  • Hi M-W,

    Thanks for the info. I'm gong as per your advice.

    Why we make Uart_Close everytime when it goes to sleep mode is to reduce the power consumption. So my doubt here is , if I just do UART_readCancel  and UART_writeCancel only, will it consume more power or not.  I'm not fully understanding what it is written in Power management topic.

  • Hi Dileep,

    It should not consume more power, this because the Power driver would be allowed to turn of the power domain when going into standby.
  • Hi M-W,

    Thanks.

    But if I do not use Uart_Close, and only doing readCancel and writeCancel of Uart, I can observe in the Tx line of Uart as high (3.3v) even after going to sleep mode.

  • Hi Dileep,

    Yes this is expected as the GPIO pins are latched to maintain their state in standby. As a UART bus has an idle high state, this means the bus lines will be set high when in standby. This should not impact your power consumption unless you for some reason are grounding the signals when in standby (and by that running current via the pull-up resistor).