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

Enabling 2MBPS and CODED PHYs

Hello, I have a project that's fairly mature and working great but now I want to extend the abilities of the device by using the extended PHYs. I know there are a million threads on this but I can't make any sense out of any of them. I tried looking at the throughput example, and updating my code to match and I still get errors all over the place. I guess I don't even understand how this is supposed to work and what all of it is. I saw a post from years ago that someone was going to create a blog post on what the different advertising types were, etc but I don't think it ever happened.

Here is the relevant code from my project, which I believe I used Blinky as a base example when creating this, along with some questions

static uint8_t m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX];                    /**< Buffer for storing an encoded advertising set. */
static uint8_t m_enc_scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX];         /**< Buffer for storing an encoded scan data. */

/**@brief Struct that contains pointers to the encoded advertising data. */
static ble_gap_adv_data_t m_adv_data =
{
    .adv_data =
    {
        .p_data = m_enc_advdata,
        .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
    },
    .scan_rsp_data =
    {
        .p_data = m_enc_scan_response_data,
        .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX

    }
};

What do these do/store? the throughput example has two different sets of these, but it doesn't use the scan_rsp_data anywhere.

void advertising_init(void){

    ret_code_t    err_code;
    ble_advdata_t advdata;
    ble_advdata_t srdata;

    ble_uuid_t adv_uuids[] = {{CTCWS_UUID_CONFIG_SERVICE, m_ctcws.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              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;


    memset(&srdata, 0, sizeof(srdata));
    srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    srdata.uuids_complete.p_uuids  = adv_uuids;

    err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    APP_ERROR_CHECK(err_code);

    err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
    APP_ERROR_CHECK(err_code);

    ble_gap_adv_params_t adv_params;

    // Set advertising parameters.
    memset(&adv_params, 0, sizeof(adv_params));

    adv_params.primary_phy      = tx_rate;
    adv_params.primary_phy      = tx_rate;
    adv_params.duration         = advertise_timeout;
    adv_params.properties.type  = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params.p_peer_addr     = NULL;
    adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
    adv_params.interval        = advertise_interval;

    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_adv_handle, tx_power);
    APP_ERROR_CHECK(err_code);

    #ifdef DEBUG
    printf("advertising_init\r\n");
    #endif
}

This all works great at 1MBPS, but changing the primary and secondary phy to either CODED or 2MBPS, and changing the type to  BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED causes me to get an error at one or the other of ble_adv_data no matter how I set up ble_gap_adv_data_t.adv_data or ble_gap_adv_data_t.scan_rsp_data.

I also don't know if this has something to do with MTU? That's my next challenge is extending that, right now I think I'm just using the standard 23 byte MTU for backwards compatibility.

Do I need to do anything with the connection to change speeds? or just the advertising?

Can I get a simple explanation of how to update this (blinky) code to allow 2MPBS and CODED, without just saying "look at the mtu throughput example" like all the other threads? It's not making any sense to me and I can get this to work based on the mtu throughput example.

SDK is 15.2.0 SD is S140 - 6.1.0

Parents Reply
  • You mentioned that you were using blinky example as the base. I assume it's the ble_app_blinky. The code I posted should work with the ble_app_blinky as the base so you can modify it to your needs. 

    If you want to have your own service UUID/data in the advertising packet. Just use advdata instead of srdata


    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    advdata.uuids_complete.p_uuids = adv_uuids;

    As long as you set     m_adv_data.scan_rsp_data.len=0; the code should work with just the .phys and the .type change. 

Children
No Data
Related