Cause and recovery from CY_BLE_ERROR_INSUFFICIENT_RESOURCES

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
user_1516261
Level 2
Level 2

Hello,

I have the following scenario:

We have two custom boards with CY8C6347BZI-BLD53 MCUs. One board is a sensor and the other one is a BLE-to-Ethernet gateway. Each gateway communicates with many (20+) sensors. The gateway connects to each sensor approx. once every 10 minutes and reads out measurement data (~6kB). The gateway is configured with 4 simultaneous BLE connections.

When running long-term tests, I'm having issue with the gateway failing to connect to the sensors after a couple of hours. When examining the failure, I have discovered that Cy_BLE_GAPC_InitConnection() returns CY_BLE_ERROR_INSUFFICIENT_RESOURCES for each subsequent call. My first thought was that there was some error with some sensors not disconnecting cleanly, so I tried to add Cy_BLE_GAP_Disconnect() for all bdHandles, but I noticed that Cy_BLE_GAP_Disconnect() also returned CY_BLE_ERROR_INSUFFICIENT_RESOURCES. I currenly have a workaround where I restart the gateway when I get into this situation, but this is not a long term solution.

To continuing with my troubleshooting, I would like to know the following information:

  • What is the cause of the error code CY_BLE_ERROR_INSUFFICIENT_RESOURCES? What resources is it that are not available? How can I avoid getting into this scenario?
  • When I get into this situation, is there any way to recover without resetting the device?

Thanks in advance,

William

0 Likes
6 Replies
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello William,

In multi connection use case, the recommended minimum connection interval per connection should be greater than N * Max Time taken by individual connections to complete a BLE Connection Event (CE).

     Min_CI = N * Average Time Per CE. Where, N is the no. of BLE Connections supports.

Average time for each CE is the amount of time taken to complete one BLE Tx and Rx transaction. This time varies depending on Link Layer Data Length Extension (DLE) and BLE data rate (1 Mbps or 2 Mbps) configuration. Please refer the description of Cy_BLE_GAPC_InitConnection() for recommended Connection Interval values in cy_ble_stack_gap_central.h file.

Please let me know if this helps.

Thanks,

P Yugandhar.

0 Likes

Hi!

My connection interval was to low (I had it set to 7.5 ms and with DLE enabled and 2 Mbps, it should be at least 14 ms according to the descrition). However, I changed the minimum connection interval to 25 ms and maximum to 50 ms. It did not help, the problem persists

0 Likes
NazarP_56
Employee
Employee
25 solutions authored 10 sign-ins 50 replies posted

Hello William,

Cy_BLE_GAPC_InitConnection() and Cy_BLE_GAP_Disconnect() can return CY_BLE_ERROR_INSUFFICIENT_RESOURCES if HCI commands queue is FULL, so BLE stack can't allocate resource for this command.


Possible reasons:

1. Before calling Cy_BLE_GAPC_InitConnection, you called another couple Stack functions without waiting the response (by event). Will be good to review your implementation of BLE part in gateway project,

2. You do not enough call Cy_BLE_ProcessEvent  (refer to documentation for this function),
3. Application corrupts memory related to BLE middleware.

Regards,
Nazar

0 Likes

Hi,

* I call Cy_BLE_ProcessEvent() every loop in my main task, so it should run approx. once per ms, that should be often enough

* I have run valgrind on all my unit tests and not found any memory corruption errors. I guess I can try to put a conditional breakpoint if there is some specific struct you'd like me to check. When connect is called, as far as I can see all parameters have reasonable/correct values.

So, the reason is then likely your point 2). I have reviewed my code, and I have a lot of error handling code to try to recover from some scenarios in which I never get completion events from the stack. I guess that might be a cause. So I have removed the error handling code and I'm experiencing three kinds of failures:

* In Cy_BLE_GAPC_ConnectDevice() the call to Cy_BLE_StartTimer() returns CY_BLE_ERROR_INVALID_OPERATION which according to API documentation simply means "On failed operation.". cy_ble_connectionParameters has the values timerHandle = 0 and timeout = 30. cy_ble_state is CY_BLE_STATE_ON and all four entires in cy_ble_connState is DISCONNECTED. When this happens I added a retry after 15 seconds. That ran for several hours without recovering

* I have experienced never (let it try fro 30 minutes) receiving the connection event after a successfull call to Cy_BLE_GAPC_ConnectDevice(). I checked cy_ble_state and it was still CY_BLE_STATE_CONNECTING. I added calling Cy_BLE_GAPC_CancelConnection() when this occured, but then the completion event for that was not received either

* I have experienced Cy_BLE_GAP_Disconnect() not generating the disconnect events. I have tried calling Cy_BLE_GAP_Disconnect() again if event is not received within 30 seconds. That has either had the same effect or returned INSUFFICENT_RESOURCES. I have tried powering off the device that it thinks it's connected to, but it is still shown as connected in cy_ble_connState

0 Likes

Ok, so I did two changes to my code yesterday:

* Previously I had the BLE controller om the M0+ core and the BLE host on M4. I changed so that the entire stack ran on M4

* I upgraded PDL from version 3.0.4 to 3.1.0

After these changes, I have not seen these issues

/William

0 Likes

Hi William,

Could you confirm that you do not observe problem with BLE dual mode (BLE controller on the M0+ core and the BLE host on M4) on 3.1.0?

What is BLESS ISR configuration on project which was failed (3.0.4 + BLE dual)?

Did you do any modification in cy_ipc_config.h?

Regards,
Nazar