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

Adding Nordic UART Service to project with FreeRTOS - Ivalid Parameters

Hi everyone,

I have a BLE project and i added the Nordic UART Service to it. It compile without error or warnings but ble_advertising_init() return NRF_ERROR_INVALID_PARAMS

static void advertising_init(void)
{
    ret_code_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;
    init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.advdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&m_advertising, &init);
    // At this point err_code = 7 -> NRF_ERROR_INVALID_PARAMS
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

Here is the Log

<error> app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at ../../../main.c:813
PC at: 0x00032BD3
<error> app: End of error report

Here is the Line 812 & 813 of my main.c

ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);

After some diging i found that VERIFY_SUCCESS(ret) at line 475 in ble_advertising.c fail (ret = 7). This means the error come from 

ret = ble_advdata_encode(&p_init->advdata, p_advertising->enc_advdata, &p_advertising->adv_data.adv_data.len);

Putting some NRF_LOG_INFO() in ble_adv_data_encode(), i found out the error comes from uuid_list_encode at line 563 in ble_advdata.c

// Encode 'complete' uuid list.
if (p_advdata->uuids_complete.uuid_cnt > 0)
{
    err_code = uuid_list_encode(&p_advdata->uuids_complete,
                                BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE,
                                BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE,
                                p_encoded_data,
                                p_len,
                                max_size);
    VERIFY_SUCCESS(err_code);
}

So i think the error comes from

#define NUS_SERVICE_UUID_TYPE		BLE_UUID_TYPE_VENDOR_BEGIN		/**< UUID type for the Nordic UART Service (vendor specific). */
...
static ble_uuid_t m_adv_uuids[] =                                   		/**< Universally unique service identifiers. */
{
    {BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE},
    {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE},
    {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
};

I used the ble_app_uart example for reference as how to implement the NUS. Mine sdk_config.h is almost the same as the example's one. By almost, i mean i have enabled the driver i need, BAS and DIS.

NRF_SDH_BLE_VS_UUID_COUNT is define to 1 as i only have NUS which is vendor specific.

Something is not right but i don't know what it is.

I use SDK 15.3.0, SoftDevice S132 V6.1.1 on a nRF52832 in a custom board. My IDE is Eclipse on Windows 10

Parents
  • Hi Steve,

    There is no enough space in the advertising packet for the both the advertising name + UUIDs. Try moving the UUIDs over to the scan response packet.

    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids; 

    Best regards,

    Marjeris

  • Hi Marjeris,

    Thank you for your time.

    I have moved the UUIDs to the scan response as you mentionned but the error is still the same. I also tried to move only the NUS UUID in the scan response and let the BAS and DIS UUIDs in the advertising response (as shown  below) but the error is still the same again

    #define NUS_SERVICE_UUID_TYPE		BLE_UUID_TYPE_VENDOR_BEGIN		/**< UUID type for the Nordic UART Service (vendor specific). */
    
    static ble_uuid_t m_adv_uuids[] =                                   		/**< Universally unique service identifiers. */
    {
        {BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE},
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };
    
    static ble_uuid_t m_sr_uuids[] = {
        {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
    };
    
    /*....*/
    
    init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    init.srdata.uuids_complete.uuid_cnt	 = sizeof(m_sr_uuids) / sizeof(m_sr_uuids[0]);
    init.srdata.uuids_complete.p_uuids   = m_sr_uuids;

  • Maybe this can help find the source of the error: I did try to change the NUS UUID type from BLE_UUID_TYPE_VENDOR_BEGIN to BLE_UUID_TYPE_BLE and now the error is gone. I don't know why this is working because it's the wrong UUID type for NUS.

  • Hi Steve,

    Have you called service_init() before advertising_init() in main()? You can get in trouble if done the other way around, and the NRF_ERROR_INVALID_PARAMS error you mention above in the start of the ticket comes probably from this.

    If this doesn't help please send me your whole main.c file so I can take a look at the rest of the code.

    Best regards,

    Marjeris

Reply Children
Related