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

S132 and custom application start address

Hello, I would like to use a custom flash memory layout for the flash memory of nrf52:

image description

I thought that I should be able to use the UICR.NRFFW[0] - if I set to the start address of my application, SD should jump there (instead of bootloader, for which this register is usually used). However when I set the start address of my application to UICR.NRFFW[0] I end up in a hard-fault handler. Is there some other consideration that I should take into account when realizing this scenario? Is it supposed to work the way I imagine?

  • If the MBR detects that there is a bootloader or in this cas an application present ( if there is an address in the bootloader address location in UICR) it will not initialize the SoftFevice, but forward all interrupt to the bootloader and it is the bootloader that is responsible to initialize the softdevice or not.

    I dont know how you're writing the address to the UICR register, but I added the following snippet to the top of my main.

    #include "nrf_mbr.h"
    
    #define NRF_UICR_BOOTLOADER_START_ADDRESS       (NRF_UICR_BASE + 0x14)
    #define APP_START_ADDR                          0x20000
    
    #if defined (__CC_ARM )
        #pragma push
        #pragma diag_suppress 1296
        uint32_t  m_uicr_bootloader_start_address __attribute__((at(NRF_UICR_BOOTLOADER_START_ADDRESS)))
                                                        = APP_START_ADDR;
        #pragma pop
    #elif defined ( __GNUC__ )
        volatile uint32_t m_uicr_bootloader_start_address  __attribute__ ((section(".uicrBootStartAddress")))
                                                = BOOTLOADER_START_ADDR;
    #elif defined ( __ICCARM__ )
        __root    const uint32_t m_uicr_bootloader_start_address @ NRF_UICR_BOOTLOADER_START_ADDRESS
                                                = BOOTLOADER_START_ADDR;
    #endif
    

    Add this function before ble_stack_init()

    uint32_t nrf_dfu_mbr_init_sd(void)
    {
        uint32_t ret_val;
    
        sd_mbr_command_t command =
        {
            .command = SD_MBR_COMMAND_INIT_SD
        };
    
        ret_val = sd_mbr_command(&command);
    
        return ret_val;
    }
    

    and add the following code snippet in ble_stack_init() before the SOFTDEVICE_HANDLER_INIT macro

    err_code = nrf_dfu_mbr_init_sd();
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_softdevice_vector_table_base_set(APP_START_ADDR);
    APP_ERROR_CHECK(err_code);
    
Related