/** * @brief DFU_LeaveDFUMode * Handles the sub-protocol DFU leave DFU mode request (leaves DFU mode * and resets device to jump to user loaded code). * @param pdev: device instance * @retval None */ void DFU_LeaveDFUMode(void *pdev) { Manifest_State = Manifest_complete; if ((usbd_dfu_CfgDesc[(11 + (9 * USBD_ITF_MAX_NUM))]) & 0x04) { DeviceState = STATE_dfuMANIFEST_SYNC; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; return; } else { DeviceState = STATE_dfuMANIFEST_WAIT_RESET; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /* Disconnect the USB device */ DCD_DevDisconnect (pdev); /* DeInitilialize the MAL(Media Access Layer) */ MAL_DeInit(); /* Generate system reset to allow jumping to the user code */ NVIC_SystemReset(); /* This instruction will not be reached (system reset) */ return; } }
void DFU_Check_Reset() { if (DFU_Reset_Count && !--DFU_Reset_Count) { /* DeInitilialize the MAL(Media Access Layer) */ MAL_DeInit(); /* Set system flags and generate system reset to allow jumping to the user code */ Finish_Update(); } }
/** * @brief usbd_dfu_Init * De-initializes the DFU layer. * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t usbd_dfu_DeInit (void *pdev, uint8_t cfgidx) { /* Restore default state */ DeviceState = STATE_dfuIDLE; DeviceStatus[4] = DeviceState; wBlockNum = 0; wlength = 0; /* DeInitilialize the MAL(Media Access Layer) */ MAL_DeInit(); return USBD_OK; }