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

Basic Bootloader nRF52832

Dear All,

I know similar questions have been asked before but I have read around quite a bit and I couldn't find an answer to my specific problem.

I have a ble application with softdevice which normally runs just fine. Now I would like to have some simple bootloader so that I can check at boot if a new firmware is available in an external flash. This is how my client wants it so there is no way out. Therefore I started testing with something simple.

I started with the iot_secure_dfu_bootloader and I stripped everything away until my main looked like this:

#include <stdint.h>
#include "boards.h"
#include "nrf_bootloader_info.h"
#include "nrf_bootloader_app_start.h"


void app_error_handler_bare(uint32_t error_code)
{
    (void)error_code;
    //NRF_LOG_ERROR("received an error: 0x%08x!\r\n", error_code);
    NVIC_SystemReset();
}

int main(void)
{
	while(1);
    nrf_bootloader_app_start();
}

where the while(1); can be commented or uncommented and serves as the simplest possible test of whether the bootloader is executing correctly or not. When I flash the bootloader directly from SEGGER Embedded Studio everything seems to work as expected (at least apparently), when the while(1); is there everything gets stuck, when I comment it out I can see my application start so that suggests that the control is going MBR->bootloader->softdevice->app.

However, if I then power-cycle the device the application always executes, even when I put an infinite loop in the bootloader, which makes me think that, after the power cycle, the bootloader is in fact not being executed and the control jumps straight to the application. What could the reason be?

Can anyone help me in setting up such simple bootloader? I have seen a lot of people on these forums struggling to get something simple like this to work, so I think it would be helpful for the community if we could document a clear and correct way to have a fully custom bootloader without DFU, encryption or anything of that sort.

Thank you very much.

Parents
  • Hi,

    The MBR checks if UICR.NRFFW[0] @ 0x10001014 contain a bootloader start address on startup, then if the address is valid the MBR will branch execution to this address. Can you verify that  UICR.NRFFW[0] holds the address to your bootloader? You can use the memory window in SES or the following nrfjprog command to check: nrfjprog --memrd 0x10001014. 

    where the while(1); can be commented or uncommented and serves as the simplest possible test of whether the bootloader is executing correctly or not. When I flash the bootloader directly from SEGGER Embedded Studio everything seems to work as expected (at least apparently), when the while(1); is there everything gets stuck, when I comment it out I can see my application start so that suggests that the control is going MBR->bootloader->softdevice->app.

    Maybe it's something with the debugger configuration. SES does for instance set the VTOR  register to the start address of the project you're building unless you build with  "NO_VTOR_CONFIG"

  • One question though. When writing to  UICR.NRFFW[0] (while using segger) should I take care of erasing the flash location to make sure it can be properly written or is it performed "quietly" by the programmer tools?

    Should I then actively write the bootloader address in the MBR at runtime?

Reply Children
  • The programming tool (nrfjprog/Jlink commander/ IDE) should give a warning or an error if the UICR.NRFFW[0] is not erased before you write to it. The verify operation should also detect if the register was not properly set, provided the value+address is included as a part of the hex file.

    vittopascu said:
    Should I then actively write the bootloader address in the MBR at runtime?

    It's not required to write the address to MBR if you use UICR.NRFFW[0].  MBR will check both locations for a BL start address on boot. 

Related