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

Booting in application and after a button press goning into DFU

Hello,

I'm trying to modify the dfu_dual_bank_ble_s130_pca10028 bootloader so my device would start with the application and after a signal (with the button) it should start the DFU so it could be updated.

I'm using th nRF51422 (pca10028) uController with SDK 11, the S130 Softdevice and nRFutil 0.5.2.

Any Ideas how i could achiev that?

Parents
  • Hi Matthias, 

    I suggest that you take a look at the bootloader_start() function in dfu_app_handler.c

    Do you bond with the nRF51422 device? If not, then the implementation can be simplified a bit. Also, should the DfuTarget perform directed advertisment to the device it was connected to when the button was pressed or should any device be able to connect after the nRF51422 enters bootloader mode?

    Best regards

    Bjørn

  • Hi Bjørn.

    in the example the dfu_app_handler.c isn't included. How do I Import it to the projekt so it works like intendet?

    I was thinking about setting a flag with GPREGRET and go into the application if its set (before sleep mode) or stays and wait for dfu if it was clear. But I don't know witch bit from the 8 bits is free to use without messing up the bootloader.

    Yes I bond with the nRF51422 device, frist to the DfuTarget to upload my application and afterwards to the application to get the wanted information from it.

    The device can advertis freely.

    Grettings

    Matze

  • Hi Matthias, 

    The bootloader will start the application if there is a valid application present on the device. If the bootloader button is pressed or the GPREGRET registers is set to BOOTLOADER_DFU_START (0xB1) then the bootloader will stay in bootloader mode. 

        bool     dfu_start = false;
        bool     app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START);
    
        if (app_reset)
        {
            NRF_POWER->GPREGRET = 0;
        }
        
        dfu_start  = app_reset;
        dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false);
        
        if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START)))
        {
            nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED);
    
            // Initiate an update of the firmware.
            err_code = bootloader_dfu_start();
            APP_ERROR_CHECK(err_code);
    
            nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED);
        }
        
          if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress())
        {
            // Select a bank region to use as application region.
            // @note: Only applications running from DFU_BANK_0_REGION_START is supported.
            bootloader_app_start(DFU_BANK_0_REGION_START);
        }

    dfu_app_handler.c is included in the application code, not the bootloader code, see the nRF5_SDK_11.0.0_89a8197\examples\ble_peripheral\ble_app_hrs\pca10028\s130_with_dfu project. 

Reply
  • Hi Matthias, 

    The bootloader will start the application if there is a valid application present on the device. If the bootloader button is pressed or the GPREGRET registers is set to BOOTLOADER_DFU_START (0xB1) then the bootloader will stay in bootloader mode. 

        bool     dfu_start = false;
        bool     app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START);
    
        if (app_reset)
        {
            NRF_POWER->GPREGRET = 0;
        }
        
        dfu_start  = app_reset;
        dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false);
        
        if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START)))
        {
            nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED);
    
            // Initiate an update of the firmware.
            err_code = bootloader_dfu_start();
            APP_ERROR_CHECK(err_code);
    
            nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED);
        }
        
          if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress())
        {
            // Select a bank region to use as application region.
            // @note: Only applications running from DFU_BANK_0_REGION_START is supported.
            bootloader_app_start(DFU_BANK_0_REGION_START);
        }

    dfu_app_handler.c is included in the application code, not the bootloader code, see the nRF5_SDK_11.0.0_89a8197\examples\ble_peripheral\ble_app_hrs\pca10028\s130_with_dfu project. 

Children
No Data
Related