forked from stm/stm32-mw-usb-device
Release v2.11.2
This commit is contained in:
@@ -65,6 +65,8 @@ extern "C" {
|
||||
|
||||
#define DFU_DESCRIPTOR_TYPE 0x21U
|
||||
|
||||
#define DFU_VENDOR_CMD_MAX 32U
|
||||
|
||||
|
||||
/**************************************************/
|
||||
/* DFU Requests DFU states */
|
||||
@@ -126,6 +128,11 @@ extern "C" {
|
||||
#define DFU_MANIFEST_MASK (1U << 2)
|
||||
#define DFU_STATUS_DEPTH 6U
|
||||
|
||||
#define IS_DFU_DOWNLOAD 0x0DFDFU
|
||||
#define IS_DFU_UPLOAD 0x1DFDFU
|
||||
#define IS_DFU_SETADDRESSPOINTER 0x2DFDFU
|
||||
#define IS_DFU_PHY_ADDRESS 0x3DFDFU
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DFU_DETACH = 0U,
|
||||
@@ -176,6 +183,7 @@ typedef struct
|
||||
uint32_t wblock_num;
|
||||
uint32_t wlength;
|
||||
uint32_t data_ptr;
|
||||
uint32_t app_addr_ptr;
|
||||
uint32_t alt_setting;
|
||||
|
||||
uint8_t dev_status[DFU_STATUS_DEPTH];
|
||||
@@ -193,6 +201,17 @@ typedef struct
|
||||
uint16_t (* Write)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||
uint8_t *(* Read)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||
uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
uint16_t (* GetVendorCMD)(uint8_t *cmd, uint8_t *cmdlength);
|
||||
uint16_t (* VendorDownloadCMD)(uint8_t *pbuf, uint32_t BlockNumber, uint32_t wlength, uint32_t *status);
|
||||
uint16_t (* VendorUploadCMD)(uint32_t Add, uint32_t BlockNumber, uint32_t *status);
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||
uint16_t (* VendorCheck)(uint8_t *pbuf, uint32_t ReqType, uint32_t *status);
|
||||
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||
uint16_t (* LeaveDFU)(uint32_t Add);
|
||||
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||
} USBD_DFU_MediaTypeDef;
|
||||
|
||||
typedef struct
|
||||
|
||||
@@ -521,9 +521,13 @@ static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_SetupReqTypedef req;
|
||||
uint32_t app_addr_ptr;
|
||||
uint32_t addr;
|
||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
uint32_t VendorStatus = 0U;
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
|
||||
if (hdfu == NULL)
|
||||
{
|
||||
@@ -541,11 +545,43 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
else
|
||||
{
|
||||
/* Vendor specific DFU CMD */
|
||||
if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num,
|
||||
hdfu->wlength, &VendorStatus) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
}
|
||||
else if (hdfu->wlength == 5U)
|
||||
{
|
||||
if (hdfu->buffer.d8[0] == DFU_CMD_SETADDRESSPOINTER)
|
||||
{
|
||||
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_SETADDRESSPOINTER, &VendorStatus) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||
|
||||
hdfu->data_ptr = hdfu->buffer.d8[1];
|
||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
|
||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
|
||||
@@ -553,20 +589,61 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
else if (hdfu->buffer.d8[0] == DFU_CMD_ERASE)
|
||||
{
|
||||
hdfu->data_ptr = hdfu->buffer.d8[1];
|
||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
|
||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
|
||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[4] << 24;
|
||||
|
||||
if (DfuInterface->Erase(hdfu->data_ptr) != USBD_OK)
|
||||
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||
|
||||
app_addr_ptr = hdfu->buffer.d8[1];
|
||||
app_addr_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
|
||||
app_addr_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
|
||||
app_addr_ptr += (uint32_t)hdfu->buffer.d8[4] << 24;
|
||||
|
||||
if (DfuInterface->Erase(app_addr_ptr) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = DFU_ERROR_VENDOR;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
}
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
else
|
||||
{
|
||||
/* Vendor specific DFU CMD */
|
||||
if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num,
|
||||
hdfu->wlength, &VendorStatus) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
}
|
||||
#else
|
||||
else
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -584,12 +661,33 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
if (hdfu->wblock_num > 1U)
|
||||
{
|
||||
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||
|
||||
/* Decode the required address */
|
||||
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
|
||||
|
||||
/* Perform the write operation */
|
||||
if (DfuInterface->Write(hdfu->buffer.d8, (uint8_t *)addr, hdfu->wlength) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = DFU_ERROR_VENDOR;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
}
|
||||
@@ -670,7 +768,7 @@ static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t inde
|
||||
else
|
||||
{
|
||||
/* Not supported Interface Descriptor index */
|
||||
length = 0U;
|
||||
*length = 0U;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -758,6 +856,11 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||
uint32_t VendorStatus = 0U;
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
|
||||
if (hdfu == NULL)
|
||||
{
|
||||
return;
|
||||
@@ -789,15 +892,30 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
/* 0 Data DNLOAD request */
|
||||
else
|
||||
{
|
||||
/* End of DNLOAD operation*/
|
||||
/* End of DNLOAD operation */
|
||||
if ((hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) || (hdfu->dev_state == DFU_STATE_IDLE))
|
||||
{
|
||||
hdfu->manif_state = DFU_MANIFEST_IN_PROGRESS;
|
||||
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_SETADDRESSPOINTER, &VendorStatus) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
}
|
||||
else
|
||||
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||
{
|
||||
hdfu->manif_state = DFU_MANIFEST_IN_PROGRESS;
|
||||
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -820,6 +938,13 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||
uint8_t *phaddr;
|
||||
uint32_t addr;
|
||||
uint32_t CmdLength;
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
uint32_t VendorStatus = 0U;
|
||||
uint8_t VendorCmdLength = 0U;
|
||||
uint8_t VendorCmdBuffer[DFU_VENDOR_CMD_MAX];
|
||||
uint8_t idx;
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
|
||||
if (hdfu == NULL)
|
||||
{
|
||||
@@ -851,8 +976,24 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
hdfu->buffer.d8[1] = DFU_CMD_SETADDRESSPOINTER;
|
||||
hdfu->buffer.d8[2] = DFU_CMD_ERASE;
|
||||
|
||||
CmdLength = 3U;
|
||||
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
if (DfuInterface->GetVendorCMD != NULL)
|
||||
{
|
||||
(void)DfuInterface->GetVendorCMD(VendorCmdBuffer, (uint8_t *)&VendorCmdLength);
|
||||
|
||||
for (idx = 0U; idx < MIN(VendorCmdLength, DFU_VENDOR_CMD_MAX); idx++)
|
||||
{
|
||||
hdfu->buffer.d8[idx + 3U] = VendorCmdBuffer[idx];
|
||||
}
|
||||
|
||||
CmdLength += MIN(VendorCmdLength, DFU_VENDOR_CMD_MAX);
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
|
||||
/* Send the status data over EP0 */
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), 3U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), CmdLength);
|
||||
}
|
||||
else if (hdfu->wblock_num > 1U)
|
||||
{
|
||||
@@ -863,13 +1004,48 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
/* Vendor specific DFU CMD */
|
||||
if (DfuInterface->VendorUploadCMD(hdfu->data_ptr, hdfu->wblock_num, &VendorStatus) != USBD_OK)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_ERROR_STALLEDPKT;
|
||||
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
/* Return the physical address where data are stored */
|
||||
phaddr = DfuInterface->Read((uint8_t *)addr, hdfu->buffer.d8, hdfu->wlength);
|
||||
/* Call the error management function (command will be NAKed) */
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
|
||||
/* Send the status data over EP0 */
|
||||
(void)USBD_CtlSendData(pdev, phaddr, hdfu->wlength);
|
||||
if (VendorStatus == IS_DFU_PHY_ADDRESS)
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
{
|
||||
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
|
||||
|
||||
/* Return the physical address where data are stored */
|
||||
phaddr = DfuInterface->Read((uint8_t *)addr, hdfu->buffer.d8, hdfu->wlength);
|
||||
|
||||
if (phaddr == NULL)
|
||||
{
|
||||
hdfu->dev_state = DFU_ERROR_STALLEDPKT;
|
||||
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
/* Call the error management function (command will be NAKed) */
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Send the status data over EP0 */
|
||||
(void)USBD_CtlSendData(pdev, phaddr, hdfu->wlength);
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* unsupported hdfu->wblock_num */
|
||||
{
|
||||
@@ -880,7 +1056,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
/* Call the error management function (command will be NAKed */
|
||||
/* Call the error management function (command will be NAKed) */
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
}
|
||||
@@ -890,7 +1066,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
hdfu->wlength = 0U;
|
||||
hdfu->wblock_num = 0U;
|
||||
|
||||
/* Call the error management function (command will be NAKed */
|
||||
/* Call the error management function (command will be NAKed) */
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
}
|
||||
@@ -944,7 +1120,7 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
||||
DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status);
|
||||
}
|
||||
}
|
||||
else /* (hdfu->wlength==0)*/
|
||||
else /* (hdfu->wlength == 0U) */
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_DNLOAD_IDLE;
|
||||
|
||||
@@ -960,7 +1136,7 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_MANIFEST;
|
||||
|
||||
hdfu->dev_status[1] = 1U; /*bwPollTimeout = 1ms*/
|
||||
hdfu->dev_status[1] = 1U; /* bwPollTimeout = 1ms */
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
@@ -1088,9 +1264,10 @@ static void DFU_Abort(USBD_HandleTypeDef *pdev)
|
||||
static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||
USBD_DFUFuncDescTypeDef *pDfuFunc = (USBD_DFUFuncDescTypeDef *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
|
||||
|
||||
if ((hdfu == NULL) || (pDfuFunc == NULL))
|
||||
if ((hdfu == NULL) || (DfuInterface == NULL) || (pDfuFunc == NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1119,8 +1296,13 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
||||
/* Disconnect the USB device */
|
||||
(void)USBD_Stop(pdev);
|
||||
|
||||
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||
/* Jump should be ensured by user application */
|
||||
DfuInterface->LeaveDFU(hdfu->data_ptr);
|
||||
#else
|
||||
/* Generate system reset to allow jumping to the user code */
|
||||
NVIC_SystemReset();
|
||||
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||
|
||||
/* The next instructions will not be reached (system reset) */
|
||||
}
|
||||
|
||||
@@ -38,6 +38,17 @@ uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||
uint16_t MEM_If_DeInit(void);
|
||||
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer);
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
uint16_t MEM_If_GetVendorCMD(uint8_t *cmd, uint8_t *cmdlength);
|
||||
uint16_t MEM_If_VendorDownloadCMD(uint8_t *pbuf, uint32_t BlockNumber, uint32_t wlength, uint32_t *status);
|
||||
uint16_t MEM_If_VendorUploadCMD(uint32_t Add, uint32_t BlockNumber, uint32_t *status);
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||
uint16_t MEM_If_VendorCheck(uint8_t *pbuf, uint32_t ReqType, uint32_t *status);
|
||||
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||
uint16_t MEM_If_LeaveDFU(uint32_t Add);
|
||||
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||
|
||||
USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
||||
{
|
||||
@@ -48,8 +59,19 @@ USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
||||
MEM_If_Write,
|
||||
MEM_If_Read,
|
||||
MEM_If_GetStatus,
|
||||
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
MEM_If_GetVendorCMD,
|
||||
MEM_If_VendorDownloadCMD,
|
||||
MEM_If_VendorUploadCMD,
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||
MEM_If_VendorCheck,
|
||||
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||
MEM_If_LeaveDFU
|
||||
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief MEM_If_Init
|
||||
* Memory initialization routine.
|
||||
@@ -115,7 +137,7 @@ uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||
UNUSED(Len);
|
||||
|
||||
/* Return a valid address to avoid HardFault */
|
||||
return (uint8_t *)(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,3 +166,85 @@ uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||
/**
|
||||
* @brief Get supported vendor specific commands
|
||||
* @param pointer to supported vendor commands
|
||||
* @param pointer to length of supported vendor commands
|
||||
* @retval 0 if operation is successful
|
||||
*/
|
||||
uint16_t MEM_If_GetVendorCMD(uint8_t *cmd, uint8_t *cmdlength)
|
||||
{
|
||||
UNUSED(cmd);
|
||||
UNUSED(cmdlength);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Vendor specific download commands
|
||||
* @param pbuf DFU data buffer
|
||||
* @param BlockNumber DFU memory block number
|
||||
* @param wLength DFU request length
|
||||
* @param pointer to DFU status
|
||||
* @retval 0 if operation is successful
|
||||
*/
|
||||
uint16_t MEM_If_VendorDownloadCMD(uint8_t *pbuf, uint32_t BlockNumber, uint32_t wlength, uint32_t *status)
|
||||
{
|
||||
UNUSED(pbuf);
|
||||
UNUSED(BlockNumber);
|
||||
UNUSED(wlength);
|
||||
UNUSED(status);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Vendor specific upload commands
|
||||
* @param Add memory Address
|
||||
* @param BlockNumber DFU memory block number
|
||||
* @param pointer to DFU status
|
||||
* @retval 0 if operation is successful
|
||||
*/
|
||||
uint16_t MEM_If_VendorUploadCMD(uint32_t Add, uint32_t BlockNumber, uint32_t *status)
|
||||
{
|
||||
UNUSED(Add);
|
||||
UNUSED(BlockNumber);
|
||||
UNUSED(status);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||
|
||||
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||
/**
|
||||
* @brief Vendor memory check
|
||||
* @param pbuf DFU data buffer
|
||||
* @param ReqType IS_DFU_SETADDRESSPOINTER/DOWNLOAD/UPLOAD
|
||||
* @param pointer to DFU status
|
||||
* @retval 0 if operation is successful
|
||||
*/
|
||||
uint16_t MEM_If_VendorCheck(uint8_t *pbuf, uint32_t ReqType, uint32_t *status)
|
||||
{
|
||||
UNUSED(pbuf);
|
||||
UNUSED(ReqType);
|
||||
UNUSED(status);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||
|
||||
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||
/**
|
||||
* @brief Vendor Leave DFU
|
||||
* @param Application address
|
||||
* @retval 0 if operation is successful
|
||||
*/
|
||||
uint16_t MEM_If_LeaveDFU(uint32_t Add)
|
||||
{
|
||||
UNUSED(Add);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||
|
||||
Reference in New Issue
Block a user