cancel
Showing results for 
Search instead for 
Did you mean: 

Problem setting up service on BlueNRG-MS

Ricardo Hassan
Associate III
Posted on June 29, 2017 at 00:48

Hi,

    I'm using a BlueNRG-MS attached to an STM32l4 via SPI.   I've got the connection working all right.  When I try to define a custom service with 6 characteristics, the first 2 work fine, but the rest of the aci_gall_add_char(...) calls return 0x1F, Out of Memory.  I can't believe the BlueNRG chip is already out of memory with just one service and 2 characteristics.  What am I doing wrong?  Here's the code I'm using to set it up:

HCI_Init();

BlueNRG_RST();

tBleStatus status;

uint8_t hwVersion = 0;

uint16_t fwVersion = 0;

getBlueNRGVersion(&hwVersion, &fwVersion);

BlueNRG_RST();

uint8_t bdaddr[] = {0xaa, 0x00, 0x00, 0xE1, 0x80, 0x02};

aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr);

status = aci_gatt_init();

if (status != 0) { while(1); }

uint16_t default_service_handle;

status = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1, 0, 10, &default_service_handle, &device_name_handle_, &appearance_handle_);

if (status != 0) { while(1); }

// set up the service with it's characteristics, as defined in the comm spec

status = aci_gatt_add_serv(UUID_TYPE_16,

kMyService

, PRIMARY_SERVICE, 6, &service_handle_);

status = aci_gatt_add_char(service_handle_, UUID_TYPE_128, kChar1Uuid, 8,

CHAR_PROP_WRITE, ATTR_PERMISSION_NONE, 0, 0, 1, &session_key_write_handle_);

status = aci_gatt_add_char(service_handle_, UUID_TYPE_128,

kChar2Uuid

, 8,

CHAR_PROP_NOTIFY, ATTR_PERMISSION_NONE, 0, 0, 1, &session_key_read_handle_);

status = aci_gatt_add_char(service_handle_, UUID_TYPE_128,

kChar3Uuid

, 17,

CHAR_PROP_WRITE, ATTR_PERMISSION_NONE, 0, 0, 1, &energizer_tx_handle_);

status = aci_gatt_add_char(service_handle_, UUID_TYPE_128,

kChar4Uuid

, 17,

CHAR_PROP_NOTIFY, ATTR_PERMISSION_NONE, 0, 0, 1, &energizer_rx_handle_);

status = aci_gatt_add_char(service_handle_, UUID_TYPE_128,

kChar5Uuid

, 17,

CHAR_PROP_WRITE, ATTR_PERMISSION_NONE, 0, 0, 1, &implant_tx_handle_);

status = aci_gatt_add_char(service_handle_, UUID_TYPE_128,

kChar6Uuid

, 17,

CHAR_PROP_NOTIFY, ATTR_PERMISSION_NONE, 0, 0, 1, &implant_rx_handle_);

const char my_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME, 'M', 'y', ' ', 'E', 'N', 'G'};

hci_le_set_scan_resp_data(16, kMyService);

// start advertising

aci_gap_set_discoverable(ADV_IND, 0, 0, PUBLIC_ADDR, NO_WHITE_LIST_USE, sizeof(my_name), my_name,

16, (uint8_t*)

kMyService

, 0, 0);

At the end it does advertise with the 2 successfully added characteristics.

4 REPLIES 4
Antonio Vilei
Senior III
Posted on June 29, 2017 at 11:51

Dear Hassan Ricardo,

Basically, when you create your service, you have to specify the maximum number of attribute records that can be added to it. In your case, when you call aci_gatt_add_serv(), you used '6' as the max number, and this is definitely not enough for all the characteristics that you planned to add. Indeed it is enough for only two of them, as you experienced yourself.

You can find more information about this subject 

https://community.st.com/0D70X000006SyK4SAK

.

You may also want to try the 

http://www.st.com/content/st_com/en/products/embedded-software/wireless-connectivity-software/stsw-bnrgui.html

 in order to experiment with service and characteristic creation. The tool can automatically calculate the correct number of attributes you need based on the characteristics and their properties.

Hope that helps,

Antonio

Posted on June 29, 2017 at 18:27

Hi Antonio,

    That's exactly what I needed to know.  Thanks for the quick reply!

Ricardo

Micha Valach
Associate III
Posted on August 01, 2017 at 14:56

Hello,

In my opinion it is related to fail of 'aci_gap_set_discoverable'

ret = aci_gap_set_discoverable(ADV_IND, 0, 0, PUBLIC_ADDR, NO_WHITE_LIST_USE, sizeof(my_name), my_name,

16, (uint8_t*)

kMyService

, 0, 0);

Please check the ret value and you will find that it is NOT OK (different from 0=OK) (it seems that the serviceUUIDList in your case 

kMyService is NOT Supported for 16 bytes UUID also as total length is > 40, and might not supported in the BlueNRG-MS verified it also inside BlueNRG GUI

Thanks,

Micha

Posted on August 01, 2017 at 18:18

Antonio was correct.  I increased the number of attribute records to 19 and everything worked fine.  I am using a 16 bit UUID for the service UUID, no problem.  

Regards,

Ricardo