This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Custom Service Issue

I am attempting to enable a second custom service with a vendor specific UUID with three characteristics (in addition to an existing custom service and the battery service which are already working just fine) in SDK 13.0.0-alpha with the 5.0.0-1.alpha S132 softdevice, on an nrf52832.

Just like many other instances I have seen on the forum, calling sd_ble_uuid_vs_add() on the second custom service was resulting in NRF_ERROR_NO_MEM

As per the many other threads, to remedy this, in ble_stack_init() I am calling:

ble_enable_params_t ble_enable_params;
err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
                                                PERIPHERAL_LINK_COUNT,
                                                &ble_enable_params);
APP_ERROR_CHECK(err_code);
ble_enable_params.common_enable_params.vs_uuid_count = 2;
ble_enable_params.gatts_enable_params.attr_tab_size = 0x900;
ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;

before calling softdevice_enable(&ble_enable_params);

Of course, I have no idea what size to set attr_tab_size to. The best advice I have seen is to try setting it too big then do some trial and error.

The default target memory sizes for my project (which work fine with my softdevice when this service is commented out) are:

IROM1 Start: 0x20000
IROM1 Size: 0x53000
IRAM1 Start: 0x20002168
IRAM1 Size: 0xDE98

As I understand it, I also need to adjust the IRAM Start and Size to accommodate my attr_tab_size.

I have seen it suggest that these should be set to:

IRAM1 Start: 0x20002168 + BLE_GATTS_ATTR_TAB_SIZE  
IRAM1 Size: 0xDE98 - BLE_GATTS_ATTR_TAB_SIZE

So in my case, if using an attr_tab_size of 0x900, I believe they should be:

IRAM1 Start: 0x20002A68  
IRAM1 Size: 0xD598

No dice : (

I have also tried larger and smaller values for attr_tab_size, each time adjusting my IRAM settings accordingly with no luck.

Within my custom service, I have also tried setting attr_md.vloc = BLE_GATTS_VLOC_USER; insted of BLE_GATTS_VLOC_STACK to no avail. (cccd_md.vloc always remains set to BLE_GATTS_VLOC_STACK)

Any advice regarding what I might be doing wrong would be much appreciated.

Parents
  • Please examine softdevice_enable(). Here ram_start equals the linker value of the RAM starting point of the application. app_ram_base is set to ram_start and is given to the SoftDevice through sd_ble_enable().

    The SoftDevice will compare the value of app_ram_base with the RAM it actually needs, if too little RAM has been provided sd_ble_enable() will return NRF_ERROR_NO_MEM and app_ram_base will will be the required RAM starting point of the application.

    You can check the value of the app_ram_base by using the debugger (turn off optimizations), or by printing:

        NRF_LOG_WARNING("sd_ble_enable: RAM start should be adjusted to 0x%x\r\n",
                app_ram_base);
        NRF_LOG_WARNING("RAM size should be adjusted to 0x%x \r\n",
                ram_end_address_get() - app_ram_base);
    
  • Hello Petter and thank you for the reply.

    I left the ble_enable_params.gatts_enable_params.attr_tab_size set to 0x900 and am debugging with the default memory size settings listed above.

    I have optimization set to Level 0 (-O0) in my C/C++ settings and set some break points around if (app_ram_base != ram_start).

    err_code equals 0x00000004 ram_start is 0x20002168 and app_ram_base becomes 0x200024F8 I also created a variable ram_size and set it equal to ram_end_address_get() - app_ram_base.

    ram_end_address_get is called and returns 0x20010000 as ram_end_address.

    My ram_size variable becomes 0x0000DB08

    So I go back and set my IRAM Start to 0x200024F8 and IRAM size to 0x0000DB08

    Sure enough, soft_device_enable() returns err_code 0x00000000, which I believe is NRF_SUCCESS.

    Unfortunately, now ble_advertising_init is returning 0x07 I have tried using:

    advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = m_adv_uuids;
    [...]
    err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
    

    as well as:

    ble_advdata_t          scanrsp;
    [...]
    memset(&scanrsp, 0, sizeof(scanrsp));
    scanrsp.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    scanrsp.uuids_complete.p_uuids  = m_adv_uuids;
    [...]
    err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
    

    Any thoughts on what might be causing this?

Reply
  • Hello Petter and thank you for the reply.

    I left the ble_enable_params.gatts_enable_params.attr_tab_size set to 0x900 and am debugging with the default memory size settings listed above.

    I have optimization set to Level 0 (-O0) in my C/C++ settings and set some break points around if (app_ram_base != ram_start).

    err_code equals 0x00000004 ram_start is 0x20002168 and app_ram_base becomes 0x200024F8 I also created a variable ram_size and set it equal to ram_end_address_get() - app_ram_base.

    ram_end_address_get is called and returns 0x20010000 as ram_end_address.

    My ram_size variable becomes 0x0000DB08

    So I go back and set my IRAM Start to 0x200024F8 and IRAM size to 0x0000DB08

    Sure enough, soft_device_enable() returns err_code 0x00000000, which I believe is NRF_SUCCESS.

    Unfortunately, now ble_advertising_init is returning 0x07 I have tried using:

    advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = m_adv_uuids;
    [...]
    err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
    

    as well as:

    ble_advdata_t          scanrsp;
    [...]
    memset(&scanrsp, 0, sizeof(scanrsp));
    scanrsp.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    scanrsp.uuids_complete.p_uuids  = m_adv_uuids;
    [...]
    err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
    

    Any thoughts on what might be causing this?

Children
No Data
Related