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.
This commit is contained in:
Harald Welte
2017-03-03 00:34:17 +01:00
parent db17e83960
commit d1e963479e
5 changed files with 27 additions and 13 deletions

View File

@@ -178,15 +178,17 @@ out:
void DFURT_SwitchToDFU(void)
{
unsigned int *dfu_except_tbl = (unsigned int *)IFLASH_ADDR;
void (*toDFU)(void) = (void *)dfu_except_tbl[1];
*(unsigned int *)USB_DFU_MAGIC_ADDR = USB_DFU_MAGIC;
/* 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;
/* 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)