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

App does not start from bootloader

I'm trying to start my app from the bootloader, which is funcionally basically the same as the one in nRF5_SDK_11.0.0_89a8197.

To start the app I call bootloader_app_start(). In there the SD gets disabled, the vector table base is set to CODE_REGION_1_START and then bootloader_util_app_start(CODE_REGION_1_START) gets called. After that, nothing happens any more. As bootloader_util_app_start does not return, I don't get an error code or anything. I don't know how to proceed...

void bootloader_app_start(void)
{
	ERROR_CHECK(sd_softdevice_disable());
	disableInterrupts();
	ERROR_CHECK(sd_softdevice_vector_table_base_set(CODE_REGION_1_START));
    bootloader_util_app_start(CODE_REGION_1_START);
}

bootloader_util_app_start starts the following:

static inline void bootloader_util_reset(uint32_t start_addr)
{
    __asm volatile(
    "ldr   r0, [%0]\t\n"            // Get App initial MSP for bootloader.
    "msr   msp, r0\t\n"             // Set the main stack pointer to the applications MSP.
    "ldr   r0, [%0, #0x04]\t\n"     // Load Reset handler into R0.

    "movs  r4, #0xFF\t\n"           // Move ones to R4.
    "sxtb  r4, r4\t\n"              // Sign extend R4 to obtain 0xFFFFFFFF instead of 0xFF.

    "mrs   r5, IPSR\t\n"            // Load IPSR to R5 to check for handler or thread mode.
    "cmp   r5, #0x00\t\n"           // Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader.
    "bne   isr_abort\t\n"           // If not zero we need to exit current ISR and jump to reset handler of bootloader.

    "mov   lr, r4\t\n"              // Clear the link register and set to ones to ensure no return.
    "bx    r0\t\n"                  // Branch to reset handler of bootloader.

    "isr_abort:  \t\n"

    "mov   r5, r4\t\n"              // Fill with ones before jumping to reset handling. Will be popped as LR when exiting ISR. Ensures no return to application.
    "mov   r6, r0\t\n"              // Move address of reset handler to R6. Will be popped as PC when exiting ISR. Ensures the reset handler will be executed when exist ISR.
    "movs  r7, #0x21\t\n"           // Move MSB reset value of xPSR to R7. Will be popped as xPSR when exiting ISR. xPSR is 0x21000000 thus MSB is 0x21.
    "rev   r7, r7\t\n"              // Reverse byte order to put 0x21 as MSB.
    "push  {r4-r7}\t\n"             // Push everything to new stack to allow interrupt handler to fetch it on exiting the ISR.

    "movs  r4, #0x00\t\n"           // Fill with zeros before jumping to reset handling. We be popped as R0 when exiting ISR (Cleaning up of the registers).
    "movs  r5, #0x00\t\n"           // Fill with zeros before jumping to reset handling. We be popped as R1 when exiting ISR (Cleaning up of the registers).
    "movs  r6, #0x00\t\n"           // Fill with zeros before jumping to reset handling. We be popped as R2 when exiting ISR (Cleaning up of the registers).
    "movs  r7, #0x00\t\n"           // Fill with zeros before jumping to reset handling. We be popped as R3 when exiting ISR (Cleaning up of the registers).
    "push  {r4-r7}\t\n"             // Push zeros (R4-R7) to stack to prepare for exiting the interrupt routine.

    "movs  r0, #0xF9\t\n"           // Move the execution return command into register, 0xFFFFFFF9.
    "sxtb  r0, r0\t\n"              // Sign extend R0 to obtain 0xFFFFFFF9 instead of 0xF9.
    "bx    r0\t\n"                  // No return - Handler mode will be exited. Stack will be popped and execution will continue in reset handler initializing other application.
    ".align\t\n"
    :: "r" (start_addr)             // Argument list for the gcc assembly. start_addr is %0.
    :  "r0", "r4", "r5", "r6", "r7" // List of register maintained manually.
);
}

I'm working with an Eclipse makefile Project with Cross ARM GCC on a nRF52832 with s132_nrf52_2.0.0_softdevice.hex. The app binary is the output file from eclipse and was send to the µC with my own DFU-Service from my android app. It was validated on reception and after moving it from Bank 1 to Bank 0 with a crc. The image should therefore not be the problem, I hope.

I appreciate any help, thanks!

Related