bt_enable fails and returns code -22

Our project was previously functional when we were developing using the nrf52840dk_nrf52840 with an overlay to reconfigure for our custom pcba. We created a custom board config using the "Create a new board" thing in  nRF Connect. After adding a bunch of apparently missing CONFIGs in <custom_pcba_name>_defconfig, and copying all the dts stuff over form zephyr/boads/arm/nrf52840dk_nrf52840 the project builds, but fails in runtime on a call to bt_enable, with following output to the console:

E: Unable to get page info
E: settings_subsys_init failed (err -22)
Bluetooth init failed (err -22)
ble_init() failed

Any help on how to fix this would me much appreciated.

Thank you.

  • err -22 = invalid argument,

    Can you start your application in debugger to find the originator of this error? Some module seems to have been called with invalid arguments. It is hard to say without seeing some code snippets on how you initialized and enabled BLE.

  • Susheel,

    Thank you for getting back.

    I stepped through main() as shown:

    The console output is after halting at line 38 is:

    The definition of ble_init is:

    int ble_init() {
           int err;

        bt_conn_cb_register(&conn_callbacks);
        if (IS_ENABLED(CONFIG_BT_LBS_SECURITY_ENABLED))
        {
            bt_conn_auth_cb_register(&conn_auth_callbacks);
            bt_conn_auth_info_cb_register(&auth_cb_info);
        }

        err = bt_enable(NULL);
        if (err)
        {
            printk("Bluetooth init failed (err %d)\n", err);
            return err;
        }


        if (IS_ENABLED(CONFIG_SETTINGS))
        {
            settings_load();
        }

        err = bt_nus_init(&nus_cb);
        if (err) {
                printk("Failed to initialize UART service (err: %d)", err);
                return err;
        }

        struct bt_le_adv_param param =
            BT_LE_ADV_PARAM_INIT(
    //                     BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED,
                         BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_EXT_ADV,
                         BT_GAP_ADV_FAST_INT_MIN_2,
                         BT_GAP_ADV_FAST_INT_MAX_2,
                         NULL);


        err = bt_le_ext_adv_create(&param, NULL, &adv);
        if (err) {
            printk("Failed to create advertiser set (%d)\n", err);
            return err;
        }
        
        //Copy serial number in adv packets
        memcpy(app_adv_data+BLE_MANUFACTURE_ID_LENGTH, serial_num, SERIAL_NUMBER_LENGTH);

        err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
        if (err) {
            printk("Failed to set advertising data (%d)\n", err);
            return err;
        }
        printk("Bluetooth initialized\n");

        return err;
    }

    There is no output from the debug console.

    I think  bt_conn_cb_register is generating the "E: Unable to get page info" error, and possibly "E: settings_subsys_init failed (err -22)". Obviously bt_enable is failing, possibly due to the failure bt_conn_cb_register.

    As a reminder, all of this working before we migrated the project from v1.8.0 to v2.1.2 (added all the pinctrl stuff to the dts files) and used a custom board config rather than nrf52840dk_nrf52840 with overlay.

  • zsvtmml said:
    The console output is after halting at line 38 is:

    You can start your application in debug mode and step into this function ble_init to narrow down the exact place where this happens. It is still hard for me to see anything wrong with the arguments used in this functions.

Related