Problem sending consecutive notifications: CYBLE_ERROR_MEMORY_ALLOCATION_FAILED

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

cross mob
Zaborpila
Level 1
Level 1
First reply posted First question asked Welcome!

I am working with a PSOC 4 214015 test module.

I am trying to see how fast I am able to send 81 byte notifications. To do so I have set the MTU values accordingly and I am using the following code:

///////////////////////////////////////////////////////////////////////////////////////////////

uint8 _readDataBuffer[81];

uint32 ind = 0;

...

memset(&_readDataBuffer, 0, sizeof(_readDataBuffer));

while(ind < 200000)
{
_NotifySensorsReadsCharacteristic();

ind++;

}

/*******************************************************************************
*  _NotifySensorsReadsCharacteristic
*******************************************************************************/
void _NotifySensorsReadsCharacteristic(void)
{

CYBLE_GATTS_HANDLE_VALUE_NTF_T sensorsReadsNotificationHandle;

do
{
CyBle_ProcessEvents();
}
while(CYBLE_STACK_STATE_BUSY == CyBle_GattGetBusyStatus());

/* Check if stack is not busy */
if( TRUE == _sensorsReadsNotification &&
CYBLE_STACK_STATE_FREE == CyBle_GattGetBusStatus())
{
/* Update handle with data*/
sensorsReadsNotificationHandle.attrHandle = CYBLE_SENSORS_SENSORS_READS_CHAR_HANDLE;
sensorsReadsNotificationHandle.value.val = _readDataBuffer;
sensorsReadsNotificationHandle.value.len =  81;

CyBle_GattsNotification(cyBle_connHandle, &sensorsReadsNotificationHandle);
CyBle_ProcessEvents();
}
}

///////////////////////////////////////////////////////////////////////////////////////////////

As far as I understand, checking the stack busy state in _NotifySensorsReadsCharacteristic using CyBle_GattGetBusyStatus the way I am doing  it inside a while should wait until the stack is free. Notice that I check it once again before calling CyBle_GattsNotification and then I call CyBle_ProcessEvents.

With the code above I was expecting to get 200000 notifications, but it turns out that I barely get around 200.

I am using Cysmart 1.3 and the Cypress VBLE 4.2 dongle to connect to a 201415 Test module that contains the code I am testing.

After checkin the return value of CyBle_GattsNotification it turns out that I am geting a

CYBLE_ERROR_MEMORY_ALLOCATION_FAILED error.

I found this old thread refering to this same problem and two approaches to come around it

 https://community.cypress.com/t5/PSoC-4-MCU/Why-get-the-quot-CYBLE-ERROR-MEMORY-ALLOCATION-FAILED-qu...

One is adding a delay between the calls to CyBle_GattsNotification. Another one retrying sending the same failed notification repeatedly until the API method returns a success result.

I was wondering if there could be a different approach, a check similar to CyBle_GattGetBusyStatus that would prevent from calling CyBle_GattsNotification to avoid the stack state that generates the CYBLE_ERROR_MEMORY_ALLOCATION_FAILED return.

This second thread mentions a way to avoid this error in a different call by increassing BLE stack internal buffer size but it did not seems to help in my case:

https://community.cypress.com/t5/PSoC-4-MCU/How-to-avoid-CYBLE-ERROR-MEMORY-ALLOCATION-FAILED/td-p/5...

 

 

 

0 Likes
1 Solution
Yugandhar
Moderator
Moderator
Moderator
1000 replies posted 5 likes given First comment on blog

Hello,

1. Please ensure that the BLE subsystem (BLESS) interrupt has the highest priority i.e., priority should be 0.
2. CyBle_ProcessEvents() needs to be called at least once every connection interval. If a custom function consumes more time for execution, call CyBle_ProcessEvents inside it.
3. Always use the latest BLE Component version V3.66 in your design.
4. Please check with increasing the BLE stack internal buffer size with higher values as mentioned in this thread https://community.cypress.com/t5/PSoC-4-MCU/How-to-avoid-CYBLE-ERROR-MEMORY-ALLOCATION-FAILED/td-p/5... , if you are still having the issue then please share your code for testing at our end.

For reference, please check the Day024_Throughput GATT project from the Github. In this project, continuous notification data will be send over BLE using GATT notifications on a custom characteristic.

Thanks,
P Yugandhar.

View solution in original post

0 Likes
1 Reply
Yugandhar
Moderator
Moderator
Moderator
1000 replies posted 5 likes given First comment on blog

Hello,

1. Please ensure that the BLE subsystem (BLESS) interrupt has the highest priority i.e., priority should be 0.
2. CyBle_ProcessEvents() needs to be called at least once every connection interval. If a custom function consumes more time for execution, call CyBle_ProcessEvents inside it.
3. Always use the latest BLE Component version V3.66 in your design.
4. Please check with increasing the BLE stack internal buffer size with higher values as mentioned in this thread https://community.cypress.com/t5/PSoC-4-MCU/How-to-avoid-CYBLE-ERROR-MEMORY-ALLOCATION-FAILED/td-p/5... , if you are still having the issue then please share your code for testing at our end.

For reference, please check the Day024_Throughput GATT project from the Github. In this project, continuous notification data will be send over BLE using GATT notifications on a custom characteristic.

Thanks,
P Yugandhar.

0 Likes