Skip to main content
DSica.1
Associate
May 15, 2020
Solved

aci_gatt_add_char() returned BLE_STATUS_OUT_OF_MEMORY

  • May 15, 2020
  • 2 replies
  • 2719 views

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

This topic has been closed for replies.
Best answer by Silvio

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

2 replies

Silvio
SilvioBest answer
ST Employee
May 21, 2020

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

DSica.1
DSica.1Author
Associate
May 21, 2020

Hello Silvio,

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

BR

Dave

Silvio
ST Employee
June 27, 2020

Hello,

this discussion thread can provide you with more information:

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

BR

Silvio