This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How do you add more than 1 custom UUID?

Hi Nordic DevTeam,

So I already followed this tutorial on how to add custom service UUID.

https://github.com/NordicPlayground/nRF5x-custom-ble-service-tutorial

I have 3 services that I want to add DFU, NUS and Custom, and probably more Custom UUID later.

I kept getting error 12 (NRF_ERROR_DATA_SIZE) on the ble_advertising_init() even though I already updated the #define NRF_SDH_BLE_VS_UUID_COUNT 3 (I assume it's 3 because DFU, NUS and Custom?)

Here's my code :

static ble_uuid_t m_adv_uuids[]          =                                          /**< Universally unique service identifier. */
{
    {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE},
    {CUSTOM_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN}
};

...
...
...

/**@brief Function for initializing services that will be used by the application.
 */
static void services_init(void)
{
    uint32_t           err_code;
    ble_nus_init_t     nus_init;
    nrf_ble_qwr_init_t qwr_init = {0};
    ble_cus_init_t     cus_init;

    // Initialize Queued Write Module.
    qwr_init.error_handler = nrf_qwr_error_handler;

    err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init);
    APP_ERROR_CHECK(err_code);

    // Initialize NUS.
    memset(&nus_init, 0, sizeof(nus_init));

    nus_init.data_handler = nus_data_handler;

    err_code = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(err_code);

    // Initialise CUS Service init structure to zero.
    memset(&cus_init, 0, sizeof(cus_init));

    err_code = ble_cus_init(&m_cus, &cus_init);
    APP_ERROR_CHECK(err_code);

    // BEGIN Block Added for DFU
    // ONLY ADD THIS BLOCK TO THE EXISTING FUNCTION
    // Initialize the DFU service
    ble_dfu_buttonless_init_t dfus_init =
    {
      .evt_handler = ble_dfu_buttonless_evt_handler
    };

    err_code = ble_dfu_buttonless_init(&dfus_init);
    APP_ERROR_CHECK(err_code);
    // END Block Added for DFU


}

....
....
....

/**@brief Function for initializing the Advertising functionality.
 */
static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;

    memset(&init, 0, sizeof(init));

    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = true;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;// BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;

    advertising_config_get(&init.config);

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&m_advertising, &init);
    NRF_LOG_INFO("%d", err_code);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

What's wrong with my initialisation bit?

Parents
  • Hello,

    @awneil is right - you will need to increase your SoftDevice memory. 
    As a supplement to his comment, please see this excellent guide by my colleague Andreas on how to adjust RAM and flash memory for a walkthrough of how to change this.

    Pleas also make sure that DEBUG is defined in your preprocessor defines, like shown in the included image.

    This will make a detailed error message be printed to your logger output when a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.

    Please do this, and let us know what the logger outputs when this error occurs.

    Best regards,
    Karl

  • Hi Karl,

    I already adjusted the RAM when the debug terminal asks too, but I still get this message

    <debug> nrf_sdh_ble: RAM starts at 0x20002D68
    <info> app: 12
    <error> app: ERROR 12 [NRF_ERROR_DATA_SIZE] at C:\...\ble_app_libUARTE_dfu\main.c:1984
    PC at: 0x0002F369
    <error> app: End of error report

    I followed all these threads but I still don't quite get it : 

    https://devzone.nordicsemi.com/f/nordic-q-a/59712/error-code-12-in-advertising-tutorial

    https://devzone.nordicsemi.com/f/nordic-q-a/39697/custom-service-proximity-example-merge---error-12-nrf_error_data_size-in-ble-advertising-init

    https://github.com/bjornspockeli/custom_ble_service_example/issues/7

    https://devzone.nordicsemi.com/f/nordic-q-a/52390/understanding-advertisement-of-multiple-128-bit-custom-uuid

    and I referred to this project example 

    /cfs-file/__key/communityserver-discussions-components-files/4/8623.custom_5F00_ble_5F00_service_5F00_example_5F00_multiple_5F00_vs_5F00_bases.zip

    I still have the same problem even putting them separately under like this

     memset(&init, 0, sizeof(init));
    
    
    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = true;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;// BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;
    
    m_adv_uuids_more[0].type = m_cus.uuid_type;
    init.srdata.uuids_more_available.uuid_cnt = sizeof(m_adv_uuids_more)/sizeof(m_adv_uuids_more[0]);
    init.srdata.uuids_more_available.p_uuids = m_adv_uuids_more;
    

  • I already adjusted the RAM when the debug terminal asks too, but I still get this message

    IME, finding the right memory size is rather hit and miss: there's no guidance - just a matter of trying more until it works!

    Disappointed

  • awneil said:
    IME, finding the right memory size is rather hit and miss: there's no guidance - just a matter of trying more until it works!

    Could you elaborate on what you are referring to here?
    I think the issue with the NRF_ERROR_DATA_SIZE error that coyodha is seeing here might be with the size of the dataset they are trying to advertise.

    When it comes to setting the right RAM start address we've taken some steps in the nrf_sdh_ble.c to make this a little easier by having the debug logging output what you should change the RAM start address to. If you start out by setting the RAM start address unnaturally high before compiling and running it, you'll get the appropriate start address written to the logger, and then you can change it from there. Have you experienced some issues with this?

    I would also argue that calculating the required flash on the one hand is also pretty straight forward, since the size of the SoftDevice is given in its particular specification. On the other hand you will also need to keep control yourself on what else your application uses the flash for.
    There is indeed no guidance for the latter, but it might be helpful to have a look at the device memory layout when working with this, or checking out the FDS / flash storage examples.

    I would love to hear any input or feedback you might have on this, @awneil !

    Best regards,
    Karl

  • Could you elaborate on what you are referring to here?

    I was referring to the RAM required for extra Services & Characteristics.

    And it would have been back in SDK v15, IIRC - so maybe things have improved now?

  • Hi Karl,

    You are right, the problem is the size of the advertising data.

    When I just have the NUS service, the program doesn't execute that error.

    Now, I am trying to make sense of what to put in. What's the difference between advertising data and scan response?

    /**@brief Function for initializing the Advertising functionality.
     */
    static void advertising_init(void)
    {
        uint32_t               err_code;
        ble_advertising_init_t init;
    
        memset(&init, 0, sizeof(init));
    
    
        init.advdata.name_type          = BLE_ADVDATA_SHORT_NAME;
        init.advdata.short_name_len     = 3; // Advertise only first 3 letters of name
        init.advdata.include_appearance = true;
        init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;// BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
        
        init.advdata.uuids_complete.uuid_cnt = 1;
        init.advdata.uuids_complete.p_uuids  = &m_adv_uuids[0];
    
        init.srdata.uuids_more_available.uuid_cnt = 1;
        init.srdata.uuids_more_available.p_uuids = &m_adv_uuids[1];
    
        init.config.ble_adv_fast_enabled = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    
        advertising_config_get(&init.config);
    
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }

    The code above works in my case, but I am actually not sure what I am doing. I can see all the UUID Service in nRF Connect. 

    How's the structure for advertising data and scan response?

  • awneil said:
    And it would have been back in SDK v15, IIRC - so maybe things have improved now?

    I am happy to say that yes, they have indeed improved since then! Slight smile
    You may see this particular change in nrf_sdh_ble.c, in the nrf_sdh_ble_enable function. It now has a more detailed printouts, stating exactly what you should change the RAM start to to make it work.

    Best regards,
    Karl

Reply
  • awneil said:
    And it would have been back in SDK v15, IIRC - so maybe things have improved now?

    I am happy to say that yes, they have indeed improved since then! Slight smile
    You may see this particular change in nrf_sdh_ble.c, in the nrf_sdh_ble_enable function. It now has a more detailed printouts, stating exactly what you should change the RAM start to to make it work.

    Best regards,
    Karl

Children
No Data
Related