BLE DFU softdevice loading issue in bootloader

I've been trying to setup BLE DFU bootloading for my nrf52840, using this tutorial:
https://novelbits.io/nrf52-ota-dfu-ble-part-4/

I've come a long way, I've created an blinky app which works button less. 
also setup the bootloader which includes my public key.

Using the nrfConnect app I can initiate the DFU bootloader only to get it into an infinite bootloop.

To diagnose a bit further I hooked on the debugger and setup the booloader to print the debug logs to its uarts.

I can trace the issue currently to the initialization of the softdevice.

in function "ble_stack_init"

err_code = nrf_dfu_mbr_init_sd();
VERIFY_SUCCESS(err_code);

Gets executed and I am always rewarded with an return code: 7

This is where the bootloader resets.


If I disable the initialization by setting NRF_DFU_BLE_SKIP_SD_INIT=1
the next function "nrf_sdh_enable_request();" returns 1
and the bootloader also resets.

Does anyone have a clue what I am doing wrong?
I've been at this for days without any real progress.

I know the softdevice must work, otherwise the blinky application would not be able to communicate with the nrfConnect app

Attached below is a small snippet of the Application + bootloader logs

<info> app: Inside main
<debug> app: In nrf_bootloader_init
<debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
<debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
<debug> nrf_dfu_settings: Using settings page.
<debug> nrf_dfu_settings: Copying forbidden parts from backup page.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<debug> app: Enter nrf_bootloader_fw_activate
<info> app: No firmware to activate.
<debug> app: App is valid
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<debug> app: Running nrf_bootloader_app_start with address: 0x00001000
<debug> app: Disabling interrupts. NVIC->ICER[0]: 0x0
<info> app: Setting vector table to bootloader: 0x000ED000
<info> app: Setting vector table to main app: 0x00027000
<info> app_timer: RTC: initialized.
<info> app: Blinky. V4.0
<info> app: USBD CDC ACM example started.
<info> app: No USB power detection enabled
Starting USB now
<info> app: Inside main
<debug> app: In nrf_bootloader_init
<debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
<debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
<debug> nrf_dfu_settings: Using settings page.
<debug> nrf_dfu_settings: Copying forbidden parts from backup page.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<debug> app: Enter nrf_bootloader_fw_activate
<info> app: No firmware to activate.
<debug> app: App is valid
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<debug> app: Running nrf_bootloader_app_start with address: 0x00001000
<debug> app: Disabling interrupts. NVIC->ICER[0]: 0x0
<info> app: Setting vector table to bootloader: 0x000ED000
<info> app: Setting vector table to main app: 0x00027000
<info> app_timer: RTC: initialized.
<info> app: Blinky. V4.0
<info> app: USBD CDC ACM example started.
<info> app: No USB power detection enabled
Starting USB now
<info> app: Connected
<info> app: Device is preparing to enter bootloader mode

<info> app: Device will enter bootloader mode

<info> app: Power management wants to reset to DFU mode.
<info> app: Power management allowed to reset to DFU mode.
<info> app: Inside main
<debug> app: In nrf_bootloader_init
<debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
<debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
<debug> nrf_dfu_settings: Using settings page.
<debug> nrf_dfu_settings: Copying forbidden parts from backup page.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<debug> app: Enter nrf_bootloader_fw_activate
<info> app: No firmware to activate.
<debug> app: App is valid
<debug> app: DFU mode requested via GPREGRET.
<info> nrf_bootloader_wdt: WDT is not enabled
<debug> app: in weak nrf_dfu_init_user
<debug> app: timer_stop (0x200059A0)
<debug> app: timer_activate (0x200059A0)
<info> app: Entering DFU mode.
<debug> app: Initializing transports (found: 1)
<debug> nrf_dfu_ble: Initializing BLE DFU transport
<debug> app: Failed to initialize transport 0, error 7
<error> app: Could not initalize DFU transport: 0x00000007
<error> app: Received an error: 0x00000003!
<info> app: Inside main
<debug> app: In nrf_bootloader_init
<debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
<debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
<debug> nrf_dfu_settings: Using settings page.
<debug> nrf_dfu_settings: Copying forbidden parts from backup page.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<debug> app: Enter nrf_bootloader_fw_activate
<info> app: No firmware to activate.
<debug> app: App is valid
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<debug> app: Running nrf_bootloader_app_start with address: 0x00001000
<debug> app: Disabling interrupts. NVIC->ICER[0]: 0x0
<info> app: Setting vector table to bootloader: 0x000ED000
<info> app: Setting vector table to main app: 0x00027000
<info> app_timer: RTC: initialized.
<info> app: Blinky. V4.0
<info> app: USBD CDC ACM example started.
<info> app: No USB power detection enabled
Starting USB now

Parents
  • Hi Sebastiaan,

    So, I wrestle with the project quite a bit today. Here are my "test report" of what you have given me.

    Using your four hex files:

    The device can boot. I see it advertises just fine.
    As I don't have your private key, I cannot test DFU

    So this test doesn't have much meaning...

    Using your bootloader project and my application project:

    I don't run into the same problem with the SoftDevice.
    I did run into a problem which is probably due to logging cannot keep up with the bootloader's activity.
    Changing logging baud to 1,000,000 fixed it, I can perform DFU successfully

    (Of course, there are other differences: I use Windows 10; UART_TX pin changed to 6 because I'm on the DK; and I had to use my private/public key pair; I also restore the nrf_crypto_allocator.h file that you probably unintentionally discarded).

    So there seems to be no problem with your project...


    I observe that the bootloader .emProject file is changed. Besides the addition of UART related libraries, a Debug configuration was added, and the flash size is increased by 0x4000 with the address changed to 0xED000 instead. That explains the difference seen in one of my previous replies.

    Did you intentionally make the above change?

    If you did not, there is the possibility that your SDK was changed in some previous development jobs...

    As I cannot reproduce your issue, I can only recommend you restart the process with a clean download of the SDK.
    If you do restart, this time I recommend you follow the blog post I shared previously though. It is here: Getting started with Nordic's Secure DFU bootloader, a step by step guide  


    As a side note, I did make my own implementation of the NovelBits article work. I did have to add the following small fix though.
    That's for if you wish to give the NovelBits article another try. I recommend giving our guide a try this time.

    static void ble_dfu_buttonless_evt_handler(ble_dfu_buttonless_evt_type_t event)
    {
        ...
        switch (event)
        {
            case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
                sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                NRF_LOG_INFO("Device is preparing to enter bootloader mode\r\n");
                break;
            
            ...
        }
    }

    Sorry it took so much time, but I couldn't figure out what is wrong after all...

    Best regards,

    Hieu

  • Hi Hieu,

    I've just setup an GCC environment instead of the SES environment.

    Now the DFU bootloader works.

    My best guess is that the SES compiler/linker screws something up.

    It now works and am over the moon.
    thank you so much for your assist.

    regards,

    Sebastiaan

Reply Children
  • Hi Sebastiaan,

    It's great that you finally got it to work.

    The fact that the environment change fixed it is very interesting. Your guess is probably right.

    Unfortunately, nRF5 SDK is in maintenance now, so there probably won't be much investigation into it. However, I will still send this back to our team for further discussions and record.

    Thank you for letting us know.

    Best regards,

    Hieu

  • Hi

    Just wondering what exactly did you do when you say you "set up GCC environment instead of SES"...

    Did you give up on using the SES IDE for the build and migrate your boot loader and application builds to a GCC specific (e.g. command line) build?

    OR,

    Did you just change the compiler drivers in the SES IDE from 'gcc' to 'Segger' (or one of the other options)?

    Thanks for your response...

Related