1

Why does sd_ble_cfg_set return Invalid Param for cfg_id BLE_CONN_CFG_GATTS?

bwhanson gravatar image

asked 2017-05-18 16:25:22 +0100

updated 2017-05-18 16:26:50 +0100

I am attempting to increase the queue size for handle value notifications to support a higher number of packets per connection event. However, I am unable to set the queue size using the BLE_CONN_CFG_GATTS cfg_id, as the function always returns "Invalid Param", which is documented to mean an improper cfg_id. Is there a step I'm missing? My softdevice and stack initialization code is below. This is for SDKv13, SoftDevice S132 v4.0.2.

static void ble_stack_init(void)
{
    uint32_t err_code;

    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;

    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true);

    // RAM Start
    uint32_t ram_start = 0;
    err_code = softdevice_app_ram_start_get(&ram_start);
    APP_ERROR_CHECK(err_code);

    // BLE Configuration
    ble_cfg_t ble_cfg;

    // VS UUIDs
    memset(&ble_cfg, 0, sizeof ble_cfg);
    ble_cfg.common_cfg.vs_uuid_cfg.vs_uuid_count = 2;
    err_code = sd_ble_cfg_set(BLE_COMMON_CFG_VS_UUID, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);

    // Max Connections
    memset(&ble_cfg, 0, sizeof ble_cfg);
    ble_cfg.gap_cfg.role_count_cfg.periph_role_count = BLE_GAP_ROLE_COUNT_PERIPH_DEFAULT;
    ble_cfg.gap_cfg.role_count_cfg.central_role_count = 0;
    ble_cfg.gap_cfg.role_count_cfg.central_sec_count = 0;
    err_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);

    // Max Packets Per Connection Event
    memset(&ble_cfg, 0, sizeof ble_cfg);
    ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 4;
    err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = softdevice_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    // 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 BLE events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}
edit retag flag offensive close delete report spam

1 answer

Sort by ยป oldest newest most voted
1
Petter gravatar image

answered 2017-05-19 17:09:11 +0100

The connection configuration can't be BLE_CONN_CFG_TAG_DEFAULT (0).

Something like this should work:

memset(&ble_cfg, 0, sizeof ble_cfg);
ble_cfg.conn_cfg.conn_cfg_tag                     = 1;
ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 4;
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);
APP_ERROR_CHECK(err_code);
edit flag offensive delete publish link more

Comments

Thanks for the response. I made this modification and was able to (sort of) get past that error, however now the advertising module complains about the same error code. That's from the call to ble_advertising_start. Are the two related in any way? I wouldn't imagine that updating the stack config would interfere with advertising, but apparently that's the case.

Any insight is appreciated.

Brad Hanson ( 2017-05-19 17:52:08 +0100 )editconvert to answer

Both modules should use the same tag i guess. What example in the SDK 13 is this???

Daniel Wang ( 2017-05-19 17:58:42 +0100 )editconvert to answer

This isn't an example, it's an application we're writing ourselves. We're utilizing chunks of code from the template app included with SDK 13, however.

It's definitely strange behavior. The advertising module works fine prior to making the tx queue size change (as in it's commented out entirely), but throws an Invalid Param upon calling ble_advertising_start after adding the TX change.

Brad Hanson ( 2017-05-19 20:41:09 +0100 )editconvert to answer

Can you check where inside ble_advertising_start() the error is returned?

Petter Myhre ( 2017-05-20 18:21:32 +0100 )editconvert to answer

Line 579 of an unmodified ble_advertising.c. It's a call to sd_ble_gap_adv_start. It looks like it's getting a value for that cfg_tag of BLE_CONN_CFG_TAG_DEFAULT...do I need to change that behavior now that i've modified the cfg_tag of the running ble config?

EDIT: Yes, it appears I need to update the BLE CFG tag using ble_advertising_conn_cfg_tag_set(). Is there a way I should be programmatically gathering the tag of the current configuration, or am I best off leaving that as a #define somewhere and using the same value through both ble_stack_init() and with cfg_tag_set() between the advertising init and start?

Brad Hanson ( 2017-05-22 14:38:12 +0100 )editconvert to answer

I believe you are best of leaving a #define somehwere.

Petter Myhre ( 2017-05-22 16:05:20 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

Question Tools

1 follower

Stats

Asked: 2017-05-18 16:25:22 +0100

Seen: 278 times

Last updated: mai 19