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.

  • 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

  • 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