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

How to make it run application when there is a bootloader in the nRF52

Hi,

I'm using the bootloader in nRF5_SDK V12.0 with nRF52832. I have some problems want to know:

  1. How to make it run application first after I program softdevice,bootloader and application? I found that it runs the bootloader and broadcast as "DfuTarg". I know it can set m_boot_settings in nRF5_SDK V11.

  2. After I finish the OTA, it can run the application. However, if I just do a little modification in my application and then program it, it would neve run the application,it runs the bootloader. Is it normal?

  3. I want to use AT command received by the UART to make it switch to bootloader instead of using a button. I do that like this: In my application,when received the AT command, I will write a value to the flash(the last page in the flash) using fstorage then do a reset. In the bootloader, I add some code to read the flash to check the value. So my question is I should use the fstorage or do it like flashwrite example in SDK? Which way would you suggest? Thanks.

  • Hi Alice,

    1. You have to generate the bootloader settings page that sets the application crc and the bank 0 status flag to NRF_DFU_BANK_VALID_APP, see this page in the nrfutil documentation.
    2. The bootloader will check the CRC of the application against the application CRC stored in the bootloader settings page. If you flash a new application to your device, then the CRCs will not match. Thus, you have to update the bootloader settings page that corresponds to your new application.
    3. If you're only writing one value to flash then I suggest that you use the SoftDevice Flash API, see sd_flash_write documentation in the S132 SoftDevice API documentation.

    Best regards

    Bjørn

  • @Bjørn Thanks.

    Do you mean that I just need to use the application.hex to generate the bootloader settings page? I do it as follow. Could the version number defined freely by me? nrfutil settings generate --family NRF52 --application nrf52832_1130.hex --application-version 3 --bootloader-version 2 --bl-settings-version 1 setting_1130.hex

    Could I merge setting.hex,softdevice and bootloader to one file and then flash it to my device? I have tried it but it just run the bootloader.

    I found another way to switch bootloader just now. That is use the GPREGRET register because it can retain it's value after a soft-reset. But I also meet a problem, when I receive the AT command and then I just wirte one byte value to the GPREGRET register, the chip will reset. I donn't know why. Does this way be better than write a value to flash?

    1. Yes, you can and should combine them into one file and then flash it to you board.
    2. Yes, you should be able to set the application version in the bootloader settings freely. Just keep in mind that the next time you create an application image then the application version number must be greater than the one in bootloader settings, please see "Acceptance rules for versions" on this Infocenter page
    3. Yes, you a right, the GPREGRET register is more suited for this. Are you writing to the GPREGRET or GPREGRET2?
  • I combine them into one file and then flash it to my board,but it just run the bootloader. What problem do you think? Both GPREGRET and GPREGRET2, I have tried it.

  • Can you readout the bootloader settings page using the following nrjprog command

    nrfjprog -f nrf52 --memrd 0x7F000 --n 256 >> bootloader_setings_hexdump.txt
    

    and attach it to the question. Could you also try to debug the bootloader and see if it enters the

     if(enter_bootloader_mode != 0 || !nrf_dfu_app_is_valid())
    

    or the

    if (nrf_dfu_app_is_valid()) 
    

    statment in nrf_dfu_init() in nrf_dfu.c?

    It could be that writing to the GPREGRET registers when the SoftDevice is enabled will trigger a Hardfault, i.e. a Reset. I will look into this.

Related