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

CODED PHY using the BLE Advertising module - INVALID PARAMS

Hi! I'm using S140 and I'm using the ble_advertising module to set up advertising.

This is my advertising_init function which is working properly until I uncomment the enabling of the extended advertising. When executing advertising_start, an INVALID_PARAMS error gets thrown in the sd_ble_gap_adv_set_configure function which by the docs points at an invalid adv_params or adv_data. I've verified through the debugger that in adv_params passed into this function, properties->type is set to 0x06 (BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED).

On first glance it looks a lot like https://devzone.nordicsemi.com/f/nordic-q-a/34543/ble-long-range but seeing how in my case the type is set correctly, I'm at a bit of an ends on how to proceed. I can't seem to step further into the functions to see what part of my adv_params or adv_data is invalid. 

/**@brief Function for initializing the Advertising functionality.
 */
static void advertising_init(uint16_t interval_ms)
{
    ret_code_t             err_code;
    ble_advertising_init_t init;
    memset(&init, 0, sizeof(init));
    NRF_LOG_INFO("Initializing advertising with interval %d", interval_ms);

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

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = MSEC_TO_UNITS(interval_ms, UNIT_0_625_MS);
    init.config.ble_adv_fast_timeout  = 0; //Set advertising to permanent

    //init.config.ble_adv_extended_enabled = true;
    //init.config.ble_adv_primary_phy = BLE_GAP_PHY_CODED;
    //init.config.ble_adv_secondary_phy   = BLE_GAP_PHY_CODED;
   
    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);
}

  • Hi,

    The INVALID_PARAMS error is probably returned from the sd_ble_gap_adv_set_configure() called from ble_advertising_start(). You will get INVALID_PARAMS if you set configure the primary PHY as BLE_GAP_PHY_CODED, and disable advertising extension. This is because it is an illegal configuration which is not allowed by the SoftDevice. So the fix is to enable advertising extensions. (Note that you can use coded PHY on the secondary PHY without extended advertising, but not on the primary PHY.) 

  • Hi! Thanks for your swift response! Yes, I mentioned that in my initial post. The error is coming from adv_set_configure() but it's happening even with GAP_PHY_CODED disabled and adv_extended_enabled set to true, so it's definitely the advertising extensions causing the INVALID_PARAMS error. Is there anything else I need to look for? Does the length of the advertising data change? Do I need to change something in SDK_CONFIG? 

    On a different note, I was able to enable coded PHY on the secondary PHY so at least that's working :) 

  • UPDATE: Removing the scan-response data did the trick! Any ideas as to why? (I commented the 2 lines adding the UUID's to the SR). 

  • Hi,

    Thanks for letting us know. That makes sense. It is not legal for extended advertisement packets to be scannable and connectable. You can see this from BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 6, Part B, Section 2.3.4 Common Extended Advertising Payload Format.

  • With SDK 16.0.0 & nRF52840 DK, in ble_app_uart example, does this advertising_init() enable CODED PHY ?
    No other code changes. I made these changes by looking at older posts in the devzone. My program does not crash(no Assert) and I don't see this peripheral device when I scan for BLE devices on my phone, as expected. I want to make sure if these changes are enough to use Coded PHY on peripheral.

    I am yet to edit ble_app_uart_c program to flash on another nRF52840 DK  to scan and connect with this peripheral.

    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 = false;
     // init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
            init.advdata.flags              =BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    
     //   init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); // no scan response in Coded PHY
     //   init.srdata.uuids_complete.p_uuids  = m_adv_uuids;
            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.config.ble_adv_primary_phy       = BLE_GAP_PHY_CODED;  // use Coded PHY
                init.config.ble_adv_secondary_phy     = BLE_GAP_PHY_CODED;
                init.config.ble_adv_extended_enabled  = true;               // Coded PHY needs extended adv (bigger adv packet size)
        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);
    }

Related