ERROR : Could not acquire conn_state user flags. Increase BLE_CONN_STATE_USER_FLAG_COUNT in the ble_conn_state module.

Hi! 

For a custom project, I need to enable and disable soft device on a peripheral. I'm able to enable/disable softdevice for two cycles, then I get this error:

<error> peer_manager_gcm: Could not acquire conn_state user flags. Increase BLE_CONN_STATE_USER_FLAG_COUNT in the ble_conn_state module.
<error> peer_manager: pm_init failed because gcm_init() returned NRF_ERROR_INTERNAL.

We init peer_manager in our project due to copy of sdk projects. We use the pm_init() function. I see that those flags are incremented at each new softdevice enables:

  m_flag_local_db_update_pending = ble_conn_state_user_flag_acquire();
    m_flag_local_db_apply_pending  = ble_conn_state_user_flag_acquire();
    m_flag_service_changed_pending = ble_conn_state_user_flag_acquire();
    m_flag_service_changed_sent    = ble_conn_state_user_flag_acquire();
    m_flag_car_update_pending      = ble_conn_state_user_flag_acquire();
    m_flag_car_handle_queried      = ble_conn_state_user_flag_acquire();
    m_flag_car_value_queried       = ble_conn_state_user_flag_acquire();

After a few enables, those flags are greather than BLE_CONN_STATE_USER_FLAG_COUNT and the error above pops out.  When I comment out the peer manager initialisation, there's obviously no error and ble seems to work without any problem. There is the peer manager init function : 

void peer_manager_init()
{
    ble_gap_sec_params_t sec_param;
    ret_code_t           err_code;

    // Flag that prevents from peer manager reinitialization.
    static bool        peer_manager_initialized = false;

    err_code = pm_init();
    APP_ERROR_CHECK(err_code);

    memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));

    // Security parameters to be used for all security procedures.
    sec_param.bond           = SEC_PARAM_BOND;
    sec_param.mitm           = SEC_PARAM_MITM;
    sec_param.lesc           = SEC_PARAM_LESC;
    sec_param.keypress       = SEC_PARAM_KEYPRESS;
    sec_param.io_caps        = SEC_PARAM_IO_CAPABILITIES;
    sec_param.oob            = SEC_PARAM_OOB;
    sec_param.min_key_size   = SEC_PARAM_MIN_KEY_SIZE;
    sec_param.max_key_size   = SEC_PARAM_MAX_KEY_SIZE;
    sec_param.kdist_own.enc  = 1;
    sec_param.kdist_own.id   = 1;
    sec_param.kdist_peer.enc = 1;
    sec_param.kdist_peer.id  = 1;

    err_code = pm_sec_params_set(&sec_param);
    APP_ERROR_CHECK(err_code);

    err_code = pm_register(pm_evt_handler);
    APP_ERROR_CHECK(err_code);
}

So what should be the best solution so those flags don't increments? only call once pm_init()? dont use pm manager

If I don't enable pm manager what should I expect to be missing out? We use NUS and DFU services in our project.

Thank you!

  • Hi

    What SDK and SoftDevice version are you using for development? The peer manager will indeed not react well to disabling the SoftDevice during run time. Why exactly do you need to disable the SoftDevice at all? Are you using the radio or some other peripheral controlled by the SoftDevice for something else?

    The peer manager is used to manage BLE securtiy (encryption, pairing, and bonding) and makes it easy to store bonding info and GATT data for bonded peer devices, so you miss out on a good implementation of BLE security procedures that are required by the Bluetooth specification, and you'll have a harder time making Bluetooth compliant application.

    Best regards,

    Simon

  • Hi Simonr, Thanks for the answer!

    I'm using sdk 16.0.0.

    I want to disable softdevice to achieve lowest current consumption possible In the range of 2uA to 10 uA. I've been able to achieve pretty lower power consumption by enabling and disabling soft device. When I enable softdevice, I see a current consumption of about 400 uA without advertising. Maybe there is a way to keep soft device enable and achieve low power consumption? Then I'll be able to keep the peer manager?

    Thank you!

  • Hi

    Yes, it should not be the SoftDevice that draws this amount of power if you put it to sleep using a function like the idle_state_handle() function in most of our example main.c files. Can you show me the current consumption you're seeing and I can try to make sense of it and let you know what's going on. You can also check out our Power optimization guide for nRF52 designs.

    Best regards,

    Simon

Related