This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Bonding issue with DFU BLE on custom board with SDK v10 and SD v8.0

In nutshell, I intend to achieve

Buttonless DFU over BLE on a custom board with SDK v10.0.0 and Softdevice v8.0.0 with bonding retained.

On this custom board, there are neither any buttons nor any external clock, hence I had to make corresponding changes in the sample bootloader (that comes with SDK v10.0.0) and in my application. Currently DFU over BLE is working (triggering DFU from bootloader and/or triggering DFU from the application), but the bonding is getting removed after DFU is completed (see the snip from the MCP logs below)

A 16:11:58.706 [DFU] Activate and Reset request sent
I 16:11:58.949 [DFU] Disconnected by the remote device
D 16:11:58.976 [DFU] gatt.refresh() (hidden)
D 16:11:59.102 [DFU] gatt.close()
V 16:11:59.150 [DFU] Removing bond information...
D 16:11:59.183 [DFU] gatt.getDevice().removeBond() (hidden)
D 16:11:59.244 [Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
D 16:11:59.299 [Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_NONE (10)
I 16:11:59.335 Bond information deleted

Enviornment:

  • SD: v8.0.0
  • SDK: v10.0.0
  • SOC: nrf51822QFAA
  • SOC IC revision: 2
  • Central Application for testing DFU BLE: Nordic's Android phone app, MCP

According to the Compatibility matrix, IC revision 2 is not supported on SDK v10.0.0, but I was told by a Nordic Employee in this thead , that IC revision 2 could also work with SDK v10.0.0 and such efforts are best left to the customers to validate. So, I started porting the application (Bond sharing between Bootloader and Application was not possible with sdk v6.1.0 and SD v7.1.0). The application was ported fine and I did some basic connectivity, and services related tests and it worked well. Now during the DFU over BLE, I face this problem of bonding getting deleted. I suspect the problem is with firmware and not with the IC compatibility issue.

I've set the memory settings for Bootlader in KEIL MDK5 Toolchain, according to this thread and is as follows:

IROM1 Start: 0x0003C000 Size: 0x3C00
IRAM1 Start: 0x20002C00 Size: 0x1380
IRAM2 Start: 0x20003F80 Size: 0x80 (NoInit Checked)

And, Memory settings for application in Keil MDK5 Toolchain:

IROM1 Start: 0x18000 Size: 0x28000 (Total 256 kB main flash memory)
IRAM1 Start: 0x20002000 Size: 0x4000 (Total 16 kB of RAM) 

Some code snips from Application:

// 1: Retain bonding
bool erase_bonds = false;
device_manager_init(erase_bonds);

// 2: Low frequency internal clock source to be used by the SoftDevice
#define NRF_CLOCK_LFCLKSRC NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION

void ble_stack_init()
{
............

SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC, NULL);
............

}

// 3: Allow service change characteristics
#define IS_SRVC_CHANGED_CHARACT_PRESENT     1

In the bootloader, same clock source (NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION) is used in ble_stack_init() and I have commented out following two lines in sample Bootloader code:

//    buttons_init(); /* No buttons on this custom board */

//    dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false); /* no use */

and Service changed characteristic is also set to '1':

// Allow service change characteristics
#define IS_SRVC_CHANGED_CHARACT_PRESENT     1

Setup for "dfu_ble_svc.c" in the bootloader project configuration:

image description

The complete DFU logs collected using nRFLog is attached here.

Has someone seen such behavior ? and how to fix this issue ? My gut feeling is that this is not a IC compatibility issue and I'm probably missing something important in the firmware side.

Please suggest.

Update: 27.05.2019

Attaching central and peripheral logs (please refer my last comment)

Central logs: dfu_central_logs.txt

Peripheral logs: dfu_peripheral_logs.txt

  • Update: 20.05.2016

    Bootloader:

    IROM1:0x3C000 (0x4000)
    IRAM1:0x20002C00 (0x1380)
    IRAM2:0x20003F80 (0x80) No Init box checked
    

    Application:

    IROM1:0x18000 (0x24000)
    IRAM1:0x20002000 (0x4000)
    

    Following are some defaults in my application code:

    #define DEVICE_MANAGER_MAX_APPLICATIONS  1
    #define DEVICE_MANAGER_MAX_CONNECTIONS   1
    #define DEVICE_MANAGER_MAX_BONDS         7
    #define DM_GATT_CCCD_COUNT               4
    #define DEVICE_MANAGER_APP_CONTEXT_SIZE    16
    

    Q.1: How to calculate DM_GATT_CCCD_COUNT and DEVICE_MANAGER_APP_CONTEXT_SIZE?

    In my bootloader code, I'm setting following in dfu_types.h

    #define DFU_APP_DATA_RESERVED           0x400
    

    My application currently does not try to store anything in the flash by using persistent storage manager, however, the application uses device manager which internally uses persistent storage manager, therefore as suggested before, I've set this macro (DFU_APP_DATA_RESERVED) from the default 0x0 to 0x1000. ( pseudo random number based on suggestion)

    Result:

    DFU while devices are bonded works fine, but bond gets deleted once DFU finishes :(

  • @sidekick: I sincerly apologize for not replying sooner. If you have set PSTORAGE_NUM_PAGES to 3, then you'll have to set DFU_APP_DATA_RESERVED to 0x1000. What I mean by "If you're not using the Persistant Storage Manager", is that you're not using it to store application data, i.e. calling pstorage_register from the application.

  • No problem and thanks a lot for helping me out with this issue.

    Update:

    As you suggested, I changed, DFU_APP_DATA_RESERVED to 0x1000 in dfu_types.h (corresponding to· PSTORAGE_NUM_OF_PAGES of 3 in pstorage_platform.h). Also I'm not calling pstorage_register anywhere in my application code.

    Result:

    Bond gets deleted after the upgrade process.

    Question:

    1: I'm using Nordic's Master Control Panel (MCP) app for Android phones for performing firmware upgrade, and I see that there is a option to "Keep bond information" under the setings-> DFU options. At the moment (I think this setting is by default) this is turned OFF, should I turn this ON ?

    2: As I mentioned before, I'm using Softdevice v8.0 with SDK 10.0.0 and to generate the application zip file that contains the application hex image. I used sd_ble_version_get() to find the softdevice version (ble_version_t.subversion_number) and then used nrfutil.exe to generate the zip file as below:

    $ nrfutil.exe dfu genpkg --application myapp.hex --application-version 0xffffffff --dev-type 0xffff --sd-req 0x64 myapp.zip
    

    During DFU-OTA process, I select, the file type as "Distribution packet (ZIP)" and pass this zip file that (myapp.zip) I created before. Is this correct method ?

  • This time, I tried DFU OTA (BLE) over a bonded link with Keep bond information in the MCP android app as ON and I get a hardfault after OTA completes. Since there is no option to attach a file in the comment section, hence i'll be attaching the central and peripheral logs in the original question section. Please advise.

  • @bjorn-spockeli: Can you please give some more pointers ?

Related