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

Error 12 from ble_advdata_set

I'm attempting to use a custom UUID as outlined in nAN-36. I get an error (NRF_ERROR_DATA_SIZE) when I call ble_advdata_set. Specifically:

  1. ble_advdata.c::uuid_list_encode calls uuid_list_sized_encode to encode all the 16 bit UUIDs (which skips over the last UUID since it's 128 bits).
  2. uuid_list_encode calls uuid_list_sized_encode again for the 128 bit UUIDs.
  3. uuid_list_sized_encode loops through all the UUIDs again and calls sd_ble_uuid_encode on each to check the size.
  4. On the first call, sd_ble_uuid_encode throws an error (this is on a 16 bit UUID).

This seems odd to me: sd_ble_uuid_encode was able to use that UUID before when uuid_list_sized_encode was looping through looking for 16 bit UUIDs.

In any case, here's pretty much the entire program:

#define HMS_UUID_BASE {0x63, 0x98, 0x3A, 0xFA, 0x10, 0x6A, 0x5E, 0x9A, 0xDD, 0x2D, 0x33, 0x58, 0x00, 0x00, 0xD2, 0x97}
#define HMS_UUID_SERVICE 0x1523
int main(void)
{
    // Initialize GPIOTE. Used by CC1101 and BLE.
    APP_GPIOTE_INIT(MAX_USERS);

    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);

    // Initialize board support. The timers must be initialized before this point.
    uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);

    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);

#if defined(S110) || defined(S310)
    // Enable BLE stack
    ble_enable_params_t ble_enable_params;
    memset(&ble_enable_params, 0, sizeof(ble_enable_params));
    ble_enable_params.gatts_enable_params.service_changed = 0;
    err_code = sd_ble_enable(&ble_enable_params);
    APP_ERROR_CHECK(err_code);
#endif

    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);

    // Register with the SoftDevice handler module for system events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);

    ble_advdata_t advdata;
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    ble_uuid128_t base_uuid = HMS_UUID_BASE;
    uint8_t uuid_type;
    err_code = sd_ble_uuid_vs_add(&base_uuid, &uuid_type);
    APP_ERROR_CHECK(err_code);

    ble_uuid_t adv_uuids[] =
    {
        {BLE_UUID_HEART_RATE_SERVICE,         BLE_UUID_TYPE_BLE},
        {BLE_UUID_BATTERY_SERVICE,            BLE_UUID_TYPE_BLE},
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE},
        {HMS_UUID_SERVICE,                    uuid_type}
    };

    // Build and set advertising data.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = true;
    advdata.flags.size              = sizeof(flags);
    advdata.flags.p_data            = &flags;
    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = adv_uuids;

    err_code = ble_advdata_set(&advdata, NULL);
    APP_ERROR_CHECK(err_code);
Related