cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB How to use GATT caching?

FWX
Associate III

Hello,
I'm using BLE_p2pClient and BLE_p2pServer programs.
I had pairing request in BLE_p2pClient to have both devices bonded.
Now, I want to have a fast connection between client and server; actually, the connection between client and server is about 2.5 seconds.
I should like not to have to discover again and again services and characteristics of the server by the client at each re-connection. Only once when the program starts.
How to do that?
Have you documentation descriving this?  (I have only found PM0271 §5.1.2).

I have activated the SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED in CFG_BLE_OPTIONS to initialize the BLE stack. But it is not sufficent!
Thank you for your help.
Best regards.
                                    FWX.

1 ACCEPTED SOLUTION

Accepted Solutions
FWX
Associate III

Hi,

 

I have solved this problem by copying IRAM1/IRAM2 characteristics from:
  - BLE_p2pClient_Ext to my BLE_p2pClient project
 - BLE_p2pServer_Ext to my BLE_p2pServer_ota

And I have modified each scatter file from each model.
Now, each application seems running on STM32WB55 board.
I continue to test the GATT Caching...

Best regards,
                                                     FWX.

View solution in original post

5 REPLIES 5
_Joe_
ST Employee

Hi FWX,

To avoid discovering every time services and characteristics, there are 
two methods to notify peer devices about the change:

  • using Service Change Indication
  • using GATT Caching feature

Service Change Indication only works if the peer devices are bonded.

GATT Caching feature overcome the bonding problem. Using GATT caching, every device can make sure that it has stored the latest version of the GATT database structure.
This is achieved by:

  • Adding two new characteristics to the Generic Attribute service (Database Hash and Client Supported Features)
  • Adding a new GATT error code (database out-of-sync)

 

To implement it :

Server side :

Use SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED to configure CFG_BLE_OPTIONS in app_conf.h

NB : This feature is available only in "full extended" BLE stack and certified in STM32Cube v1.16 MCU package or later.

 

Client side :

Read the Database Hash characteristic upon each connection and compare its value with the last stored value.

If the values match, it is safe to use stored characteristic handles.

If they do not match, start a service discovery to discover characteristic handles.

Enable Robust Caching by writing to the Client Supported Features characteristic of the server.

You will also need to check for database out-of-sync error after each GATT operation.

I hope this information will help you. If you need more information regarding Database Hash/Client Supported Feature characteristic or Database out-of-sync error code, do not hesitate to come back to me.

BR, Joé

FWX
Associate III

Hi Joé,

Thank you very much for your detailed answer.
I'm going to add code as described and test that.

Best regards,

                                        FWX.

FWX
Associate III

Hi Joé,

I have begun to modify the BLE_p2pServer and BLE_p2pClient programs to follow your indications.
But I encounter another problem.
You wrote that this feature is available only in "full extended" BLE stack. I want to use the last  firmware stm32wb5x_BLE_Stack_full_extended_fw.bin from STM32Cube_FW_WB_V1.18.0.

But I need to follow this:

  • Warning: To use this binary, it is necessary to adapt the scatter file in the BLE applications as:
    • The RAM_A shared range shall be reduced to memory range [0x20030000:0x200307FF]
    • The Mail-box buffers(MB_MEM1, MB_MEM2) shall be located in RAM_B shared defined in memory range [0x20038000:0x2003A7FF]
    • The RAM_B shared shall be added to Total_RAM_region

My question is how to modify the two projects to use this firmware. I'm developping with Keil5.

I have tried to change the options of the target "Read/Write memory areas" with:

   - IRAM1 Start: 0x20000008 Size: 0x2FC00

   -IRAM2 Start: 0x20030000 Size: 0x20030000

but the application do not run. I suppose there something else to change, but what?

 

Thank you for your help.
Best regards,

                                   FWX.

FWX
Associate III

Hi,

 

I have solved this problem by copying IRAM1/IRAM2 characteristics from:
  - BLE_p2pClient_Ext to my BLE_p2pClient project
 - BLE_p2pServer_Ext to my BLE_p2pServer_ota

And I have modified each scatter file from each model.
Now, each application seems running on STM32WB55 board.
I continue to test the GATT Caching...

Best regards,
                                                     FWX.

FWX
Associate III

Hi Joé,

 

Could you explain me that:

"Enable Robust Caching by writing to the Client Supported Features characteristic of the server."

How to do that? Because I do not find aci_gatt_write_using_char_uuid() function, for example.

Do I need to enable the Robust Caching after each connection? Or juste after call to aci_gatt_store_db() and paire_request?

Thank you for help.

 Best regards,

                                     FWX.