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:

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

main.c:

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");
		if (!err) {
			printk("settings_load BT done\n");
		} else {
			printk("settings_load BT failed, err=%d\n", err);
		}
	}
	
	...

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

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)

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

Thank you for your answers.

468744.prj.conf

Parents Reply Children
  • I tried, I made a fresh installation of sdk and the toolchain.

    The result is the same. I don't see the USB port after the application start.

    I tried to debug, but ran into another problem, GDB server kills the app after the initial break point. Somehow auto confirmation is configured or may be it is so be default.

    This is the output:

    Thread 2 received signal SIGTRAP, Trace/breakpoint trap.
    0x00000578 in ?? ()
    Kill the program being debugged? (y or n) [answered Y; input not from terminal]
    [Inferior 1 (Remote target) killed]

    This part is strange "answered Y; input not from terminal".

    There is a command in GDB `set confirm off` but I don't know how to apply it in NRF Connect fro VSCode

  • Evgeny M said:
    The result is the same. I don't see the USB port after the application start.

    For the setup, you can refer to samples/subsys/usb/console

    Evgeny M said:
    I tried to debug, but ran into another problem, GDB server kills the app after the initial break point. Somehow auto confirmation is configured or may be it is so be default.

    The nRF52840 Dongle is provided as the propopyping and doesn't have an onboard debugger, so it is unsuitable for development. Please use nRF52840DK to debug. 

  • The nRF52840 Dongle is provided as the propopyping and doesn't have an onboard debugger, so it is unsuitable for development. Please use nRF52840DK to debug.

    I use J-Link

    Finally I found the root of the problem.

    The storage partition in the zephyr/boards/nordic/nrf52840dongle/fstab-stock.dtsi has the following definition:

    storage_partition: partition@dc000 {
    	label = "storage";
    	reg = <0x000dc000 0x00004000>;
    };

    This means that it ends right before the dongle Bootloader partition at the address 0xE0000.

    But all the addresses are actually shifted up on 0x1000 because of the dongle's MBR. (CONFIG_FLASH_LOAD_OFFSET=0x1000)

    So the storage partition is conflicting with the DFU partition and this causes fault when it tries to write anything there.

    I change the start of the storage_partition to 0xDB000 and now everything works:

    storage_partition: partition@db000 {
    	label = "storage";
    	reg = <0x000db000 0x00004000>;
    };

    The only problem is that I could not do this in the overlay file, because it's not possible to change the name of the existing node.

    I think this is an error in the dtsi and it should be fixed in the future releases

  • I forgot to mention that the size of the slot1_partition should be also changed

    slot1_partition: partition@76000 {
        label = "image-1";
    	reg = <0x00076000 0x00066000>;
    };

Related