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

Bootloader with FDS

Hi everyone!

I have an application based on experimental_ble_app_eddystone for nRF52 (SDK12.2), which uses FDS to save in flash memory. Now I want to add the secure_bootloader to update the firmware with DFU.

My way to "activate" DFU mode is to write an "activation byte" in flash in the application and then reset. The bootloader always checks this byte and if the value corresponds to the "activation value", it begins DFU.

The problem is that because the application uses FDS to deal with flash, I feel forced to use FDS in bootloader as well (because it is hard to control the exact address this "activation byte" is placed).

This means to add the whole fds library, which forces me to expand the start address and default size of bootloader from 0x78000/0x6000 to 0x77000/0x7000.

I managed to do that, but other problems have appeared. I had to change too much the bootloader and then I get errors like gettinc SVC Handler, no fds handler calling or getting FDS_ERR_NO_PAGES error.

I would like to know if there is something that I also should have taken into account when doing this, or if there is a better strategy to enable DFU mode from the application. I know Nordic uses the DFU service, but I would prefer not having to modify the number of services my application uses now.

Thank you very much

Parents
  • Hi dblasco,

    if you want to enter bootloader mode from the application then you only have to write to one of the nRF52s GPREGRET registers(general purpose registers that are retained through a Soft Reset) and then check this register once you enter the bootloader on startup.

    Thus, you only need to call the following snippet in your application when you want to enter bootloader mode.

    err_code = sd_power_gpregret_set(0,0xB1);       
    APP_ERROR_CHECK(err_code);       
    
    sd_nvic_SystemReset();   
    

    In the bootloader you will have to modify the nrf_dfu_enter_check() in nrf_dfu.c to the following

    __WEAK bool nrf_dfu_enter_check(void)
    {    
         if(NRF_POWER->GPREGRET == 0xB1)
         {
               //Reset GPREGRET register so bootloader mode is not triggered when the device resets.
               NRF_POWER->GPREGRET = 0x00;       
               return true;   
         }       
    
         if (s_dfu_settings.enter_buttonless_dfu == 1)   
         {       
            s_dfu_settings.enter_buttonless_dfu = 0;       
            (void)nrf_dfu_settings_write(NULL);       
            return true;     
         }     
         return false;
    }
    

    Best regards

    Bjørn

Reply
  • Hi dblasco,

    if you want to enter bootloader mode from the application then you only have to write to one of the nRF52s GPREGRET registers(general purpose registers that are retained through a Soft Reset) and then check this register once you enter the bootloader on startup.

    Thus, you only need to call the following snippet in your application when you want to enter bootloader mode.

    err_code = sd_power_gpregret_set(0,0xB1);       
    APP_ERROR_CHECK(err_code);       
    
    sd_nvic_SystemReset();   
    

    In the bootloader you will have to modify the nrf_dfu_enter_check() in nrf_dfu.c to the following

    __WEAK bool nrf_dfu_enter_check(void)
    {    
         if(NRF_POWER->GPREGRET == 0xB1)
         {
               //Reset GPREGRET register so bootloader mode is not triggered when the device resets.
               NRF_POWER->GPREGRET = 0x00;       
               return true;   
         }       
    
         if (s_dfu_settings.enter_buttonless_dfu == 1)   
         {       
            s_dfu_settings.enter_buttonless_dfu = 0;       
            (void)nrf_dfu_settings_write(NULL);       
            return true;     
         }     
         return false;
    }
    

    Best regards

    Bjørn

Children
Related