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.

Unable to restart advertising reliably

Other Parts Discussed in Thread: CC2541

I have a BLE peripheral device based on the SimpleBLEPeripheral example code and BLE SDK v1.2.1. It advertises on startup, and on timeout goes to sleep. Pressing a button causes the device to start advertising again. The problem is that sometimes advertising doesn't start up again.

The device appears to get stuck in a state where it's waiting for something to happen. I've tracked it down to the point where it appears that OSAL task 0 (LL task) is waiting for something because it has set its power manager state to PWRMGR_HOLD (keeping the CC2541 from going to sleep).

I looked around to see if anyone had a similar problem, but I haven't been able to find anything. I am somewhat surprised because this problem happens fairly regularly on my system.

I reduced the project to something very minimal: 3 profiles (GAP, GATT, DevInfo), and an interrupt to detect the button press (sends an event to the simpleBLEPeripheral task which sets GAPROLE_ADVERT_ENABLED to turn on advertising)

I found a very hack-ish solution which is to set my task's power manager state to PWRMGR_HOLD when I turn on advertising. I put it back to PWRMGR_CONSERVE about 500 ms later. This seems to prevent the problem, but it's obviously not a good solution. Since this works, it really sounds to me like some type of race condition bug.

  • Hi Nick,

    Thanks for reporting this. In the near future <= 1.5 week hopefully, we will release v1.3 of the stack. It would be nice if you could test this again on this version. I myself have not experienced this. Does it happen on a blank Keyfobdemo or SimpleBLEPeripheral example project?

    Best regards,
    Aslak 

  • Aslak,

    I was able to get it to happen in the SimpleBLEPeripheral example project by  making the following modifications:

    1. Define SBP_PERIODIC_EVT_PERIOD to 0
    2. Modify hal_key so that the interrupt generates an event on the SimpleBLEPeripheral task directly so that it can start advertising [I created an event that is handled in SimpleBLEPeripheral_ProcessEvent() that just calls simpleBLEPeripheral_HandleKeys(0, HAL_KEY_SW_2), and then in halKeyPort0Isr() I just call osal_set_event(simpleBLE_taskID, START_ADVERTISING_EVENT)]
    3. Turn off the non-interrupt hal_key code (debouncing and polling until buttons released) by commenting out calls to HalKeyConfig() in OnBoard_KeyCallback()

    It still happens less frequently than my custom code, but I've looked into it that a little more as well. The steps above all do things that reduce the cycle time of the main loop (osal_run_system). They reduce the number of timers that are in use (the periodic timer, timer for key debouncing, and timer for key polling). This speeds up the main loop because the remaining time is updated for all timers each time through the main loop.

    To test the idea that it was this added delay that prevents the problem, I modified my code to insert a busy-wait after turning on advertising. I also removed the code that I mentioned in my first post that keeps the device from going to sleep. With this busy wait in place advertising started every time. Without the busy-wait I have frequent failures. I did not play with the busy-wait to see how long it needed to be.

    
    

    I look forward to trying v1.3. It would be nice if that fixes this problem.

    Nick

  • Hi Nick,

    Are you still facing this issue in the BLE stack? I am developing one product on 1.3.2 and I am facing something similar issue, though not too frequent. My customers are facing this issue once/twice a day while continuous use and reported when they are at the edge of the range and continuously connecting and disconnecting to the device(CC2541 with iPhone).

    Once this condition raises my device is not able to advertise again ever by pressing the button. I need to remove and re-insert the battery to restart the advertising properly. Is this is the same case with your end? If yes then is there is any way to detect such kind of LOCKUP? So that I can reset my device and start the advertising again?


    Thanks,

    Maulik.

  • Are you using the advertising setting GAPROLE_ADVERT_OFF_TIME to timeout advertising or are you using your own timing and enabling/disabling with GAPROLE_ADVERT_ENABLED (and having GAPROLE_ADVERT_OFF_TIME = 0) ? 

  • Hi Kevin,


    I am using GAPROLE_ADVERT_OFF_TIME = 0. I am using the limited advertising method and using TGAP_LIM_ADV_TIMEOUT to limit the advertising duration. And restart the advertising if required from GAPROLE_WAITING.

    Regards,

    Maulik