Why get the "CYBLE_ERROR_MEMORY_ALLOCATION_FAILED" when send notification ?

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

cross mob
Anonymous
Not applicable

Hi,

   

When I send a notification to a client, the API "CyBle_GattsNotification()" sometimes returns the error "CYBLE_ERROR_MEMORY_ALLOCATION_FAILED".

   

What is the reason for memory allocation failed while send notification?

   

Thanks!

   

Aaron Deng

0 Likes
7 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Might be that a malloc() goes wrong. I would try increasing the heap size. In .cydwr view System-Tab.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob,

   

Now the heap size is 0x400 (1024), I tested it by using CySmart PC version, it does not happen this problem,

   

but when I test it by using CySmart Android version, this problem will bring out frequently even I increased the heap size to 0x600.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Are you using sprintf()? I experienced some strange behaving especially when sprintf float numbers.

   

Is your program using malloc() and free()? Can that be a cause??

   

When all fails, I would suggest you to get in contact with Cypress directly: At top of this page select "Design support -> Create a Support Case" and ask your question. You will be helped by a Cypress engineer. But keep in mind it's independence day on July 4th.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

How quickly are you sending notifications? Some buffering is needed because packets can't all be sent immediately, and the stack has limited space available for buffering packets. If you are attempting to send notifications faster than they can be transmitted, then the internal buffers will fill and ultimately reject new packets until some have been sent.

   

In the "sending too fast" case, which I suspect is the issue here, there are two solutions:

   
        
  1. Introduce some delay between notifications so that this condition doesn't occur
  2.     
  3. Retry sending the same failed notification repeatedly until the API method returns a success result
  4.    
   

There is no problem with using either approach, but option #2 may use more power on average since there's no possibility for sleep. If you throttle your transmissions down to perhaps once ever 5 ms or so (for example), the CPU and stack can sleep between each transmission.

Anonymous
Not applicable

Hi jrow,

   

Yes, you are right.

   

When I slow down the frequency of sending notification, the CySmart Android version will not happen the error "CYBLE_ERROR_MEMORY_ALLOCATION_FAILED".

   

But I wonder about why this error only occurs on CySmart Android version ?

   

(Both CySmart PC and iOS version are OK by using the same condition to test for.)

   

Thanks!!

0 Likes
Anonymous
Not applicable

The Stack state  has to be free before sending the notification.

   

So checking the stack busy state is the way to avoid the "CYBLE_ERROR_MEMORY_ALLOCATION_FAILED".

   

Aaron Deng

0 Likes
Anonymous
Not applicable

Hey Aaron, could you provide the code you used to avoid this problem? I'm running into it, and checking the busy state doesn't seem to help. (http://www.cypress.com/forum/proc-ble/problems-ble-notifications)

0 Likes