write without response returning invalid parameter

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

cross mob
lock attach
Attachments are accessible only for community members.
DaCh_1995281
Level 3
Level 3
First solution authored 10 sign-ins 10 questions asked

I'm having trouble calling the Cy_BLE_GATTC_WriteWithoutResponse(cy_stc_ble_gattc_write_cmd_req_t * param) function. The handleValPair and connHandle of param appear to be correct but I keep getting a CY_BLE_ERROR_INVALID_PARAMETER error.

For context, I'm calling this function in a DMA interrupt to send audio to another psoc 6 device.

I have attached my project for reference.

Any help would be appreciated.

0 Likes
1 Solution
MeenakshiR_71
Employee
Employee
100 likes received 50 likes received 25 likes received

Hello dchu_1995281​,

I don't see "Cy_BLE_GATTC_ExchangeMtuReq" API in your example. Please call this API after connection is completed (or Authentication complete, if enabled) from the device, which is going to act as client. The MTU has to exchanged for the devices to use the 203 MTU size configured in the BLE configuration. Otherwise, it may use 23 as the default MTU size, which can result in INVALID_PARAMETER error as the write packet length is 148 (>23).

I have not tested the project, just skimmed the code. If you still face the issue, let me know the hardware setup. I will try it out and see what goes wrong.

Regards,

Meenakshi Sundaram R

View solution in original post

4 Replies
MeenakshiR_71
Employee
Employee
100 likes received 50 likes received 25 likes received

Hello dchu_1995281​,

I don't see "Cy_BLE_GATTC_ExchangeMtuReq" API in your example. Please call this API after connection is completed (or Authentication complete, if enabled) from the device, which is going to act as client. The MTU has to exchanged for the devices to use the 203 MTU size configured in the BLE configuration. Otherwise, it may use 23 as the default MTU size, which can result in INVALID_PARAMETER error as the write packet length is 148 (>23).

I have not tested the project, just skimmed the code. If you still face the issue, let me know the hardware setup. I will try it out and see what goes wrong.

Regards,

Meenakshi Sundaram R

lock attach
Attachments are accessible only for community members.

Hi Meenakshi,

Thanks, the MTU exchange fixed the CY_BLE_ERROR_INVALID_PARAMETER error. However writing only works the first time, any subsequent calls to the write function give me a CY_BLE_ERROR_INVALID_OPERATION error and I haven't been able to find much information about what might be causing this error.

Would you be able to provide any insight regarding this error?

I attached an updated project.

If you want to test it, I am using two psoc 6 eval kits. Right now the client sending audio has the CY8CKIT-028-TFT shield on it.

0 Likes

The "CY_BLE_ERROR_INVALID_OPERATION" occurs because the stack is unable to take in more packets as it is busy with something (could be processing the previous packets too).

I just went through the PDM side of the implementation and looks like you have configured it for a 16 KHz sample rate. This translates to around 4.625 ms per 74 samples (74/16kHz) your DMA transfers per X loop ==> Your DMA interrupt triggers every 4.625 ms ==> you call the WriteWithoutResponse API every 4.625 ms.

I checked your connections parameters are 20-50 ms (not sure what final connection interval you end up with). This would mean you can call the API more than 5 times before BLE is able to transfer one packet over the air. I believe this ends up in the invalid operation error as you try to push more packets than it could send out.

I would recommend the below -

1. Use a bigger buffer size and make sure the DMA interrupt occurs every BLE connection event time (for proper sync) - May be have the size such that your DMA transfer takes around 15-16 ms. Increase the MTU size accordingly as well (max is 512 bytes). For instance do a 240 bytes (240/16k = 15 ms) transfer per X loop and have the MTU size as 483( = 2*240 + 3 bytes for ATT overhead). Also for max through put, use 244 as the LL Tx/Rx Payload.

2. Force your BLE connection to be 15-16 ms - change the "Connection parameters" min/max settings in the GAP settings tab of the BLE customizer. This lets you push one PDM packet per BLE event. Set both to 15 ms for the example case I provided in 1.

Try the above and see if that helps. I will try to get hold of a kit to test this out.

Regards,

Meenakshi Sundaram R

Hi Meenakshi,

After following your suggestions, it still wasn't working. After investigating a bit more, I figured out that some incorrectly set DMA API on the peripheral side was causing it to hang. After removing the DMA code the writes no longer failed.

Thanks for your help.