DFU: fix transitions between runtime and DFU mode
we now always go through a processor reset to avoid any state that might
be persistent/left-over during the switch.
diff --git a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu.h b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu.h
index b49cce0..dd0e5e2 100644
--- a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu.h
+++ b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu.h
@@ -86,12 +86,11 @@
/* magic value we use during boot to detect if we should start in DFU
* mode or runtime mode */
#define USB_DFU_MAGIC 0xDFDFDFDF
-/* RAM address for this magic value above */
-#define USB_DFU_MAGIC_ADDR IRAM_ADDR
/* The API between the core DFU handler and the board/soc specific code */
struct dfudata {
+ uint32_t magic;
uint8_t status;
uint32_t state;
int past_manifest;
diff --git a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c
index f5e7c82..16e07d3 100644
--- a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c
+++ b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c
@@ -457,7 +457,7 @@
void USBDFU_SwitchToApp(void)
{
/* make sure the MAGIC is not set to enter DFU again */
- *(unsigned int *)USB_DFU_MAGIC_ADDR = 0;
+ g_dfu->magic = 0;
printf("switching to app\r\n");
@@ -468,7 +468,6 @@
__disable_irq();
/* Tell the hybrid to execute FTL JUMP! */
- //BootIntoApp();
NVIC_SystemReset();
}
diff --git a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c
index ba9665e..b71a572 100644
--- a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c
+++ b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c
@@ -178,15 +178,17 @@
void DFURT_SwitchToDFU(void)
{
- unsigned int *dfu_except_tbl = (unsigned int *)IFLASH_ADDR;
- void (*toDFU)(void) = (void *)dfu_except_tbl[1];
+ /* store the magic value that the DFU loader can detect and
+ * activate itself, rather than boot into the application */
+ g_dfu->magic = USB_DFU_MAGIC;
- *(unsigned int *)USB_DFU_MAGIC_ADDR = USB_DFU_MAGIC;
-
+ /* Disconnect the USB by remoting the pull-up */
USBD_Disconnect();
__disable_irq();
- toDFU();
+ /* reset the processor, we will start execution with the
+ * ResetVector of the bootloader */
+ NVIC_SystemReset();
}
void USBDCallbacks_RequestReceived(const USBGenericRequest *request)