I am currently trying to write a bootloader with the SAMD21 Xplained pro development kit by reading firmware from the EDBG UART and writing the firmware to the onboard SPI flash memory. I then use methods similar to the SAMD20 SPI master bootloader example project to load that file into memory. Through debugging, it seems as though I am writing the file into the NVM, but once I try to start the application from the application start address, the MCU seems to be doing nothing (or at least not running from the application start address).
I'm not completely sure how the below code works, and was hoping understanding that may give me some insight as to where my problem lies. I've also attached a picture of my debug window right before the last line of code is executed.
void (*application_code_entry)(void); /* Rebase the Stack Pointer */ __set_MSP(*(uint32_t *) APP_START_ADDRESS); /* Rebase the vector table base address */ SCB->VTOR = ((uint32_t) APP_START_ADDRESS & SCB_VTOR_TBLOFF_Msk); /* Load the Reset Handler address of the application */ application_code_entry = (void (*)(void))(unsigned *)(*(unsigned *)(APP_START_ADDRESS + (uint32_t)0x00000004)); /* Jump to user Reset Handler in the application */ application_code_entry();