Error in Settings API on saving BLE connection properties

Hello,

I'm implementing a device based on the NRF52840 Dongle and the hids keyboard example. The basic functionality work, so that I can send pressed keys to a connected device. The problem is that after the restart/power loss, the devices must be paired again.

I added SETTINGS related variables to the prj.conf:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
# NVS variables when enabled prevent boot. Even serial port is not visible in the system
# CONFIG_NVS=y
# CONFIG_SETTINGS_NVS=y
# Setting these two does not change the behavior.
# CONFIG_FCB=y
# CONFIG_SETTINGS_FCB=y
# This variable gets "y" in the build unless NVS or FCB is enabled
# CONFIG_SETTINGS_NONE=n
CONFIG_BT_SETTINGS=y
CONFIG_BT_GATT_CACHING=n
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

main.c:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main(void)
{
if (IS_ENABLED(CONFIG_SETTINGS)) {
err = settings_load();
if (!err) {
printk("settings_load done\n");
} else {
printk("settings_load failed, err=%d\n", err);
}
}
err = bt_enable(NULL);
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return 0;
}
printk("Bluetooth initialized\n");
if (IS_ENABLED(CONFIG_SETTINGS)) {
// see bt_enable() description
err = settings_load_subtree("bt");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

After the successful connection I see several error messages in the console:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
Connected 64:6E:E0:48:6A:A1 (public)
E: Failed to save keys (err -2)
Pairing completed: 64:6E:E0:48:6A:A1 (public), bonded: 1
HID service notified
E: Failed to store CCCs (err -2)
Security changed: 64:6E:E0:48:6A:A1 (public) level 2
E: failed to store SC (err -2)
Output report read
E: Failed to store CCCs (err -2)
E: Failed to store CCCs (err -2)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I tried already different CONFIG combinations, nothing worked. What I'm doing wrong?

Thank you for your answers.

468744.prj.conf