cancel
Showing results for 
Search instead for 
Did you mean: 

aci_gatt_add_char() returned BLE_STATUS_OUT_OF_MEMORY

DSica.1
Associate

Hello - My project is based on the SensorDemoBLESensor application built using using the CubeMX tool version 5.6.1 with the X-NUCLEO-BNRG2A1 development board attached to a NUCLEO-F303RE. I successfully added 5 custom characteristics to my first custom service. When I attempt to add a 6th characteristic the aci_gatt_add_char() returned 0x48 (BLE_STATUS_OUT_OF_MEMORY) on the STM32F303. I added a 2nd custom service and successfully added the characteristic that failed to add on the first service. So I don't think this a total memory problem.

The modified the default DTM settings in DTM_Config.h running on the BlueNRG-M2 as follows:

#define DTM_NUM_LINK           2 // Was 8

#define DTM_NUM_GATT_SERVICES  5 // Was 8

#define DTM_NUM_GATT_ATTRIBUTES 125 // Was 68

#define ATT_VALUE_ARRAY_SIZE   (3000) // Was 1248

I still see the error. There seems to be a limit to the number of characteristics (attributes) per service.

Any help would be appreciated.

Best

1 ACCEPTED SOLUTION

Accepted Solutions
Silvio
ST Employee

Hello,

when adding a characteristic to a service you should verify that, when creating that service using the function aci_gatt_add_service(), you declared a sufficient number of attribute records.

For instance, in the SensorDemo_BLESensor-App, in function Add_HWServW2ST_Service() you have:

/* Add_HWServW2ST_Service */
COPY_HW_SENS_W2ST_SERVICE_UUID(uuid);  
BLUENRG_memcpy(&service_uuid.Service_UUID_128, uuid, 16);
ret = aci_gatt_add_service(UUID_TYPE_128, &service_uuid, PRIMARY_SERVICE, 
                           1+3*5, &HWServW2STHandle); 
if (ret != BLE_STATUS_SUCCESS) 
  return BLE_STATUS_ERROR;

where (1+3*5) is the Max_Attribute_Records, i.e. the Maximum number of attribute records that can be added to this service.

In such a case you can have no more than 5 characteristics (all readable, writable and notify).

If you need to have 6 characteristics, you have to increase the Max_Attribute_Records value to (1+3*6).

BR

Silvio

View solution in original post

4 REPLIES 4
Silvio
ST Employee

Hello,

when adding a characteristic to a service you should verify that, when creating that service using the function aci_gatt_add_service(), you declared a sufficient number of attribute records.

For instance, in the SensorDemo_BLESensor-App, in function Add_HWServW2ST_Service() you have:

/* Add_HWServW2ST_Service */
COPY_HW_SENS_W2ST_SERVICE_UUID(uuid);  
BLUENRG_memcpy(&service_uuid.Service_UUID_128, uuid, 16);
ret = aci_gatt_add_service(UUID_TYPE_128, &service_uuid, PRIMARY_SERVICE, 
                           1+3*5, &HWServW2STHandle); 
if (ret != BLE_STATUS_SUCCESS) 
  return BLE_STATUS_ERROR;

where (1+3*5) is the Max_Attribute_Records, i.e. the Maximum number of attribute records that can be added to this service.

In such a case you can have no more than 5 characteristics (all readable, writable and notify).

If you need to have 6 characteristics, you have to increase the Max_Attribute_Records value to (1+3*6).

BR

Silvio

Hello Silvio,

This solved my problem. Thank you for your time and effort.

BR

Dave

Can someone explain why a field labeled "Max_Attribute_ Records" should be "1+3*X"? What is the "1+3*" and why is it used? I used "6" and was able to add 2 characteristics to my service without issue, but fail on adding a 3rd. In terms of the documentation you would assume that supplying "6" would mean the service should support 6.

Silvio
ST Employee

Hello,

this discussion thread can provide you with more information:

https://community.st.com/s/question/0D50X00009XkYAvSAN/sensortile-bluenrgms-custom-service-aci

BR

Silvio