From 61739ec34d060a208db9506d5a8d94ad7059c7c5 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 8 Jan 2012 18:24:32 +0100 Subject: DFU: include code to switch from DFU to RUNTUIME after bus reset / mannifest --- usb/device/core/USBD_UDPHS.c | 6 ++++++ usb/device/dfu/dfu.h | 3 +++ usb/device/dfu/dfu_driver.c | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/usb/device/core/USBD_UDPHS.c b/usb/device/core/USBD_UDPHS.c index f02fa55..4ea6d1a 100644 --- a/usb/device/core/USBD_UDPHS.c +++ b/usb/device/core/USBD_UDPHS.c @@ -41,6 +41,7 @@ #include #include #include +#include #include @@ -1119,6 +1120,11 @@ void USBD_IrqHandler(void) // TRACE_DEBUG_WP("EoB "); +#if defined(BOARD_USB_DFU) && !defined(dfu) + if (g_dfu.past_manifest) + USBDFU_SwitchToApp(); +#endif + // The device enters the Default state deviceState = USBD_STATE_DEFAULT; // MCK + UDPCK are already enabled diff --git a/usb/device/dfu/dfu.h b/usb/device/dfu/dfu.h index eec956b..52b4ea5 100644 --- a/usb/device/dfu/dfu.h +++ b/usb/device/dfu/dfu.h @@ -139,6 +139,9 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request); void USBDFU_Initialize(const USBDDriverDescriptors *pDescriptors); +/* USBD tells us to switch from DFU mode to application mode */ +void USBDFU_SwitchToApp(void); + #define DFU_RET_NOTHING 0 #define DFU_RET_ZLP 1 #define DFU_RET_STALL 2 diff --git a/usb/device/dfu/dfu_driver.c b/usb/device/dfu/dfu_driver.c index 832ccbb..c9a9f03 100644 --- a/usb/device/dfu/dfu_driver.c +++ b/usb/device/dfu/dfu_driver.c @@ -22,6 +22,9 @@ #include +#include +#include + #include #include @@ -462,3 +465,19 @@ void USBDFU_Initialize(const USBDDriverDescriptors *pDescriptors) USBD_Init(); } + +void USBDFU_SwitchToApp(void) +{ + /* make sure the MAGIC is not set to enter DFU again */ + *(unsigned int *)USB_DFU_MAGIC_ADDR = 0; + + /* disconnect from USB to ensure re-enumeration */ + USBD_Disconnect(); + + /* disable any interrupts during transition */ + __disable_irq(); + + /* Tell the hybrid to execute FTL JUMP! */ + //BootIntoApp(); + RSTC_ProcessorReset(); +} -- cgit v1.2.3