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

How to implement DFU in NRF52 [BMD301] via BLE and UART Method simultaneously?

Hi,

  • I have used BMD301 BLE chip. I have connected one wifi chip "ESP02" with BMD301 chip via UART.
  • I am using nRF5_SDK_15.3.0_59ac345 for my ble application firmware.
  • Currently I have implemented DFU in my application firmware. I am able to update BMD301 firmware via NRF Connect app.
    It works fine. For that, I have used the below example for a bootloader.
    • Bootloader : nRF5_SDK_15.3.0_59ac345\examples\dfu\secure_bootloader\pca10040_ble 
    • Main application firmware : nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\ble_app_buttonless_dfu
  • Now I want to update BMD301 firmware via UART and BLE both.

As I have seen in SDK examples, There are some examples for bootloader.
nRF5_SDK_15.3.0_59ac345\examples\dfu\secure_bootloader\pca10040_ble,
nRF5_SDK_15.3.0_59ac345\examples\dfu\secure_bootloader\pca10040_uart

Can you guide me, How can I implement DFU in BMD301 via BLE and UART simultaneously?
What change I have to make in "sdk_config.h"? Please share all the required steps.

Thanks.

Parents
  • Hi Edvin,

    For testing I am using below development board which has the UART pins P0.08 and P0.06 

    https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide?view=all

    So you know  I want to test UART bootloder,

    I have compiled below example

    nRF5_SDK_15.3.0_59ac345\examples\dfu\secure_bootloader\pca10040_uart

    and take its hex file as bootloader.hex.

    Currently, I have merged bootloader.hex, softdevice, settings, and blinky_app.hex

    and just uploaded firmware using Segger Jlink EDU.

    It work fine and adverising as Nordic_blinky.

    I have generated zip file with softdevice or without soft device. then I have tried below command but thats not works.

    nrfutil dfu serial -pkg FW.zip -p COM3 -b 115200

    Can you guide me?

    Thanks.

     

  • VIJAY said:

    I have generated zip file with softdevice or without soft device. then I have tried below command but thats not works.

    nrfutil dfu serial -pkg FW.zip -p COM3 -b 115200

     What application are you trying to create the DFU image from, and what is the command that you use? You should use an example that uses the softdevice, and you don't need to include the softdevice in the DFU image. 

    So, what command did you use to generate the image, and what do you mean by "that not works"? What does it say when it doesn't work?

  • Hi Edvin,

    I am describing what I have done. See the below steps.

    I have attached zip file where I have list all scripts..

    Here added bootloader is

    nRF5_SDK_15.3.0_59ac345\examples\dfu\secure_bootloader\pca10040_uart

    I have run first 06_copy_buttonless_create_settings_merge_flash - FULL RESET WITH SD+BL.bat file first.

    I think after running this script, I could be able to update firmware via uart pins.

    Am I Right?

    I have two scripts to create a zip file of the firmware.

    03_create_fw_zip_package.bat,

    03b_create_fw_zip_package_noSD.bat 

    Above both scripts generare FW.zip file.

    at the end of above both scripts I have added one line to upload the same firmware via uart.

    nrfutil dfu serial -pkg FW.zip -p COM3 -b 115200

    I have connected this module via usb cable which port is COM3 in my case.

    https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide?view=all

    File created but not uploading.

    Let me know, Should I add any specific function or code to start uart boot loader mode in my main application. in current scenario, its below example I have used.

    Currently, I haven't added anything extra in below code.

    nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\ble_app_blinky

    PFA.

    nrf-upload-commands.zip

  • Ok, so let us focus on the noSD .bat script. To simplify, you are using the command:

    nrfutil pkg generate --application app.hex --application-version 1 --application-version-string "1.0.0" --hw-version 52 --sd-req 0xB7 --key-file private.pem FW.zip

    Right?

    Try removing the --application-version-string argument. 

    And I will ask one more time:

     

    Edvin said:
    what do you mean by "that not works"? What does it say when it doesn't work?

     Does nrfutil say anything? Or does it say: "sorry. It didn't work"?. Perhaps you can share a screenshot.

  • Hi Edvin,

    See the screenshot

    nrfutil dfu serial -pkg FW.zip -p COM3 -b 115200

    what do you mean by "that not works"? What does it say when it doesn't work?

    using above command , not be able to upload firmware via uart.

  • Ok, so your UART is not working. It is not responding. Your UART pins are probably not routed to your computer. Does your module (BMD301) have an on board debugger?

    Is the BMD301 equipped with an onboard debugger?

    I think you need to check with the producers of the BMD301 if and how the UART pins are connected to the BMD's programmer (if it has a programmer). Or maybe it says in the datasheet.

    BR,

    Edvin

Reply
  • Ok, so your UART is not working. It is not responding. Your UART pins are probably not routed to your computer. Does your module (BMD301) have an on board debugger?

    Is the BMD301 equipped with an onboard debugger?

    I think you need to check with the producers of the BMD301 if and how the UART pins are connected to the BMD's programmer (if it has a programmer). Or maybe it says in the datasheet.

    BR,

    Edvin

Children
  • Hi Edvin,

    For testing i am using readymade development board

    https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide?view=all

    It has USB connector. I am able to see log on uart port using below examples,

    nRF5_SDK_15.3.0_59ac345\examples\

    So on this board has UART pins P0.08 and P0.06.

    To upload firmware in this module I have used swd and swdio pins.

    Here, I think I am missing some configuration in the bootloader section.

    - Do we need to add any function or code to start uart bootloader in our application? like

    nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\ble_app_blinky

    -  When I have uploaded BLE bootloader, then I have merged with below example

    nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\ble_app_buttonless_dfu

    I think, in this code, something is added which helps to enable bootloader mode when I pass it zip file via nrf connect application in DFU service.

    So I think similarly in case of uart bootloader code there must be a method to trigger uart bootloader and then we need to give the command. Right?

    nrfutil dfu serial -pkg FW.zip -p COM3 -b 115200

    I have found this example, Can you guide me what this example does in short?

    UART DFU Master code: DFUMaster_UART.zip

    https://devzone.nordicsemi.com/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-00-14/DFUMaster_5F00_UART.zip

  • VIJAY said:

    -  When I have uploaded BLE bootloader, then I have merged with below example

    nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\ble_app_buttonless_dfu

     What does this mean? What did you merge the ble_app_buttonless_dfu example with?

    Have you tried to debug in the bootloader project? Set a breakpoint and see if it is hit or not.

    You didn't merge the bootloader project with the buttonless_dfu example? The bootloader is supposed to be a standalone project and hex file.

    The way the bootloader works is that if you program either the softdevice or the MBR (the MBR is included in the softdevice) whenever you reset the nRF the MBR will check if there is a bootloader present or not. If there is a bootloader, it will run the bootloader. If the bootloader doesn't see any sign on staying in DFU mode (button press or register set by the buttonless_dfu_service) it will continue by starting the application.

    What do you intend to do with the DFUMaster_UART project that you attached? That is not related to the bootloader itself. This is a demo replacement project for nrfutil. The bootloader is located in SDK\examples\dfu\secure_bootloader.

     

    VIJAY said:
    I think, in this code, something is added which helps to enable bootloader mode when I pass it zip file via nrf connect application in DFU service.

     Is that your question now? How to put the device in DFU mode? This has to be done either by the application or by e.g. pressing a button while resetting the device. If your application is running, then nrfutil will not be able to communicate with the bootloader.

    This is a long shot, but I will try.

    If you want to trigger DFU mode via UART, you have to do this from your application. If you look in the bootloader project, study the function:

    nrf_bootloader_init() -> dfu_enter_check():

    if (NRF_BL_DFU_ENTER_METHOD_GPREGRET &&
           (nrf_power_gpregret_get() & BOOTLOADER_DFU_START))
        {
            NRF_LOG_DEBUG("DFU mode requested via GPREGRET.");
            return true;
        }

    If the GPREGRET register is set to 0xB1, it will enter DFU mode, so if you write this to your application before you reset, it will enter dfu mode. Perhaps you can use some special UART command to trigger this. E.g. if you receive "dfu mode enter" over the UART, then you have a handler that will set this register and then reset:

    static void enter_dfu_mode(void)
    {
        uint8_t gpregret_value = nrf_power_gpregret_get();
        gpregret_value |= 0xB1; // Add (or) 0xB1 to whatever the value was before.
        nrf_power_gpregret_set(gpregret_value);
        
        while ((nrf_power_gpregret_get() & 0xB1) != 0xB1)
        {
            // Wait for the register to be properly written before we continue.
        }
        
        NVIC_SystemReset(); // Reset the nRF. With the given gpregret the bootloader will enter DFU mode.
        
    }

    If you call this from somewhere in your application, the nRF will enter DFU mode. Quite similar (but not exactly) to how the ble_app_buttonless_dfu example does it.

    BR,

    Edvin

Related