Cy_BLE_GATTS_Notification: CY_BLE_ERROR_INVALID_OPERATION

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

cross mob
DaBr_4777916
Level 2
Level 2
25 sign-ins 10 replies posted 10 sign-ins

I'm trying to send data packets between two BLE devices (A and B) with both peripheral/central GAP roles.  When I add and remove other devices to the BLE network, I find by debugging device A that it can enter a state where any attempt at sending a GATT notification to device B returns a  CY_BLE_ERROR_INVALID_OPERATION error, though it can send GATT notifications to other devices that are connected.  In this circumstance, A is peripheral wrt to device B, and GATT write requests can be sent from device B to device A.  Cypress code comments indicate CY_BLE_ERROR_INVALID_OPERATION occurs when the BLE stack queue is full or some other problem occurs.  Is it possible to look at the BLE stack queue in debug mode to get a clearer idea of what's going wrong?

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

Hello,

Yes, this error CY_BLE_ERROR_INVALID_OPERATION will occur when the BLE Stack is busy. Please check the stack busy status before calling Cy_BLE_GATTS_Notification() function as shown in below code. Please refer to the CY_BLE_EVT_STACK_BUSY_STATUS event for more information. This event is triggered by BLE Stack to indicate if the BLE stack is busy or not. The Event Parameter corresponding to this event will indicate the state of BLE stack's internal protocol buffers for the application to safely initiate data transactions (GATT, GAP Security, and L2CAP transactions) with the peer BLE device.

*********************************************************

if(Cy_BLE_GATT_GetBusyStatus(appConnHandle.attId) == CY_BLE_STACK_STATE_FREE)
{
/* Send notification data to the GATT Client*/
Cy_BLE_GATTS_Notification(&notificationPacket);
}

*********************************************************

Thanks,
P Yugandhar.

0 Likes
lock attach
Attachments are accessible only for community members.
DaBr_4777916
Level 2
Level 2
25 sign-ins 10 replies posted 10 sign-ins

Thanks.  Useful information.  However, it turns out when this invalid operation error is being thrown, the stack is `hanging', in the sense that no new events are being processed (as confirmed by the switch(event) breakpoint in the attached image never being reached).  Despite the fact this breakpoint is never reached while device A is running, it can be reached when device B sends a GATT notification to device A.  Is there some common reason why the stack may stop operation in this way?

0 Likes

Hello,

Please share your complete project so that we can check at our end.

Thanks,

P Yugandhar.

0 Likes

Which email address should I use to send you the code?

0 Likes
lock attach
Attachments are accessible only for community members.
DaBr_4777916
Level 2
Level 2
25 sign-ins 10 replies posted 10 sign-ins

I'll ask our senior firmware engineer about sharing the project.  BLE sniffer suggests there is a very high level of BLE ota traffic in the office (20+ devices, enough to make nRF51 DK sniffer.exe crash -image attached), could this be causing a problem with BLE devices assigned a specific network tag even if there are only 5 of them?

0 Likes

Hello,

I don't think the problem might be because of more number of BLE devices around. You can refer to the below points and check in your project.  

1. The CY_BLE_ERROR_INVALID_OPERATION error code will be returned if the stack queue is full or for other reasons, the stack cannot process the operation. So, you can check with increasing the BLE Stack's default queue depth(CY_BLE_L2CAP_STACK_Q_DEPTH_PER_CONN) and achieve better throughput for the attribute MTU greater than 32, use the AddQdepthPerConn parameter in the 'Expression View' of the Advanced tab in the BLE component GUI. To Access the 'Expression View', right click on the 'Advanced' tab in the BLE Component GUI and select the 'Show Expression View' option. Please refer to the CY_BLE_EVT_STACK_BUSY_STATUS for more information in BLE documentation.
2. Cy_BLE_ProcessEvents() function checks the internal task queue in the BLE Stack, and pending operation of the BLE Stack, if any. So, this must be called at least once every connection interval or ADV interval(whichever is smaller).
3. Please ensure that the BLESS interrupt priority is at highest in the project.

Please let me know if this helps.

Thanks,
P Yugandhar.

0 Likes
DaBr_4777916
Level 2
Level 2
25 sign-ins 10 replies posted 10 sign-ins

With the code changes you suggest, it appears the bug may still be occurring with 5 devices networked together.  When the 5 devices are powered on, they network together correctly, and since each device is connected to 4 others, ADV_SCAN_IND are broadcast by each device as shown by a packet sniffer.  However, when the power on one of the devices is toggled, it frequently occurs that one or more of the devices stop advertising, as indicated by the fact no packets of any type (e.g. ADV_IND, ADV_SCAN_IND, SCAN_REQ, SCAN_RSP, CONNECT_REQ) from the address are found by packet sniffing.  I think this is a scenario relevant to this support request, whereby on a device that has stopped advertising, the BLE stack event handler 'hangs', and returns a stack busy flag whenever the device attempts to send a GATT notification.

Given that the network is failing with such a simple operation, it appears to me the BLE stack hanging may be due to running out of RAM, but it would be helpful if you could briefly scan the BLE event handler code we are using in case there is any obvious issue we've missed.  Is there an email address I can send this code to for inspection?

 

0 Likes