Hi,
I've an issue when I try to jump between to Arduino application stored simultaneously in flash.
If the USB cable is plugged in the native port, the second application doesn't start. I think it is due to some USB registers not being reset, but I can't figure out which one(s).
here is the code to jump between application :
extern "C" {
#define APP_START_ADDRESS 0x10000
void jumpApplication() {
/* Pointer to the Application Section */
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 + 4));
/* Jump to user Reset Handler in the application */
application_code_entry();
}
}
it is called like this :
...
...
SPI.end();
dma.end();
//some kind of USB.end()...
//p763 of datasheet
USB->DEVICE.CTRLA.bit.ENABLE=0;
USB->DEVICE.CTRLB.bit.DETACH = 1;
USB->DEVICE.INTFLAG.bit.SUSPEND = 1;
digitalWrite(13, LOW);
jumpApplication();
Has anyone an idea how to solve this?