2017-06-28 03:48 PM
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.
2017-06-29 02:51 AM
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
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
2017-06-29 11:27 AM
Hi Antonio,
That's exactly what I needed to know. Thanks for the quick reply!
Ricardo
2017-08-01 05:56 AM
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
2017-08-01 11:18 AM
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