To explain our problem: We have a system with a NRF52840 chip, we also have an external flash, the settings_subsystem is mounted in the NVS on the internal flash I have included our ninja partition_manager_report below. We are using MCUBoot and Mcumgr to DFU our device. Upon performing a DFU, when the device reboots after the swap, our bt_enable() fails with a settings_subsystem_init() fail with error -45 (-EDEADLK). This error cannot be fixed with a restart, it also cannot be fixed by performing a factory reset on our device which deletes the bluetooth bond keys with a call to bt_unpair(BT_ID_DEFAULT, BT_ADDR_LE_ANY).
There is one way for us to fix the error, we can fix it by erasing the external flash.
We do not understand why erasing the external flash fixes the issue, they seem unrelated.
Flashing it with Jlink does not produce this issue, it only occurs after a DFU.
external_flash (0x1000000 - 16384kB): +------------------------------------------------+ | 0x0: mcuboot_secondary (0xe7000 - 924kB) | | 0xe7000: littlefs_storage (0xf19000 - 15460kB) | | 0x1000000: external_flash (0x0 - 0B) | +------------------------------------------------+ flash_primary (0x100000 - 1024kB): +--------------------------------------------------+ | 0x0: mcuboot (0x15000 - 84kB) | +---0x15000: mcuboot_primary (0xe7000 - 924kB)-----+ | 0x15000: mcuboot_pad (0x200 - 512B) | +---0x15200: mcuboot_primary_app (0xe6e00 - 923kB)-+ | 0x15200: app (0xe6e00 - 923kB) | +--------------------------------------------------+ | 0xfc000: qual_storage (0x1000 - 4kB) | | 0xfd000: user_storage (0x1000 - 4kB) | | 0xfe000: settings_storage (0x2000 - 8kB) | +--------------------------------------------------+ sram_primary (0x40000 - 256kB): +--------------------------------------------+ | 0x20000000: sram_primary (0x40000 - 256kB) | +--------------------------------------------+