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

How to set bootloader run first in my application?

Iprogram the bootloader.hex to 0x78000 with jlink.Then in my application program,I set the NRF_UICR->NRFFW[0] register as belew:

static void write_uicr_customer_register(uint32_t * data, uint32_t offset)
{
    uint32_t* cust_data = (uint32_t*)(NRF_UICR_BASE + offset);

    if(*cust_data != 0xFFFFFFFF)
    {
        NRF_NVMC->CONFIG = 2; //erase enable

        while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy

        NRF_NVMC->ERASEUICR = 1; //perform erase of UICR only

        while(NRF_NVMC->READY == NVMC_READY_READY_Busy || NRF_NVMC->ERASEUICR == 1);//busy

        while(*cust_data != 0xFFFFFFFF);
    }

    NRF_NVMC->CONFIG = 1; //write enabled

    while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy

    *cust_data = *data;

    while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy

    NRF_NVMC->CONFIG = 0; //read only

    while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy

    NVIC_SystemReset();
}

int main(void)
{
    uint32_t data = 0x00078000;
    system_module_init();

    // uicr_page_erase();
    LOG_INFO("smartrouter started!\r\n");
    LOG_INFO("main: %X\r\n", main);
    LOG_INFO("ADDR IS %X\r\n", &NRF_UICR->NRFFW[0]);
    LOG_INFO("BEFORE ADDR IS %X\r\n", NRF_UICR->NRFFW[0]);
    LOG_INFO("AFTER ADDR IS %X\r\n", NRF_UICR->NRFFW[0]);

    write_uicr_customer_register(&data, 0x14);

    for (;;)
    {
        // Wait for BLE events.
        // power_manage();
    }
}

I can readback that register is seated,but when restart, it do not goto the boot loader.Please give me a hand,Thank you very much!

  • Hi Sheep,

    Do you use our bootloader or your own bootloader? If you use our bootloader, the UICR is already written when flashing the bootloader (using attribute keyword) check nrf_bootloader_info.c . Could you try to test with the DFU bootloader included in the SDK ?

    I assume you used and flashed S132, do you have the version you use ? Have you made sure to disable the softdevice before you do NRF_NVMC activity ? it's blocked when the softdevice is active.

    When you reset and come back to the application could check and read UICR at offset 0x14, do you see anything ?

  • I use my own boot loader ,device is nrf52832 and S132,so when power on,it come to the app,I set the NRF_UICR->NRFFW[0] and then read back to check in the app program。When I power off and on,I wish it run boot loader first,but it doesn't come to my own boot loader.

  • I know it doesn't come to your bootloader, but you need to check if the value is still there when you restart.

    Note that the way it works is : MBR run first at reset handle address 0x00004. Then it check if there is anything at NRF_UICR->NRFFW[0] , if it's 0xFFFFFFF it will then forward to the softdevice, the softdevice then forward to normal application. If there is something in NRF_UICR->NRFFW[0] then the MBR will forward interrupt and PC to that address.

    What if you simply test to flash your application, softdevice, and then use nrfjprog and write to nRF_UICR->NRFFW[0] address 0x78000. If everything works as it should it should brick the code and your application shouldn't run after a reset after that.

    What do you do in your bootloader ?

Related