forked from stm/stm32-mw-usb-device
Release v2.5.3
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USB_AUDIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -101,13 +101,13 @@
|
||||
/* Total size of the audio transfer buffer */
|
||||
#define AUDIO_TOTAL_BUF_SIZE ((uint16_t)(AUDIO_OUT_PACKET * AUDIO_OUT_PACKET_NUM))
|
||||
|
||||
/* Audio Commands enumeration */
|
||||
/* Audio Commands enumeration */
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_CMD_START = 1,
|
||||
AUDIO_CMD_PLAY,
|
||||
AUDIO_CMD_STOP,
|
||||
}AUDIO_CMD_TypeDef;
|
||||
} AUDIO_CMD_TypeDef;
|
||||
|
||||
|
||||
typedef enum
|
||||
@@ -126,12 +126,12 @@ AUDIO_OffsetTypeDef;
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmd;
|
||||
uint8_t data[USB_MAX_EP0_SIZE];
|
||||
uint8_t len;
|
||||
uint8_t unit;
|
||||
uint8_t cmd;
|
||||
uint8_t data[USB_MAX_EP0_SIZE];
|
||||
uint8_t len;
|
||||
uint8_t unit;
|
||||
}
|
||||
USBD_AUDIO_ControlTypeDef;
|
||||
|
||||
@@ -152,14 +152,14 @@ USBD_AUDIO_HandleTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int8_t (*Init) (uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||
int8_t (*DeInit) (uint32_t options);
|
||||
int8_t (*AudioCmd) (uint8_t* pbuf, uint32_t size, uint8_t cmd);
|
||||
int8_t (*VolumeCtl) (uint8_t vol);
|
||||
int8_t (*MuteCtl) (uint8_t cmd);
|
||||
int8_t (*PeriodicTC) (uint8_t cmd);
|
||||
int8_t (*GetState) (void);
|
||||
}USBD_AUDIO_ItfTypeDef;
|
||||
int8_t (*Init)(uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||
int8_t (*DeInit)(uint32_t options);
|
||||
int8_t (*AudioCmd)(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||
int8_t (*VolumeCtl)(uint8_t vol);
|
||||
int8_t (*MuteCtl)(uint8_t cmd);
|
||||
int8_t (*PeriodicTC)(uint8_t cmd);
|
||||
int8_t (*GetState)(void);
|
||||
} USBD_AUDIO_ItfTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -187,10 +187,10 @@ extern USBD_ClassTypeDef USBD_AUDIO;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops);
|
||||
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops);
|
||||
|
||||
void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
||||
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_AUDIO_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* ===================================================================
|
||||
* AUDIO Class Description
|
||||
* ===================================================================
|
||||
* This driver manages the Audio Class 1.0 following the "USB Device Class Definition for
|
||||
* This driver manages the Audio Class 1.0 following the "USB Device Class Definition for
|
||||
* Audio Devices V1.0 Mar 18, 98".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
@@ -48,16 +48,16 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_audio.h"
|
||||
@@ -93,7 +93,7 @@
|
||||
/** @defgroup USBD_AUDIO_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
|
||||
#define AUDIO_PACKET_SZE(frq) (uint8_t)(((frq * 2U * 2U)/1000U) & 0xFFU), \
|
||||
(uint8_t)((((frq * 2U * 2U)/1000U) >> 8) & 0xFFU)
|
||||
@@ -103,42 +103,26 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_AUDIO_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
|
||||
|
||||
static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length);
|
||||
|
||||
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length);
|
||||
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
/**
|
||||
@@ -316,7 +300,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
||||
} ;
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END=
|
||||
__ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
@@ -345,7 +329,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIE
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
|
||||
@@ -354,15 +338,15 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Allocate Audio structure */
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_AUDIO_HandleTypeDef));
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_AUDIO_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
haudio->alt_setting = 0U;
|
||||
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
||||
haudio->wr_ptr = 0U;
|
||||
@@ -381,6 +365,7 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, haudio->buffer,
|
||||
AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -391,18 +376,17 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_CloseEP(pdev, AUDIO_OUT_EP);
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0U);
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0U);
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
@@ -417,8 +401,8 @@ static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
uint16_t len;
|
||||
@@ -426,96 +410,96 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
uint16_t status_info = 0U;
|
||||
uint8_t ret = USBD_OK;
|
||||
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
AUDIO_REQ_GetCurrent(pdev, req);
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
AUDIO_REQ_GetCurrent(pdev, req);
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_SET_CUR:
|
||||
AUDIO_REQ_SetCurrent(pdev, req);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_SET_CUR:
|
||||
AUDIO_REQ_SetCurrent(pdev, req);
|
||||
break;
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if ((req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_AUDIO_CfgDesc + 18;
|
||||
len = MIN(USB_AUDIO_DESC_SIZ, req->wLength);
|
||||
|
||||
USBD_CtlSendData(pdev, pbuf, len);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&haudio->alt_setting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
haudio->alt_setting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if( (req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_AUDIO_CfgDesc + 18;
|
||||
len = MIN(USB_AUDIO_DESC_SIZ , req->wLength);
|
||||
|
||||
USBD_CtlSendData (pdev, pbuf, len);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&haudio->alt_setting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
haudio->alt_setting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -529,9 +513,10 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_AUDIO_CfgDesc);
|
||||
*length = sizeof(USBD_AUDIO_CfgDesc);
|
||||
|
||||
return USBD_AUDIO_CfgDesc;
|
||||
}
|
||||
|
||||
@@ -542,10 +527,8 @@ static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
/* Only OUT data are processed */
|
||||
return USBD_OK;
|
||||
}
|
||||
@@ -556,17 +539,18 @@ static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (haudio->control.cmd == AUDIO_REQ_SET_CUR)
|
||||
{/* In this driver, to simplify code, only SET_CUR request is managed */
|
||||
{
|
||||
/* In this driver, to simplify code, only SET_CUR request is managed */
|
||||
|
||||
if (haudio->control.unit == AUDIO_OUT_STREAMING_CTRL)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]);
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]);
|
||||
haudio->control.cmd = 0U;
|
||||
haudio->control.len = 0U;
|
||||
}
|
||||
@@ -580,7 +564,7 @@ static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Only OUT control data are processed */
|
||||
return USBD_OK;
|
||||
@@ -591,7 +575,7 @@ static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
@@ -602,15 +586,15 @@ static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
{
|
||||
uint32_t cmd = 0U;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
haudio->offset = offset;
|
||||
|
||||
if(haudio->rd_enable == 1U)
|
||||
if (haudio->rd_enable == 1U)
|
||||
{
|
||||
haudio->rd_ptr += (uint16_t)(AUDIO_TOTAL_BUF_SIZE / 2U);
|
||||
|
||||
@@ -621,15 +605,15 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
}
|
||||
}
|
||||
|
||||
if(haudio->rd_ptr > haudio->wr_ptr)
|
||||
if (haudio->rd_ptr > haudio->wr_ptr)
|
||||
{
|
||||
if((haudio->rd_ptr - haudio->wr_ptr) < AUDIO_OUT_PACKET)
|
||||
if ((haudio->rd_ptr - haudio->wr_ptr) < AUDIO_OUT_PACKET)
|
||||
{
|
||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((haudio->rd_ptr - haudio->wr_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||
if ((haudio->rd_ptr - haudio->wr_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||
{
|
||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U;
|
||||
}
|
||||
@@ -637,25 +621,25 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
}
|
||||
else
|
||||
{
|
||||
if((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET)
|
||||
if ((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET)
|
||||
{
|
||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||
if ((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||
{
|
||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(haudio->offset == AUDIO_OFFSET_FULL)
|
||||
if (haudio->offset == AUDIO_OFFSET_FULL)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||
cmd,
|
||||
AUDIO_CMD_PLAY);
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,9 +650,8 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
@@ -678,9 +661,8 @@ static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t ep
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
@@ -690,11 +672,10 @@ static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t e
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (epnum == AUDIO_OUT_EP)
|
||||
{
|
||||
@@ -707,16 +688,16 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
||||
/* All buffers are full: roll back */
|
||||
haudio->wr_ptr = 0U;
|
||||
|
||||
if(haudio->offset == AUDIO_OFFSET_UNKNOWN)
|
||||
if (haudio->offset == AUDIO_OFFSET_UNKNOWN)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||
AUDIO_TOTAL_BUF_SIZE / 2U,
|
||||
AUDIO_CMD_START);
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if(haudio->rd_enable == 0U)
|
||||
if (haudio->rd_enable == 0U)
|
||||
{
|
||||
if (haudio->wr_ptr == (AUDIO_TOTAL_BUF_SIZE / 2U))
|
||||
{
|
||||
@@ -742,12 +723,12 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
memset(haudio->control.data, 0, 64U);
|
||||
|
||||
/* Send the current mute state */
|
||||
USBD_CtlSendData (pdev, haudio->control.data, req->wLength);
|
||||
USBD_CtlSendData(pdev, haudio->control.data, req->wLength);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -760,14 +741,12 @@ static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (req->wLength)
|
||||
{
|
||||
/* Prepare the reception of the buffer over EP0 */
|
||||
USBD_CtlPrepareRx (pdev,
|
||||
haudio->control.data,
|
||||
req->wLength);
|
||||
USBD_CtlPrepareRx(pdev, haudio->control.data, req->wLength);
|
||||
|
||||
haudio->control.cmd = AUDIO_REQ_SET_CUR; /* Set the request value */
|
||||
haudio->control.len = (uint8_t)req->wLength; /* Set the request data length */
|
||||
@@ -782,9 +761,10 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length)
|
||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_AUDIO_DeviceQualifierDesc);
|
||||
*length = sizeof(USBD_AUDIO_DeviceQualifierDesc);
|
||||
|
||||
return USBD_AUDIO_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -793,13 +773,14 @@ static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length)
|
||||
* @param fops: Audio interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops)
|
||||
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops)
|
||||
{
|
||||
if(fops != NULL)
|
||||
if (fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
pdev->pUserData = fops;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_audio_if_template.h"
|
||||
@@ -65,13 +65,13 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
static int8_t TEMPLATE_Init (uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||
static int8_t TEMPLATE_DeInit (uint32_t options);
|
||||
static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd);
|
||||
static int8_t TEMPLATE_VolumeCtl (uint8_t vol);
|
||||
static int8_t TEMPLATE_MuteCtl (uint8_t cmd);
|
||||
static int8_t TEMPLATE_PeriodicTC (uint8_t cmd);
|
||||
static int8_t TEMPLATE_GetState (void);
|
||||
static int8_t TEMPLATE_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||
static int8_t TEMPLATE_DeInit(uint32_t options);
|
||||
static int8_t TEMPLATE_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||
static int8_t TEMPLATE_VolumeCtl(uint8_t vol);
|
||||
static int8_t TEMPLATE_MuteCtl(uint8_t cmd);
|
||||
static int8_t TEMPLATE_PeriodicTC(uint8_t cmd);
|
||||
static int8_t TEMPLATE_GetState(void);
|
||||
|
||||
USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
||||
{
|
||||
@@ -123,9 +123,8 @@ static int8_t TEMPLATE_DeInit(uint32_t options)
|
||||
* @param cmd: command opcode
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd)
|
||||
static int8_t TEMPLATE_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -134,9 +133,8 @@ static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd)
|
||||
* @param vol: volume level (0..100)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_VolumeCtl (uint8_t vol)
|
||||
static int8_t TEMPLATE_VolumeCtl(uint8_t vol)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -145,9 +143,8 @@ static int8_t TEMPLATE_VolumeCtl (uint8_t vol)
|
||||
* @param cmd: vmute command
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_MuteCtl (uint8_t cmd)
|
||||
static int8_t TEMPLATE_MuteCtl(uint8_t cmd)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -156,9 +153,8 @@ static int8_t TEMPLATE_MuteCtl (uint8_t cmd)
|
||||
* @param cmd
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_PeriodicTC (uint8_t cmd)
|
||||
static int8_t TEMPLATE_PeriodicTC(uint8_t cmd)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -167,9 +163,8 @@ static int8_t TEMPLATE_PeriodicTC (uint8_t cmd)
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_GetState (void)
|
||||
static int8_t TEMPLATE_GetState(void)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USB_CDC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -46,11 +46,11 @@
|
||||
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
||||
|
||||
#ifndef CDC_HS_BINTERVAL
|
||||
#define CDC_HS_BINTERVAL 0x10U
|
||||
#define CDC_HS_BINTERVAL 0x10U
|
||||
#endif /* CDC_HS_BINTERVAL */
|
||||
|
||||
#ifndef CDC_FS_BINTERVAL
|
||||
#define CDC_FS_BINTERVAL 0x10U
|
||||
#define CDC_FS_BINTERVAL 0x10U
|
||||
#endif /* CDC_FS_BINTERVAL */
|
||||
|
||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||
@@ -96,16 +96,16 @@ typedef struct
|
||||
uint8_t format;
|
||||
uint8_t paritytype;
|
||||
uint8_t datatype;
|
||||
}USBD_CDC_LineCodingTypeDef;
|
||||
} USBD_CDC_LineCodingTypeDef;
|
||||
|
||||
typedef struct _USBD_CDC_Itf
|
||||
{
|
||||
int8_t (* Init) (void);
|
||||
int8_t (* DeInit) (void);
|
||||
int8_t (* Control) (uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
||||
int8_t (* Receive) (uint8_t* Buf, uint32_t *Len);
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||
|
||||
}USBD_CDC_ItfTypeDef;
|
||||
} USBD_CDC_ItfTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
@@ -146,19 +146,19 @@ extern USBD_ClassTypeDef USBD_CDC;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops);
|
||||
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops);
|
||||
|
||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length);
|
||||
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length);
|
||||
|
||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff);
|
||||
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff);
|
||||
|
||||
uint8_t USBD_CDC_ReceivePacket (USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CDC_TransmitPacket (USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_CDC_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
@@ -45,15 +45,15 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc.h"
|
||||
@@ -100,32 +100,32 @@
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev,
|
||||
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length);
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
@@ -414,7 +414,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIG
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
@@ -468,12 +468,12 @@ __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIG
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0U;
|
||||
USBD_CDC_HandleTypeDef *hcdc;
|
||||
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
||||
@@ -506,15 +506,15 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
ret = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
/* Init physical Interface components */
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
@@ -523,7 +523,7 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
hcdc->TxState = 0U;
|
||||
hcdc->RxState = 0U;
|
||||
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
||||
@@ -546,7 +546,7 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0U;
|
||||
|
||||
@@ -563,7 +563,7 @@ static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
USBD_free(pdev->pClassData);
|
||||
@@ -580,88 +580,88 @@ static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
uint8_t ifalt = 0U;
|
||||
uint16_t status_info = 0U;
|
||||
uint8_t ret = USBD_OK;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
if (req->wLength)
|
||||
{
|
||||
if (req->bmRequest & 0x80U)
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
if (req->wLength)
|
||||
{
|
||||
if (req->bmRequest & 0x80U)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t *)(void *)hcdc->data,
|
||||
req->wLength);
|
||||
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc->CmdOpCode = req->bRequest;
|
||||
hcdc->CmdLength = (uint8_t)req->wLength;
|
||||
|
||||
USBD_CtlPrepareRx(pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t *)(void *)hcdc->data,
|
||||
req->wLength);
|
||||
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc->CmdOpCode = req->bRequest;
|
||||
hcdc->CmdLength = (uint8_t)req->wLength;
|
||||
|
||||
USBD_CtlPrepareRx (pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t *)(void *)req, 0U);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
(uint8_t *)(void *)req, 0U);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
USBD_CtlSendData (pdev, &ifalt, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, &ifalt, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -674,20 +674,20 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||
PCD_HandleTypeDef *hpcd = pdev->pData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
||||
if ((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
||||
{
|
||||
/* Update the packet total length */
|
||||
pdev->ep_in[epnum].total_length = 0U;
|
||||
|
||||
/* Send ZLP */
|
||||
USBD_LL_Transmit (pdev, epnum, NULL, 0U);
|
||||
USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -708,16 +708,16 @@ static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
/* Get the received data length */
|
||||
hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum);
|
||||
hcdc->RxLength = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being
|
||||
NAKed till the end of the application Xfer */
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||
|
||||
@@ -735,16 +735,16 @@ static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||
if ((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
||||
(uint8_t *)(void *)hcdc->data,
|
||||
(uint16_t)hcdc->CmdLength);
|
||||
hcdc->CmdOpCode = 0xFFU;
|
||||
hcdc->CmdOpCode = 0xFFU;
|
||||
|
||||
}
|
||||
return USBD_OK;
|
||||
@@ -757,9 +757,9 @@ static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_CfgFSDesc);
|
||||
*length = sizeof(USBD_CDC_CfgFSDesc);
|
||||
return USBD_CDC_CfgFSDesc;
|
||||
}
|
||||
|
||||
@@ -770,9 +770,9 @@ static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_CfgHSDesc);
|
||||
*length = sizeof(USBD_CDC_CfgHSDesc);
|
||||
return USBD_CDC_CfgHSDesc;
|
||||
}
|
||||
|
||||
@@ -783,9 +783,9 @@ static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_OtherSpeedCfgDesc);
|
||||
*length = sizeof(USBD_CDC_OtherSpeedCfgDesc);
|
||||
return USBD_CDC_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
@@ -795,9 +795,9 @@ static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length)
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_DeviceQualifierDesc);
|
||||
*length = sizeof(USBD_CDC_DeviceQualifierDesc);
|
||||
return USBD_CDC_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -807,14 +807,14 @@ uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length)
|
||||
* @param fops: CD Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops)
|
||||
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops)
|
||||
{
|
||||
uint8_t ret = USBD_FAIL;
|
||||
|
||||
if(fops != NULL)
|
||||
if (fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
pdev->pUserData = fops;
|
||||
ret = USBD_OK;
|
||||
}
|
||||
|
||||
@@ -827,11 +827,11 @@ uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
* @param pbuff: Tx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length)
|
||||
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hcdc->TxBuffer = pbuff;
|
||||
hcdc->TxLength = length;
|
||||
@@ -846,10 +846,10 @@ uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
||||
* @param pbuff: Rx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff)
|
||||
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hcdc->RxBuffer = pbuff;
|
||||
|
||||
@@ -864,11 +864,11 @@ uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
||||
*/
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
if(hcdc->TxState == 0U)
|
||||
if (hcdc->TxState == 0U)
|
||||
{
|
||||
/* Tx Transfer in progress */
|
||||
hcdc->TxState = 1U;
|
||||
@@ -902,12 +902,12 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
/* Suspend or Resume USB Out process */
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc_if_template.h"
|
||||
@@ -64,10 +64,10 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
static int8_t TEMPLATE_Init (void);
|
||||
static int8_t TEMPLATE_DeInit (void);
|
||||
static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
||||
static int8_t TEMPLATE_Receive (uint8_t* pbuf, uint32_t *Len);
|
||||
static int8_t TEMPLATE_Init(void);
|
||||
static int8_t TEMPLATE_DeInit(void);
|
||||
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
static int8_t TEMPLATE_Receive(uint8_t *pbuf, uint32_t *Len);
|
||||
|
||||
USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
||||
{
|
||||
@@ -78,12 +78,12 @@ USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
||||
};
|
||||
|
||||
USBD_CDC_LineCodingTypeDef linecoding =
|
||||
{
|
||||
115200, /* baud rate*/
|
||||
0x00, /* stop bits-1*/
|
||||
0x00, /* parity - none*/
|
||||
0x08 /* nb. of bits 8*/
|
||||
};
|
||||
{
|
||||
115200, /* baud rate*/
|
||||
0x00, /* stop bits-1*/
|
||||
0x00, /* parity - none*/
|
||||
0x08 /* nb. of bits 8*/
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
@@ -124,62 +124,62 @@ static int8_t TEMPLATE_DeInit(void)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||
/* Add your code here */
|
||||
break;
|
||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SET_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
case CDC_SET_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_GET_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
case CDC_GET_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_CLEAR_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
case CDC_CLEAR_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SET_LINE_CODING:
|
||||
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\
|
||||
(pbuf[2] << 16) | (pbuf[3] << 24));
|
||||
linecoding.format = pbuf[4];
|
||||
linecoding.paritytype = pbuf[5];
|
||||
linecoding.datatype = pbuf[6];
|
||||
case CDC_SET_LINE_CODING:
|
||||
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \
|
||||
(pbuf[2] << 16) | (pbuf[3] << 24));
|
||||
linecoding.format = pbuf[4];
|
||||
linecoding.paritytype = pbuf[5];
|
||||
linecoding.datatype = pbuf[6];
|
||||
|
||||
/* Add your code here */
|
||||
break;
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_GET_LINE_CODING:
|
||||
pbuf[0] = (uint8_t)(linecoding.bitrate);
|
||||
pbuf[1] = (uint8_t)(linecoding.bitrate >> 8);
|
||||
pbuf[2] = (uint8_t)(linecoding.bitrate >> 16);
|
||||
pbuf[3] = (uint8_t)(linecoding.bitrate >> 24);
|
||||
pbuf[4] = linecoding.format;
|
||||
pbuf[5] = linecoding.paritytype;
|
||||
pbuf[6] = linecoding.datatype;
|
||||
case CDC_GET_LINE_CODING:
|
||||
pbuf[0] = (uint8_t)(linecoding.bitrate);
|
||||
pbuf[1] = (uint8_t)(linecoding.bitrate >> 8);
|
||||
pbuf[2] = (uint8_t)(linecoding.bitrate >> 16);
|
||||
pbuf[3] = (uint8_t)(linecoding.bitrate >> 24);
|
||||
pbuf[4] = linecoding.format;
|
||||
pbuf[5] = linecoding.paritytype;
|
||||
pbuf[6] = linecoding.datatype;
|
||||
|
||||
/* Add your code here */
|
||||
break;
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SET_CONTROL_LINE_STATE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
case CDC_SET_CONTROL_LINE_STATE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SEND_BREAK:
|
||||
/* Add your code here */
|
||||
break;
|
||||
case CDC_SEND_BREAK:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
@@ -201,7 +201,7 @@ static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_Receive (uint8_t* Buf, uint32_t *Len)
|
||||
static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len)
|
||||
{
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USB_CUSTOMHID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -51,18 +51,18 @@
|
||||
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
||||
|
||||
#ifndef CUSTOM_HID_HS_BINTERVAL
|
||||
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||
#endif /* CUSTOM_HID_HS_BINTERVAL */
|
||||
|
||||
#ifndef CUSTOM_HID_FS_BINTERVAL
|
||||
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||
#endif /* CUSTOM_HID_FS_BINTERVAL */
|
||||
|
||||
#ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE
|
||||
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
||||
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
||||
#endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */
|
||||
#ifndef USBD_CUSTOM_HID_REPORT_DESC_SIZE
|
||||
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
||||
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
||||
#endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */
|
||||
|
||||
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U
|
||||
@@ -94,11 +94,11 @@ CUSTOM_HID_StateTypeDef;
|
||||
typedef struct _USBD_CUSTOM_HID_Itf
|
||||
{
|
||||
uint8_t *pReport;
|
||||
int8_t (* Init) (void);
|
||||
int8_t (* DeInit) (void);
|
||||
int8_t (* OutEvent) (uint8_t event_idx, uint8_t state);
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* OutEvent)(uint8_t event_idx, uint8_t state);
|
||||
|
||||
}USBD_CUSTOM_HID_ItfTypeDef;
|
||||
} USBD_CUSTOM_HID_ItfTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -137,14 +137,14 @@ extern USBD_ClassTypeDef USBD_CUSTOM_HID;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len);
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len);
|
||||
|
||||
|
||||
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_CUSTOMHID_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
@@ -32,15 +32,15 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_customhid.h"
|
||||
@@ -85,27 +85,27 @@
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc (uint16_t *length);
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -181,13 +181,13 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DES
|
||||
CUSTOM_HID_FS_BINTERVAL, /*bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||
0x00,
|
||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
/* 41 */
|
||||
};
|
||||
|
||||
@@ -240,13 +240,13 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DES
|
||||
CUSTOM_HID_HS_BINTERVAL, /*bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||
0x00,
|
||||
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
/* 41 */
|
||||
};
|
||||
|
||||
@@ -299,13 +299,13 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CO
|
||||
CUSTOM_HID_FS_BINTERVAL, /*bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||
0x00,
|
||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
/* 41 */
|
||||
};
|
||||
|
||||
@@ -354,8 +354,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUA
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0U;
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
@@ -372,15 +372,15 @@ static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev,
|
||||
|
||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_CUSTOM_HID_HandleTypeDef));
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_CUSTOM_HID_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
ret = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef*) pdev->pClassData;
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hhid->state = CUSTOM_HID_IDLE;
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
@@ -400,8 +400,8 @@ static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev,
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
/* Close CUSTOM_HID EP IN */
|
||||
USBD_LL_CloseEP(pdev, CUSTOM_HID_EPIN_ADDR);
|
||||
@@ -412,7 +412,7 @@ static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev,
|
||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 0U;
|
||||
|
||||
/* FRee allocated memory */
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
USBD_free(pdev->pClassData);
|
||||
@@ -428,10 +428,10 @@ static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t len = 0U;
|
||||
uint8_t *pbuf = NULL;
|
||||
uint16_t status_info = 0U;
|
||||
@@ -439,105 +439,105 @@ static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case CUSTOM_HID_REQ_SET_PROTOCOL:
|
||||
hhid->Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_SET_IDLE:
|
||||
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_GET_IDLE:
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_SET_REPORT:
|
||||
hhid->IsReportAvailable = 1U;
|
||||
USBD_CtlPrepareRx (pdev, hhid->Report_buf, req->wLength);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
case CUSTOM_HID_REQ_SET_PROTOCOL:
|
||||
hhid->Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_SET_IDLE:
|
||||
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_GET_IDLE:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_SET_REPORT:
|
||||
hhid->IsReportAvailable = 1U;
|
||||
USBD_CtlPrepareRx(pdev, hhid->Report_buf, req->wLength);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if( req->wValue >> 8 == CUSTOM_HID_REPORT_DESC)
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE , req->wLength);
|
||||
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( req->wValue >> 8 == CUSTOM_HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_CUSTOM_HID_Desc;
|
||||
len = MIN(USB_CUSTOM_HID_DESC_SIZ , req->wLength);
|
||||
}
|
||||
}
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
USBD_CtlSendData (pdev, pbuf, len);
|
||||
break;
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if (req->wValue >> 8 == CUSTOM_HID_REPORT_DESC)
|
||||
{
|
||||
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength);
|
||||
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (req->wValue >> 8 == CUSTOM_HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_CUSTOM_HID_Desc;
|
||||
len = MIN(USB_CUSTOM_HID_DESC_SIZ, req->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
USBD_CtlSendData(pdev, pbuf, len);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -549,18 +549,18 @@ static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
* @param buff: pointer to report
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len)
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED )
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if(hhid->state == CUSTOM_HID_IDLE)
|
||||
if (hhid->state == CUSTOM_HID_IDLE)
|
||||
{
|
||||
hhid->state = CUSTOM_HID_BUSY;
|
||||
USBD_LL_Transmit (pdev, CUSTOM_HID_EPIN_ADDR, report, len);
|
||||
USBD_LL_Transmit(pdev, CUSTOM_HID_EPIN_ADDR, report, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -577,9 +577,9 @@ uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CUSTOM_HID_CfgFSDesc);
|
||||
*length = sizeof(USBD_CUSTOM_HID_CfgFSDesc);
|
||||
return USBD_CUSTOM_HID_CfgFSDesc;
|
||||
}
|
||||
|
||||
@@ -590,9 +590,9 @@ static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CUSTOM_HID_CfgHSDesc);
|
||||
*length = sizeof(USBD_CUSTOM_HID_CfgHSDesc);
|
||||
return USBD_CUSTOM_HID_CfgHSDesc;
|
||||
}
|
||||
|
||||
@@ -603,9 +603,9 @@ static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CUSTOM_HID_OtherSpeedCfgDesc);
|
||||
*length = sizeof(USBD_CUSTOM_HID_OtherSpeedCfgDesc);
|
||||
return USBD_CUSTOM_HID_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
@@ -616,8 +616,8 @@ static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||
be caused by a new transfer before the end of the previous transfer */
|
||||
@@ -633,16 +633,16 @@ static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev,
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
|
||||
hhid->Report_buf[1]);
|
||||
|
||||
USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR , hhid->Report_buf,
|
||||
USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||
|
||||
return USBD_OK;
|
||||
@@ -656,7 +656,7 @@ static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev,
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (hhid->IsReportAvailable == 1U)
|
||||
{
|
||||
@@ -674,9 +674,9 @@ static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc (uint16_t *length)
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CUSTOM_HID_DeviceQualifierDesc);
|
||||
*length = sizeof(USBD_CUSTOM_HID_DeviceQualifierDesc);
|
||||
return USBD_CUSTOM_HID_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -686,14 +686,14 @@ static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc (uint16_t *length)
|
||||
* @param fops: CUSTOMHID Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
||||
{
|
||||
uint8_t ret = USBD_FAIL;
|
||||
|
||||
if(fops != NULL)
|
||||
if (fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
pdev->pUserData = fops;
|
||||
ret = USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @file usbd_customhid_if_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief USB Device Custom HID interface file.
|
||||
* This template should be copied to the user folder, renamed and customized
|
||||
* This template should be copied to the user folder, renamed and customized
|
||||
* following user needs.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
@@ -14,15 +14,15 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_customhid_if_template.h"
|
||||
@@ -31,9 +31,9 @@
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
static int8_t TEMPLATE_CUSTOM_HID_Init (void);
|
||||
static int8_t TEMPLATE_CUSTOM_HID_DeInit (void);
|
||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent (uint8_t event_idx, uint8_t state);
|
||||
static int8_t TEMPLATE_CUSTOM_HID_Init(void);
|
||||
static int8_t TEMPLATE_CUSTOM_HID_DeInit(void);
|
||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state);
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
||||
{
|
||||
@@ -79,7 +79,7 @@ static int8_t TEMPLATE_CUSTOM_HID_DeInit(void)
|
||||
* @param state: event state
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent (uint8_t event_idx, uint8_t state)
|
||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state)
|
||||
{
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USB_DFU_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -121,7 +121,7 @@
|
||||
typedef enum
|
||||
{
|
||||
DFU_DETACH = 0U,
|
||||
DFU_DNLOAD ,
|
||||
DFU_DNLOAD,
|
||||
DFU_UPLOAD,
|
||||
DFU_GETSTATUS,
|
||||
DFU_CLRSTATUS,
|
||||
@@ -144,9 +144,9 @@ typedef void (*pFunction)(void);
|
||||
USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ \
|
||||
|
||||
#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\
|
||||
((uint8_t)(size >> 8)) /* XFERSIZEB1 */
|
||||
((uint8_t)((size) >> 8)) /* XFERSIZEB1 */
|
||||
|
||||
#define IS_PROTECTED_AREA(add) (uint8_t)(((add >= 0x08000000) && (add < (APP_DEFAULT_ADD)))? 1:0)
|
||||
#define IS_PROTECTED_AREA(add) (uint8_t)((((add) >= 0x08000000) && ((add) < (APP_DEFAULT_ADD)))? 1:0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -163,7 +163,7 @@ typedef struct
|
||||
{
|
||||
uint32_t d32[USBD_DFU_XFER_SIZE / 4U];
|
||||
uint8_t d8[USBD_DFU_XFER_SIZE];
|
||||
}buffer;
|
||||
} buffer;
|
||||
|
||||
uint32_t wblock_num;
|
||||
uint32_t wlength;
|
||||
@@ -179,12 +179,12 @@ USBD_DFU_HandleTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const uint8_t* pStrDesc;
|
||||
uint16_t (* Init) (void);
|
||||
uint16_t (* DeInit) (void);
|
||||
uint16_t (* Erase) (uint32_t Add);
|
||||
uint16_t (* Write) (uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||
uint8_t* (* Read) (uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||
const uint8_t *pStrDesc;
|
||||
uint16_t (* Init)(void);
|
||||
uint16_t (* DeInit)(void);
|
||||
uint16_t (* Erase)(uint32_t Add);
|
||||
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);
|
||||
}
|
||||
USBD_DFU_MediaTypeDef;
|
||||
@@ -215,8 +215,8 @@ extern USBD_ClassTypeDef USBD_DFU;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev,
|
||||
USBD_DFU_MediaTypeDef *fops);
|
||||
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
||||
USBD_DFU_MediaTypeDef *fops);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_DFU_MEDIA_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
@@ -42,15 +42,15 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_dfu.h"
|
||||
@@ -100,52 +100,52 @@
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_DFU_GetCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_DFU_GetDeviceQualifierDesc (uint16_t *length);
|
||||
static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
static uint8_t USBD_DFU_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_DFU_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_DFU_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_DFU_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_DFU_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_DFU_SOF (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_DFU_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_DFU_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_DFU_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_DFU_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
#if (USBD_SUPPORT_USER_STRING == 1U)
|
||||
static uint8_t* USBD_DFU_GetUsrStringDesc ( USBD_HandleTypeDef *pdev, uint8_t index , uint16_t *length);
|
||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||
static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||
#endif
|
||||
|
||||
static void DFU_Detach (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
static void DFU_Download (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
static void DFU_Upload (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
static void DFU_GetStatus (USBD_HandleTypeDef *pdev);
|
||||
static void DFU_GetStatus(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static void DFU_ClearStatus (USBD_HandleTypeDef *pdev);
|
||||
static void DFU_ClearStatus(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static void DFU_GetState (USBD_HandleTypeDef *pdev);
|
||||
static void DFU_GetState(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static void DFU_Abort (USBD_HandleTypeDef *pdev);
|
||||
static void DFU_Abort(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static void DFU_Leave (USBD_HandleTypeDef *pdev);
|
||||
static void DFU_Leave(USBD_HandleTypeDef *pdev);
|
||||
|
||||
|
||||
/**
|
||||
@@ -172,7 +172,7 @@ USBD_ClassTypeDef USBD_DFU =
|
||||
USBD_DFU_GetCfgDesc,
|
||||
USBD_DFU_GetCfgDesc,
|
||||
USBD_DFU_GetDeviceQualifierDesc,
|
||||
#if (USBD_SUPPORT_USER_STRING == 1U)
|
||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||
USBD_DFU_GetUsrStringDesc
|
||||
#endif
|
||||
};
|
||||
@@ -275,21 +275,21 @@ __ALIGN_BEGIN static uint8_t USBD_DFU_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
/* Allocate Audio structure */
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_DFU_HandleTypeDef));
|
||||
/* Allocate Audio structure */
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_DFU_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hdfu->alt_setting = 0U;
|
||||
hdfu->data_ptr = USBD_DFU_APP_DEFAULT_ADD;
|
||||
@@ -322,11 +322,11 @@ static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev,
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hdfu->wblock_num = 0U;
|
||||
hdfu->wlength = 0U;
|
||||
@@ -336,7 +336,7 @@ static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev,
|
||||
hdfu->dev_status[4] = DFU_STATE_IDLE;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
/* De-Initialize Hardware layer */
|
||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit();
|
||||
@@ -354,8 +354,8 @@ static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
uint8_t *pbuf = 0U;
|
||||
@@ -363,117 +363,117 @@ static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev,
|
||||
uint16_t status_info = 0U;
|
||||
uint8_t ret = USBD_OK;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case DFU_DNLOAD:
|
||||
DFU_Download(pdev, req);
|
||||
break;
|
||||
|
||||
case DFU_UPLOAD:
|
||||
DFU_Upload(pdev, req);
|
||||
break;
|
||||
|
||||
case DFU_GETSTATUS:
|
||||
DFU_GetStatus(pdev);
|
||||
break;
|
||||
|
||||
case DFU_CLRSTATUS:
|
||||
DFU_ClearStatus(pdev);
|
||||
break;
|
||||
|
||||
case DFU_GETSTATE:
|
||||
DFU_GetState(pdev);
|
||||
break;
|
||||
|
||||
case DFU_ABORT:
|
||||
DFU_Abort(pdev);
|
||||
break;
|
||||
|
||||
case DFU_DETACH:
|
||||
DFU_Detach(pdev, req);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case DFU_DNLOAD:
|
||||
DFU_Download(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if( (req->wValue >> 8) == DFU_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_DFU_CfgDesc + (9U * (USBD_DFU_MAX_ITF_NUM + 1U));
|
||||
len = MIN(USB_DFU_DESC_SIZ , req->wLength);
|
||||
}
|
||||
case DFU_UPLOAD:
|
||||
DFU_Upload(pdev, req);
|
||||
break;
|
||||
|
||||
USBD_CtlSendData (pdev, pbuf, len);
|
||||
break;
|
||||
case DFU_GETSTATUS:
|
||||
DFU_GetStatus(pdev);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hdfu->alt_setting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case DFU_CLRSTATUS:
|
||||
DFU_ClearStatus(pdev);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM)
|
||||
{
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hdfu->alt_setting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
case DFU_GETSTATE:
|
||||
DFU_GetState(pdev);
|
||||
break;
|
||||
|
||||
case DFU_ABORT:
|
||||
DFU_Abort(pdev);
|
||||
break;
|
||||
|
||||
case DFU_DETACH:
|
||||
DFU_Detach(pdev, req);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if ((req->wValue >> 8) == DFU_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_DFU_CfgDesc + (9U * (USBD_DFU_MAX_ITF_NUM + 1U));
|
||||
len = MIN(USB_DFU_DESC_SIZ, req->wLength);
|
||||
}
|
||||
|
||||
USBD_CtlSendData(pdev, pbuf, len);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hdfu->alt_setting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM)
|
||||
{
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hdfu->alt_setting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -487,9 +487,9 @@ static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_DFU_GetCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_DFU_CfgDesc);
|
||||
*length = sizeof(USBD_DFU_CfgDesc);
|
||||
return USBD_DFU_CfgDesc;
|
||||
}
|
||||
|
||||
@@ -500,8 +500,8 @@ static uint8_t *USBD_DFU_GetCfgDesc (uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_DFU_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -513,7 +513,7 @@ static uint8_t USBD_DFU_DataIn (USBD_HandleTypeDef *pdev,
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -524,13 +524,13 @@ static uint8_t USBD_DFU_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint32_t addr;
|
||||
USBD_SetupReqTypedef req;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
uint32_t addr;
|
||||
USBD_SetupReqTypedef req;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (hdfu->dev_state == DFU_STATE_DNLOAD_BUSY)
|
||||
{
|
||||
@@ -568,7 +568,7 @@ static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
/* Call the error management function (command will be nacked) */
|
||||
req.bmRequest = 0U;
|
||||
req.wLength = 1U;
|
||||
USBD_CtlError (pdev, &req);
|
||||
USBD_CtlError(pdev, &req);
|
||||
}
|
||||
}
|
||||
/* Regular Download Command */
|
||||
@@ -581,7 +581,7 @@ static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
|
||||
/* Preform the write operation */
|
||||
if (((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Write(hdfu->buffer.d8,
|
||||
(uint8_t *)addr, hdfu->wlength) != USBD_OK)
|
||||
(uint8_t *)addr, hdfu->wlength) != USBD_OK)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
@@ -618,7 +618,7 @@ static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_SOF (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -630,7 +630,7 @@ static uint8_t USBD_DFU_SOF (USBD_HandleTypeDef *pdev)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_DFU_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -642,7 +642,7 @@ static uint8_t USBD_DFU_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnu
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_DFU_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -654,8 +654,8 @@ static uint8_t USBD_DFU_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epn
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_DFU_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_DFU_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -667,9 +667,9 @@ static uint8_t USBD_DFU_DataOut (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_DFU_GetDeviceQualifierDesc (uint16_t *length)
|
||||
static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_DFU_DeviceQualifierDesc);
|
||||
*length = sizeof(USBD_DFU_DeviceQualifierDesc);
|
||||
return USBD_DFU_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -681,14 +681,14 @@ static uint8_t *USBD_DFU_GetDeviceQualifierDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to the descriptor table or NULL if the descriptor is not supported.
|
||||
*/
|
||||
#if (USBD_SUPPORT_USER_STRING == 1U)
|
||||
static uint8_t* USBD_DFU_GetUsrStringDesc (USBD_HandleTypeDef *pdev, uint8_t index , uint16_t *length)
|
||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||
static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length)
|
||||
{
|
||||
static uint8_t USBD_StrDesc[255];
|
||||
/* Check if the requested string interface is supported */
|
||||
if (index <= (USBD_IDX_INTERFACE_STR + USBD_DFU_MAX_ITF_NUM))
|
||||
{
|
||||
USBD_GetString ((uint8_t *)((USBD_DFU_MediaTypeDef *)pdev->pUserData)->pStrDesc, USBD_StrDesc, length);
|
||||
USBD_GetString((uint8_t *)((USBD_DFU_MediaTypeDef *)pdev->pUserData)->pStrDesc, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
/* Not supported Interface Descriptor index */
|
||||
@@ -704,12 +704,12 @@ static uint8_t* USBD_DFU_GetUsrStringDesc (USBD_HandleTypeDef *pdev, uint8_t ind
|
||||
* @param fops: storage callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev,
|
||||
USBD_DFU_MediaTypeDef *fops)
|
||||
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
||||
USBD_DFU_MediaTypeDef *fops)
|
||||
{
|
||||
if(fops != NULL)
|
||||
if (fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
pdev->pUserData = fops;
|
||||
}
|
||||
return 0U;
|
||||
}
|
||||
@@ -726,13 +726,13 @@ uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev,
|
||||
*/
|
||||
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (hdfu->dev_state == DFU_STATE_IDLE || hdfu->dev_state == DFU_STATE_DNLOAD_SYNC
|
||||
|| hdfu->dev_state == DFU_STATE_DNLOAD_IDLE || hdfu->dev_state == DFU_STATE_MANIFEST_SYNC
|
||||
|| hdfu->dev_state == DFU_STATE_UPLOAD_IDLE )
|
||||
|| hdfu->dev_state == DFU_STATE_UPLOAD_IDLE)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = DFU_STATE_IDLE;
|
||||
@@ -750,13 +750,13 @@ static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
if ((USBD_DFU_CfgDesc[12U + (9U * USBD_DFU_MAX_ITF_NUM)]) & DFU_DETACH_MASK)
|
||||
{
|
||||
/* Perform an Attach-Detach operation on USB bus */
|
||||
USBD_Stop (pdev);
|
||||
USBD_Start (pdev);
|
||||
USBD_Stop(pdev);
|
||||
USBD_Start(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Wait for the period of time specified in Detach request */
|
||||
USBD_Delay ((uint32_t)req->wValue);
|
||||
USBD_Delay((uint32_t)req->wValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,9 +769,9 @@ static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
*/
|
||||
static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
/* Data setup request */
|
||||
if (req->wLength > 0U)
|
||||
@@ -787,21 +787,21 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
/* Prepare the reception of the buffer over EP0 */
|
||||
USBD_CtlPrepareRx (pdev, (uint8_t*)hdfu->buffer.d8,
|
||||
(uint16_t)hdfu->wlength);
|
||||
USBD_CtlPrepareRx(pdev, (uint8_t *)hdfu->buffer.d8,
|
||||
(uint16_t)hdfu->wlength);
|
||||
}
|
||||
/* Unsupported state */
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
}
|
||||
/* 0 Data DNLOAD request */
|
||||
else
|
||||
{
|
||||
/* End of DNLOAD operation*/
|
||||
if (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE || hdfu->dev_state == DFU_STATE_IDLE )
|
||||
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;
|
||||
@@ -813,7 +813,7 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -827,9 +827,9 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
*/
|
||||
static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
uint8_t *phaddr = NULL;
|
||||
uint32_t addr = 0U;
|
||||
@@ -847,7 +847,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
if (hdfu->wblock_num == 0U)
|
||||
{
|
||||
/* Update the state machine */
|
||||
hdfu->dev_state = (hdfu->wlength > 3U)? DFU_STATE_IDLE:DFU_STATE_UPLOAD_IDLE;
|
||||
hdfu->dev_state = (hdfu->wlength > 3U) ? DFU_STATE_IDLE : DFU_STATE_UPLOAD_IDLE;
|
||||
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
@@ -860,7 +860,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
hdfu->buffer.d8[2] = DFU_CMD_ERASE;
|
||||
|
||||
/* Send the status data over EP0 */
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), 3U);
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), 3U);
|
||||
}
|
||||
else if (hdfu->wblock_num > 1U)
|
||||
{
|
||||
@@ -877,7 +877,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
phaddr = ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Read((uint8_t *)addr, hdfu->buffer.d8, hdfu->wlength);
|
||||
|
||||
/* Send the status data over EP0 */
|
||||
USBD_CtlSendData (pdev, phaddr, (uint16_t)hdfu->wlength);
|
||||
USBD_CtlSendData(pdev, phaddr, (uint16_t)hdfu->wlength);
|
||||
}
|
||||
else /* unsupported hdfu->wblock_num */
|
||||
{
|
||||
@@ -889,7 +889,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
}
|
||||
/* Unsupported state */
|
||||
@@ -898,7 +898,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 nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
}
|
||||
/* No Data setup request */
|
||||
@@ -921,73 +921,73 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
*/
|
||||
static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
switch (hdfu->dev_state)
|
||||
{
|
||||
case DFU_STATE_DNLOAD_SYNC:
|
||||
if (hdfu->wlength != 0U)
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_DNLOAD_BUSY;
|
||||
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
if ((hdfu->wblock_num == 0U) && (hdfu->buffer.d8[0] == DFU_CMD_ERASE))
|
||||
case DFU_STATE_DNLOAD_SYNC:
|
||||
if (hdfu->wlength != 0U)
|
||||
{
|
||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->GetStatus(hdfu->data_ptr, DFU_MEDIA_ERASE, hdfu->dev_status);
|
||||
hdfu->dev_state = DFU_STATE_DNLOAD_BUSY;
|
||||
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
if ((hdfu->wblock_num == 0U) && (hdfu->buffer.d8[0] == DFU_CMD_ERASE))
|
||||
{
|
||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->GetStatus(hdfu->data_ptr, DFU_MEDIA_ERASE, hdfu->dev_status);
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status);
|
||||
}
|
||||
}
|
||||
else
|
||||
else /* (hdfu->wlength==0)*/
|
||||
{
|
||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status);
|
||||
}
|
||||
}
|
||||
else /* (hdfu->wlength==0)*/
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_DNLOAD_IDLE;
|
||||
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
}
|
||||
break;
|
||||
|
||||
case DFU_STATE_MANIFEST_SYNC :
|
||||
if (hdfu->manif_state == DFU_MANIFEST_IN_PROGRESS)
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_MANIFEST;
|
||||
|
||||
hdfu->dev_status[1] = 1U; /*bwPollTimeout = 1ms*/
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) &&
|
||||
((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U))
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_IDLE;
|
||||
hdfu->dev_state = DFU_STATE_DNLOAD_IDLE;
|
||||
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
case DFU_STATE_MANIFEST_SYNC :
|
||||
if (hdfu->manif_state == DFU_MANIFEST_IN_PROGRESS)
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_MANIFEST;
|
||||
|
||||
hdfu->dev_status[1] = 1U; /*bwPollTimeout = 1ms*/
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) &&
|
||||
((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U))
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_IDLE;
|
||||
|
||||
hdfu->dev_status[1] = 0U;
|
||||
hdfu->dev_status[2] = 0U;
|
||||
hdfu->dev_status[3] = 0U;
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
/* Send the status data over EP0 */
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(&(hdfu->dev_status[0])), 6U);
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->dev_status[0])), 6U);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -998,9 +998,9 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (hdfu->dev_state == DFU_STATE_ERROR)
|
||||
{
|
||||
@@ -1013,7 +1013,8 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
|
||||
hdfu->dev_status[5] = 0U;/*iString*/
|
||||
}
|
||||
else
|
||||
{ /*State Error*/
|
||||
{
|
||||
/*State Error*/
|
||||
hdfu->dev_state = DFU_STATE_ERROR;
|
||||
hdfu->dev_status[0] = DFU_ERROR_UNKNOWN;/*bStatus*/
|
||||
hdfu->dev_status[1] = 0U;
|
||||
@@ -1032,12 +1033,12 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
static void DFU_GetState(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
/* Return the current state of the DFU interface */
|
||||
USBD_CtlSendData (pdev, &hdfu->dev_state, 1U);
|
||||
USBD_CtlSendData(pdev, &hdfu->dev_state, 1U);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1048,13 +1049,13 @@ static void DFU_GetState(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
static void DFU_Abort(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (hdfu->dev_state == DFU_STATE_IDLE || hdfu->dev_state == DFU_STATE_DNLOAD_SYNC
|
||||
|| hdfu->dev_state == DFU_STATE_DNLOAD_IDLE || hdfu->dev_state == DFU_STATE_MANIFEST_SYNC
|
||||
|| hdfu->dev_state == DFU_STATE_UPLOAD_IDLE )
|
||||
|| hdfu->dev_state == DFU_STATE_UPLOAD_IDLE)
|
||||
{
|
||||
hdfu->dev_state = DFU_STATE_IDLE;
|
||||
hdfu->dev_status[0] = DFU_ERROR_NONE;
|
||||
@@ -1077,11 +1078,11 @@ static void DFU_Abort(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
USBD_DFU_HandleTypeDef *hdfu;
|
||||
|
||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
||||
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hdfu->manif_state = DFU_MANIFEST_COMPLETE;
|
||||
hdfu->manif_state = DFU_MANIFEST_COMPLETE;
|
||||
|
||||
if ((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U)
|
||||
{
|
||||
@@ -1103,7 +1104,7 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
||||
hdfu->dev_status[4] = hdfu->dev_state;
|
||||
|
||||
/* Disconnect the USB device */
|
||||
USBD_Stop (pdev);
|
||||
USBD_Stop(pdev);
|
||||
|
||||
/* DeInitilialize the MAL(Media Access Layer) */
|
||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit();
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_dfu_media_template.h"
|
||||
@@ -34,21 +34,21 @@
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
uint16_t MEM_If_Init(void);
|
||||
uint16_t MEM_If_Erase (uint32_t Add);
|
||||
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_Erase(uint32_t Add);
|
||||
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);
|
||||
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer);
|
||||
|
||||
USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
||||
{
|
||||
(uint8_t *)"DFU MEDIA",
|
||||
MEM_If_Init,
|
||||
MEM_If_DeInit,
|
||||
MEM_If_Erase,
|
||||
MEM_If_Write,
|
||||
MEM_If_Read,
|
||||
MEM_If_GetStatus,
|
||||
(uint8_t *)"DFU MEDIA",
|
||||
MEM_If_Init,
|
||||
MEM_If_DeInit,
|
||||
MEM_If_Erase,
|
||||
MEM_If_Write,
|
||||
MEM_If_Read,
|
||||
MEM_If_GetStatus,
|
||||
|
||||
};
|
||||
/**
|
||||
@@ -103,10 +103,10 @@ uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||
* @param Len: Number of data to be read (in bytes).
|
||||
* @retval Pointer to the physical address where data should be read.
|
||||
*/
|
||||
uint8_t *MEM_If_Read (uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||
{
|
||||
/* Return a valid address to avoid HardFault */
|
||||
return (uint8_t*)(0);
|
||||
return (uint8_t *)(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,20 +116,20 @@ uint8_t *MEM_If_Read (uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||
* @param cmd: Number of data to be read (in bytes).
|
||||
* @retval Pointer to the physical address where data should be read.
|
||||
*/
|
||||
uint16_t MEM_If_GetStatus (uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
||||
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
||||
{
|
||||
switch (Cmd)
|
||||
{
|
||||
case DFU_MEDIA_PROGRAM:
|
||||
case DFU_MEDIA_PROGRAM:
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case DFU_MEDIA_ERASE:
|
||||
default:
|
||||
case DFU_MEDIA_ERASE:
|
||||
default:
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USB_HID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -52,11 +52,11 @@
|
||||
#define HID_REPORT_DESC 0x22U
|
||||
|
||||
#ifndef HID_HS_BINTERVAL
|
||||
#define HID_HS_BINTERVAL 0x07U
|
||||
#define HID_HS_BINTERVAL 0x07U
|
||||
#endif /* HID_HS_BINTERVAL */
|
||||
|
||||
#ifndef HID_FS_BINTERVAL
|
||||
#define HID_FS_BINTERVAL 0x0AU
|
||||
#define HID_FS_BINTERVAL 0x0AU
|
||||
#endif /* HID_FS_BINTERVAL */
|
||||
|
||||
#define HID_REQ_SET_PROTOCOL 0x0BU
|
||||
@@ -118,11 +118,11 @@ extern USBD_ClassTypeDef USBD_HID;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len);
|
||||
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len);
|
||||
|
||||
uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev);
|
||||
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -33,15 +33,15 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_hid.h"
|
||||
@@ -90,24 +90,24 @@
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_HID_GetHSCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc (uint16_t *length);
|
||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -380,13 +380,13 @@ __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] _
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE);
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_HID_HandleTypeDef));
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_HID_HandleTypeDef));
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
@@ -405,15 +405,15 @@ static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
/* Close HID EPs */
|
||||
USBD_LL_CloseEP(pdev, HID_EPIN_ADDR);
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||
|
||||
/* FRee allocated memory */
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
@@ -429,10 +429,10 @@ static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *) pdev->pClassData;
|
||||
uint16_t len = 0U;
|
||||
uint8_t *pbuf = NULL;
|
||||
uint16_t status_info = 0U;
|
||||
@@ -440,101 +440,101 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
hhid->Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
hhid->Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
||||
break;
|
||||
case HID_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
||||
break;
|
||||
|
||||
case HID_REQ_SET_IDLE:
|
||||
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
case HID_REQ_SET_IDLE:
|
||||
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_IDLE:
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
||||
break;
|
||||
case HID_REQ_GET_IDLE:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if(req->wValue >> 8 == HID_REPORT_DESC)
|
||||
{
|
||||
len = MIN(HID_MOUSE_REPORT_DESC_SIZE , req->wLength);
|
||||
pbuf = HID_MOUSE_ReportDesc;
|
||||
}
|
||||
else if(req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_HID_Desc;
|
||||
len = MIN(USB_HID_DESC_SIZ, req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
USBD_CtlSendData (pdev, pbuf, len);
|
||||
break;
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if (req->wValue >> 8 == HID_REPORT_DESC)
|
||||
{
|
||||
len = MIN(HID_MOUSE_REPORT_DESC_SIZE, req->wLength);
|
||||
pbuf = HID_MOUSE_ReportDesc;
|
||||
}
|
||||
else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_HID_Desc;
|
||||
len = MIN(USB_HID_DESC_SIZ, req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
USBD_CtlSendData(pdev, pbuf, len);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -547,21 +547,21 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
* @param buff: pointer to report
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len)
|
||||
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len)
|
||||
{
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED )
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if(hhid->state == HID_IDLE)
|
||||
if (hhid->state == HID_IDLE)
|
||||
{
|
||||
hhid->state = HID_BUSY;
|
||||
USBD_LL_Transmit (pdev,
|
||||
HID_EPIN_ADDR,
|
||||
report,
|
||||
len);
|
||||
USBD_LL_Transmit(pdev,
|
||||
HID_EPIN_ADDR,
|
||||
report,
|
||||
len);
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
@@ -573,17 +573,17 @@ uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
||||
* @param pdev: device instance
|
||||
* @retval polling interval
|
||||
*/
|
||||
uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev)
|
||||
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint32_t polling_interval = 0U;
|
||||
|
||||
/* HIGH-speed endpoints */
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Sets the data transfer polling interval for high speed transfers.
|
||||
Values between 1..16 are allowed. Values correspond to interval
|
||||
of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
|
||||
polling_interval = (((1U <<(HID_HS_BINTERVAL - 1U))) / 8U);
|
||||
/* Sets the data transfer polling interval for high speed transfers.
|
||||
Values between 1..16 are allowed. Values correspond to interval
|
||||
of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
|
||||
polling_interval = (((1U << (HID_HS_BINTERVAL - 1U))) / 8U);
|
||||
}
|
||||
else /* LOW and FULL-speed endpoints */
|
||||
{
|
||||
@@ -602,9 +602,9 @@ uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_HID_CfgFSDesc);
|
||||
*length = sizeof(USBD_HID_CfgFSDesc);
|
||||
return USBD_HID_CfgFSDesc;
|
||||
}
|
||||
|
||||
@@ -615,9 +615,9 @@ static uint8_t *USBD_HID_GetFSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetHSCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_HID_CfgHSDesc);
|
||||
*length = sizeof(USBD_HID_CfgHSDesc);
|
||||
return USBD_HID_CfgHSDesc;
|
||||
}
|
||||
|
||||
@@ -628,9 +628,9 @@ static uint8_t *USBD_HID_GetHSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_HID_OtherSpeedCfgDesc);
|
||||
*length = sizeof(USBD_HID_OtherSpeedCfgDesc);
|
||||
return USBD_HID_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
@@ -641,8 +641,8 @@ static uint8_t *USBD_HID_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
|
||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||
@@ -658,9 +658,9 @@ static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc (uint16_t *length)
|
||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_HID_DeviceQualifierDesc);
|
||||
*length = sizeof(USBD_HID_DeviceQualifierDesc);
|
||||
return USBD_HID_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_MSC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -68,16 +68,16 @@
|
||||
*/
|
||||
typedef struct _USBD_STORAGE
|
||||
{
|
||||
int8_t (* Init) (uint8_t lun);
|
||||
int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size);
|
||||
int8_t (* IsReady) (uint8_t lun);
|
||||
int8_t (* IsWriteProtected) (uint8_t lun);
|
||||
int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
||||
int8_t (* Init)(uint8_t lun);
|
||||
int8_t (* GetCapacity)(uint8_t lun, uint32_t *block_num, uint16_t *block_size);
|
||||
int8_t (* IsReady)(uint8_t lun);
|
||||
int8_t (* IsWriteProtected)(uint8_t lun);
|
||||
int8_t (* Read)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
||||
int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
||||
int8_t (* GetMaxLun)(void);
|
||||
int8_t *pInquiry;
|
||||
|
||||
}USBD_StorageTypeDef;
|
||||
} USBD_StorageTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
@@ -107,8 +107,8 @@ USBD_MSC_BOT_HandleTypeDef;
|
||||
extern USBD_ClassTypeDef USBD_MSC;
|
||||
#define USBD_MSC_CLASS &USBD_MSC
|
||||
|
||||
uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev,
|
||||
USBD_StorageTypeDef *fops);
|
||||
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev,
|
||||
USBD_StorageTypeDef *fops);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_MSC_BOT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -116,20 +116,20 @@ USBD_MSC_BOT_CSWTypeDef;
|
||||
/** @defgroup USBD_CORE_Exported_FunctionsPrototypes
|
||||
* @{
|
||||
*/
|
||||
void MSC_BOT_Init (USBD_HandleTypeDef *pdev);
|
||||
void MSC_BOT_Reset (USBD_HandleTypeDef *pdev);
|
||||
void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev);
|
||||
void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
||||
void MSC_BOT_Init(USBD_HandleTypeDef *pdev);
|
||||
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev);
|
||||
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev);
|
||||
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev,
|
||||
uint8_t CSW_Status);
|
||||
|
||||
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
||||
uint8_t CSW_Status);
|
||||
|
||||
void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_MSC_DATA_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_MSC_SCSI_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -126,14 +126,17 @@ extern uint8_t ReadFormatCapacity_Data [];
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct _SENSE_ITEM {
|
||||
typedef struct _SENSE_ITEM
|
||||
{
|
||||
char Skey;
|
||||
union {
|
||||
struct _ASCs {
|
||||
union
|
||||
{
|
||||
struct _ASCs
|
||||
{
|
||||
char ASC;
|
||||
char ASCQ;
|
||||
}b;
|
||||
uint8_t ASC;
|
||||
} b;
|
||||
uint8_t ASC;
|
||||
char *pData;
|
||||
} w;
|
||||
} USBD_SCSI_SenseTypeDef;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USBD_MSC_STORAGE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
@@ -27,16 +27,16 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_msc.h"
|
||||
@@ -80,30 +80,16 @@
|
||||
/** @defgroup MSC_CORE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
|
||||
uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length);
|
||||
|
||||
uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length);
|
||||
|
||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
|
||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length);
|
||||
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -179,9 +165,8 @@ __ALIGN_BEGIN uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
|
||||
/* USB Mass storage device Configuration Descriptor */
|
||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
||||
uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
__ALIGN_BEGIN uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_MSC_CONFIG_DESC_SIZ,
|
||||
@@ -223,7 +208,6 @@ uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
|
||||
__ALIGN_BEGIN uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
||||
USB_MSC_CONFIG_DESC_SIZ,
|
||||
@@ -293,9 +277,9 @@ __ALIGN_BEGIN uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC]
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
||||
@@ -315,9 +299,9 @@ uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_MSC_BOT_HandleTypeDef));
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_MSC_BOT_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
@@ -335,8 +319,8 @@ uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
/* Close MSC EPs */
|
||||
USBD_LL_CloseEP(pdev, MSC_EPOUT_ADDR);
|
||||
@@ -346,15 +330,16 @@ uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
USBD_LL_CloseEP(pdev, MSC_EPIN_ADDR);
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||
|
||||
/* De-Init the BOT layer */
|
||||
/* De-Init the BOT layer */
|
||||
MSC_BOT_DeInit(pdev);
|
||||
|
||||
/* Free MSC Class Resources */
|
||||
if(pdev->pClassData != NULL)
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
@@ -364,149 +349,148 @@ uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
* @param req: USB request
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
uint8_t ret = USBD_OK;
|
||||
uint16_t status_info = 0U;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
|
||||
/* Class request */
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case BOT_GET_MAX_LUN:
|
||||
if((req->wValue == 0U) && (req->wLength == 1U) &&
|
||||
((req->bmRequest & 0x80U) == 0x80U))
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun();
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hmsc->max_lun, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case BOT_GET_MAX_LUN:
|
||||
if ((req->wValue == 0U) && (req->wLength == 1U) &&
|
||||
((req->bmRequest & 0x80U) == 0x80U))
|
||||
{
|
||||
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun();
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hmsc->max_lun, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case BOT_RESET :
|
||||
if((req->wValue == 0U) && (req->wLength == 0U) &&
|
||||
((req->bmRequest & 0x80U) != 0x80U))
|
||||
{
|
||||
MSC_BOT_Reset(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case BOT_RESET :
|
||||
if ((req->wValue == 0U) && (req->wLength == 0U) &&
|
||||
((req->bmRequest & 0x80U) != 0x80U))
|
||||
{
|
||||
MSC_BOT_Reset(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
ret = USBD_FAIL;
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
/* Interface & Endpoint request */
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hmsc->interface, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hmsc->interface, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hmsc->interface = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hmsc->interface = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
|
||||
/* Flush the FIFO and Clear the stall status */
|
||||
USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
||||
/* Flush the FIFO and Clear the stall status */
|
||||
USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
||||
|
||||
/* Reactivate the EP */
|
||||
USBD_LL_CloseEP (pdev , (uint8_t)req->wIndex);
|
||||
if((((uint8_t)req->wIndex) & 0x80U) == 0x80U)
|
||||
{
|
||||
pdev->ep_in[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_HS_PACKET);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_FS_PACKET);
|
||||
}
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
/* Reactivate the EP */
|
||||
USBD_LL_CloseEP(pdev, (uint8_t)req->wIndex);
|
||||
if ((((uint8_t)req->wIndex) & 0x80U) == 0x80U)
|
||||
{
|
||||
pdev->ep_in[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_HS_PACKET);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_FS_PACKET);
|
||||
}
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
pdev->ep_out[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_HS_PACKET);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_FS_PACKET);
|
||||
}
|
||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
|
||||
/* Handle BOT error */
|
||||
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
pdev->ep_out[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_HS_PACKET);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_FS_PACKET);
|
||||
}
|
||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
|
||||
/* Handle BOT error */
|
||||
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -519,10 +503,10 @@ uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
MSC_BOT_DataIn(pdev , epnum);
|
||||
MSC_BOT_DataIn(pdev, epnum);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -533,10 +517,10 @@ uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev,
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
MSC_BOT_DataOut(pdev , epnum);
|
||||
MSC_BOT_DataOut(pdev, epnum);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -546,9 +530,10 @@ uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length)
|
||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_MSC_CfgHSDesc);
|
||||
*length = sizeof(USBD_MSC_CfgHSDesc);
|
||||
|
||||
return USBD_MSC_CfgHSDesc;
|
||||
}
|
||||
|
||||
@@ -558,9 +543,10 @@ uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length)
|
||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_MSC_CfgFSDesc);
|
||||
*length = sizeof(USBD_MSC_CfgFSDesc);
|
||||
|
||||
return USBD_MSC_CfgFSDesc;
|
||||
}
|
||||
|
||||
@@ -570,9 +556,10 @@ uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_MSC_OtherSpeedCfgDesc);
|
||||
*length = sizeof(USBD_MSC_OtherSpeedCfgDesc);
|
||||
|
||||
return USBD_MSC_OtherSpeedCfgDesc;
|
||||
}
|
||||
/**
|
||||
@@ -581,9 +568,10 @@ uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length)
|
||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_MSC_DeviceQualifierDesc);
|
||||
*length = sizeof(USBD_MSC_DeviceQualifierDesc);
|
||||
|
||||
return USBD_MSC_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -592,13 +580,14 @@ uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length)
|
||||
* @param fops: storage callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev,
|
||||
USBD_StorageTypeDef *fops)
|
||||
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev,
|
||||
USBD_StorageTypeDef *fops)
|
||||
{
|
||||
if(fops != NULL)
|
||||
if (fops != NULL)
|
||||
{
|
||||
pdev->pUserData = fops;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_msc_bot.h"
|
||||
@@ -76,10 +76,9 @@
|
||||
/** @defgroup MSC_BOT_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static void MSC_BOT_SendData (USBD_HandleTypeDef *pdev, uint8_t* pbuf,
|
||||
uint16_t len);
|
||||
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev);
|
||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
||||
/**
|
||||
@@ -99,9 +98,9 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
|
||||
void MSC_BOT_Init(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
||||
@@ -115,8 +114,8 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
|
||||
USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR);
|
||||
|
||||
/* Prapare EP to Receive First BOT Cmd */
|
||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,16 +124,16 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
|
||||
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
||||
|
||||
/* Prapare EP to Receive First BOT Cmd */
|
||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,10 +142,10 @@ void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
|
||||
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,30 +155,27 @@ void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
|
||||
* @param epnum: endpoint index
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
switch (hmsc->bot_state)
|
||||
{
|
||||
case USBD_BOT_DATA_IN:
|
||||
if(SCSI_ProcessCmd(pdev,
|
||||
hmsc->cbw.bLUN,
|
||||
&hmsc->cbw.CB[0]) < 0)
|
||||
{
|
||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
||||
}
|
||||
break;
|
||||
case USBD_BOT_DATA_IN:
|
||||
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||
{
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_BOT_SEND_DATA:
|
||||
case USBD_BOT_LAST_DATA_IN:
|
||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
||||
case USBD_BOT_SEND_DATA:
|
||||
case USBD_BOT_LAST_DATA_IN:
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -189,30 +185,27 @@ void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
||||
* @param epnum: endpoint index
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
switch (hmsc->bot_state)
|
||||
{
|
||||
case USBD_BOT_IDLE:
|
||||
MSC_BOT_CBW_Decode(pdev);
|
||||
break;
|
||||
case USBD_BOT_IDLE:
|
||||
MSC_BOT_CBW_Decode(pdev);
|
||||
break;
|
||||
|
||||
case USBD_BOT_DATA_OUT:
|
||||
case USBD_BOT_DATA_OUT:
|
||||
|
||||
if(SCSI_ProcessCmd(pdev,
|
||||
hmsc->cbw.bLUN,
|
||||
&hmsc->cbw.CB[0]) < 0)
|
||||
{
|
||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
||||
}
|
||||
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||
{
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||
}
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,17 +215,17 @@ void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
||||
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmsc->csw.dTag = hmsc->cbw.dTag;
|
||||
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
|
||||
|
||||
if ((USBD_LL_GetRxDataSize (pdev ,MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) ||
|
||||
if ((USBD_LL_GetRxDataSize(pdev, MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) ||
|
||||
(hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) ||
|
||||
(hmsc->cbw.bLUN > 1U) ||
|
||||
(hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U))
|
||||
(hmsc->cbw.bLUN > 1U) ||
|
||||
(hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U))
|
||||
{
|
||||
|
||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
@@ -242,11 +235,11 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||
{
|
||||
if(hmsc->bot_state == USBD_BOT_NO_DATA)
|
||||
if (hmsc->bot_state == USBD_BOT_NO_DATA)
|
||||
{
|
||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -264,7 +257,7 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
else if (hmsc->bot_data_length == 0U)
|
||||
{
|
||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -286,10 +279,10 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
||||
* @param len: Data Length
|
||||
* @retval None
|
||||
*/
|
||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t* pbuf,
|
||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
uint16_t length = (uint16_t)MIN(hmsc->cbw.dDataLength, len);
|
||||
|
||||
@@ -307,21 +300,21 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t* pbuf,
|
||||
* @param status : CSW status
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
||||
uint8_t CSW_Status)
|
||||
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev,
|
||||
uint8_t CSW_Status)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE;
|
||||
hmsc->csw.bStatus = CSW_Status;
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
|
||||
USBD_LL_Transmit (pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw,
|
||||
USBD_BOT_CSW_LENGTH);
|
||||
USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw,
|
||||
USBD_BOT_CSW_LENGTH);
|
||||
|
||||
/* Prepare EP to Receive next Cmd */
|
||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,23 +324,23 @@ void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev)
|
||||
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if ((hmsc->cbw.bmFlags == 0U) &&
|
||||
(hmsc->cbw.dDataLength != 0U) &&
|
||||
(hmsc->bot_status == USBD_BOT_STATUS_NORMAL))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR );
|
||||
USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
||||
}
|
||||
|
||||
USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||
|
||||
if(hmsc->bot_status == USBD_BOT_STATUS_ERROR)
|
||||
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR)
|
||||
{
|
||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,18 +352,18 @@ static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev)
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if(hmsc->bot_status == USBD_BOT_STATUS_ERROR)/* Bad CBW Signature */
|
||||
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) /* Bad CBW Signature */
|
||||
{
|
||||
USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
||||
}
|
||||
else if(((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY))
|
||||
else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY))
|
||||
{
|
||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_msc_data.h"
|
||||
@@ -67,36 +67,39 @@
|
||||
|
||||
|
||||
/* USB Mass storage Page 0 Inquiry Data */
|
||||
const uint8_t MSC_Page00_Inquiry_Data[] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
(LENGTH_INQUIRY_PAGE00 - 4U),
|
||||
0x00,
|
||||
0x80,
|
||||
0x83
|
||||
const uint8_t MSC_Page00_Inquiry_Data[] =
|
||||
{
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
(LENGTH_INQUIRY_PAGE00 - 4U),
|
||||
0x00,
|
||||
0x80,
|
||||
0x83
|
||||
};
|
||||
/* USB Mass storage sense 6 Data */
|
||||
const uint8_t MSC_Mode_Sense6_data[] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00
|
||||
const uint8_t MSC_Mode_Sense6_data[] =
|
||||
{
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00
|
||||
};
|
||||
/* USB Mass storage sense 10 Data */
|
||||
const uint8_t MSC_Mode_Sense10_data[] = {
|
||||
0x00,
|
||||
0x06,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00
|
||||
const uint8_t MSC_Mode_Sense10_data[] =
|
||||
{
|
||||
0x00,
|
||||
0x06,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00
|
||||
};
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_msc_bot.h"
|
||||
@@ -78,22 +78,22 @@
|
||||
/** @defgroup MSC_SCSI_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params);
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params);
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr);
|
||||
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr);
|
||||
|
||||
static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun);
|
||||
static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun);
|
||||
static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun);
|
||||
static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -116,57 +116,58 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
||||
{
|
||||
switch (cmd[0])
|
||||
{
|
||||
case SCSI_TEST_UNIT_READY:
|
||||
SCSI_TestUnitReady(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_TEST_UNIT_READY:
|
||||
SCSI_TestUnitReady(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_REQUEST_SENSE:
|
||||
SCSI_RequestSense (pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_INQUIRY:
|
||||
SCSI_Inquiry(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_REQUEST_SENSE:
|
||||
SCSI_RequestSense(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_INQUIRY:
|
||||
SCSI_Inquiry(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_START_STOP_UNIT:
|
||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_START_STOP_UNIT:
|
||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_ALLOW_MEDIUM_REMOVAL:
|
||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_ALLOW_MEDIUM_REMOVAL:
|
||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_MODE_SENSE6:
|
||||
SCSI_ModeSense6 (pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_MODE_SENSE6:
|
||||
SCSI_ModeSense6(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_MODE_SENSE10:
|
||||
SCSI_ModeSense10 (pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_MODE_SENSE10:
|
||||
SCSI_ModeSense10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_READ_FORMAT_CAPACITIES:
|
||||
SCSI_ReadFormatCapacity(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_READ_FORMAT_CAPACITIES:
|
||||
SCSI_ReadFormatCapacity(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_READ_CAPACITY10:
|
||||
SCSI_ReadCapacity10(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_READ_CAPACITY10:
|
||||
SCSI_ReadCapacity10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_READ10:
|
||||
SCSI_Read10(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_READ10:
|
||||
SCSI_Read10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_WRITE10:
|
||||
SCSI_Write10(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_WRITE10:
|
||||
SCSI_Write10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_VERIFY10:
|
||||
SCSI_Verify10(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_VERIFY10:
|
||||
SCSI_Verify10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
default:
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
return -1;
|
||||
default:
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
||||
*/
|
||||
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* case 9 : Hi > D0 */
|
||||
if (hmsc->cbw.dDataLength != 0U)
|
||||
@@ -190,7 +191,7 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
hmsc->bot_state = USBD_BOT_NO_DATA;
|
||||
@@ -211,9 +212,9 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
*/
|
||||
static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
uint8_t* pPage;
|
||||
uint8_t *pPage;
|
||||
uint16_t len;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (params[1] & 0x01U)/*Evpd is set*/
|
||||
{
|
||||
@@ -228,7 +229,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
|
||||
}
|
||||
else
|
||||
{
|
||||
pPage = (uint8_t *)(void *)&((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
|
||||
pPage = (uint8_t *)(void *) & ((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
|
||||
len = (uint16_t)pPage[4] + 5U;
|
||||
|
||||
if (params[4] <= len)
|
||||
@@ -256,9 +257,9 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
|
||||
*/
|
||||
static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
@@ -289,18 +290,18 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_
|
||||
*/
|
||||
static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
uint16_t blk_size;
|
||||
uint32_t blk_nbr;
|
||||
uint16_t i;
|
||||
|
||||
for(i = 0U; i < 12U ; i++)
|
||||
for (i = 0U; i < 12U ; i++)
|
||||
{
|
||||
hmsc->bot_data[i] = 0U;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0U)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0U)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
@@ -329,9 +330,9 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, ui
|
||||
* @param params: Command parameters
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t len = 8U;
|
||||
hmsc->bot_data_length = len;
|
||||
|
||||
@@ -350,10 +351,10 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
|
||||
* @param params: Command parameters
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
uint16_t len = 8U;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmsc->bot_data_length = len;
|
||||
|
||||
@@ -374,20 +375,21 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
uint8_t i;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
for(i = 0U ;i < REQUEST_SENSE_DATA_LEN; i++)
|
||||
for (i = 0U ; i < REQUEST_SENSE_DATA_LEN; i++)
|
||||
{
|
||||
hmsc->bot_data[i] = 0U;
|
||||
}
|
||||
|
||||
hmsc->bot_data[0] = 0x70U;
|
||||
hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U;
|
||||
hmsc->bot_data[0] = 0x70U;
|
||||
hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U;
|
||||
|
||||
if((hmsc->scsi_sense_head != hmsc->scsi_sense_tail)) {
|
||||
if ((hmsc->scsi_sense_head != hmsc->scsi_sense_tail))
|
||||
{
|
||||
|
||||
hmsc->bot_data[2] = hmsc->scsi_sense[hmsc->scsi_sense_head].Skey;
|
||||
hmsc->bot_data[12] = hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASCQ;
|
||||
@@ -419,7 +421,7 @@ static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
*/
|
||||
void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmsc->scsi_sense[hmsc->scsi_sense_tail].Skey = sKey;
|
||||
hmsc->scsi_sense[hmsc->scsi_sense_tail].w.ASC = ASC << 8;
|
||||
@@ -438,7 +440,7 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_
|
||||
*/
|
||||
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
hmsc->bot_data_length = 0U;
|
||||
return 0;
|
||||
}
|
||||
@@ -452,9 +454,9 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
*/
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if(hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||
{
|
||||
/* case 10 : Ho <> Di */
|
||||
if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U)
|
||||
@@ -463,7 +465,7 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
@@ -472,12 +474,12 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
(uint32_t)params[5];
|
||||
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8];
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8];
|
||||
|
||||
if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
@@ -504,9 +506,9 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
|
||||
static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
uint32_t len;
|
||||
|
||||
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||
@@ -519,14 +521,14 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
}
|
||||
|
||||
/* Check whether Media is ready */
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check If media is write-protected */
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) != 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED);
|
||||
return -1;
|
||||
@@ -535,14 +537,14 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
(uint32_t)params[5];
|
||||
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) |
|
||||
(uint32_t)params[8];
|
||||
(uint32_t)params[8];
|
||||
|
||||
/* check if LBA address is in the right range */
|
||||
if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
@@ -560,7 +562,7 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
|
||||
/* Prepare EP to receive first data packet */
|
||||
hmsc->bot_state = USBD_BOT_DATA_OUT;
|
||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
||||
}
|
||||
else /* Write Process ongoing */
|
||||
{
|
||||
@@ -578,18 +580,18 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if ((params[1]& 0x02U) == 0x02U)
|
||||
if ((params[1] & 0x02U) == 0x02U)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
return -1; /* Error, Verify Mode Not supported*/
|
||||
}
|
||||
|
||||
if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
@@ -605,10 +607,10 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
* @param blk_nbr: number of block to be processed
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr)
|
||||
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr)
|
||||
{
|
||||
@@ -624,23 +626,23 @@ static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
* @param lun: Logical unit number
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
|
||||
len = MIN(len, MSC_MEDIA_PACKET);
|
||||
|
||||
if( ((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun,
|
||||
hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun,
|
||||
hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
USBD_LL_Transmit (pdev, MSC_EPIN_ADDR, hmsc->bot_data, len);
|
||||
USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, hmsc->bot_data, len);
|
||||
|
||||
hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size);
|
||||
hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size);
|
||||
@@ -662,16 +664,16 @@ static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
|
||||
len = MIN(len, MSC_MEDIA_PACKET);
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT);
|
||||
|
||||
@@ -686,13 +688,13 @@ static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
|
||||
if (hmsc->scsi_blk_len == 0U)
|
||||
{
|
||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET);
|
||||
/* Prepare EP to Receive next packet */
|
||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_msc_storage_template.h"
|
||||
@@ -35,34 +35,30 @@
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
#define STORAGE_LUN_NBR 1
|
||||
#define STORAGE_BLK_NBR 0x10000
|
||||
#define STORAGE_BLK_SIZ 0x200
|
||||
#define STORAGE_LUN_NBR 1U
|
||||
#define STORAGE_BLK_NBR 0x10000U
|
||||
#define STORAGE_BLK_SIZ 0x200U
|
||||
|
||||
int8_t STORAGE_Init (uint8_t lun);
|
||||
int8_t STORAGE_Init(uint8_t lun);
|
||||
|
||||
int8_t STORAGE_GetCapacity (uint8_t lun,
|
||||
uint32_t *block_num,
|
||||
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num,
|
||||
uint16_t *block_size);
|
||||
|
||||
int8_t STORAGE_IsReady (uint8_t lun);
|
||||
int8_t STORAGE_IsReady(uint8_t lun);
|
||||
|
||||
int8_t STORAGE_IsWriteProtected (uint8_t lun);
|
||||
int8_t STORAGE_IsWriteProtected(uint8_t lun);
|
||||
|
||||
int8_t STORAGE_Read (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len);
|
||||
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr,
|
||||
uint16_t blk_len);
|
||||
|
||||
int8_t STORAGE_Write (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len);
|
||||
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr,
|
||||
uint16_t blk_len);
|
||||
|
||||
int8_t STORAGE_GetMaxLun (void);
|
||||
int8_t STORAGE_GetMaxLun(void);
|
||||
|
||||
/* USB Mass storage Standard Inquiry Data */
|
||||
int8_t STORAGE_Inquirydata[] = {//36
|
||||
int8_t STORAGE_Inquirydata[] = /* 36 */
|
||||
{
|
||||
|
||||
/* LUN 0 */
|
||||
0x00,
|
||||
@@ -76,7 +72,7 @@ int8_t STORAGE_Inquirydata[] = {//36
|
||||
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
|
||||
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */
|
||||
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||
'0', '.', '0' ,'1', /* Version : 4 Bytes */
|
||||
'0', '.', '0', '1', /* Version : 4 Bytes */
|
||||
};
|
||||
|
||||
USBD_StorageTypeDef USBD_MSC_Template_fops =
|
||||
@@ -98,7 +94,7 @@ USBD_StorageTypeDef USBD_MSC_Template_fops =
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_Init (uint8_t lun)
|
||||
int8_t STORAGE_Init(uint8_t lun)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
@@ -110,7 +106,7 @@ int8_t STORAGE_Init (uint8_t lun)
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
||||
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
||||
{
|
||||
*block_num = STORAGE_BLK_NBR;
|
||||
*block_size = STORAGE_BLK_SIZ;
|
||||
@@ -124,7 +120,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t *block_si
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_IsReady (uint8_t lun)
|
||||
int8_t STORAGE_IsReady(uint8_t lun)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
@@ -136,7 +132,7 @@ int8_t STORAGE_IsReady (uint8_t lun)
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_IsWriteProtected (uint8_t lun)
|
||||
int8_t STORAGE_IsWriteProtected(uint8_t lun)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -148,10 +144,8 @@ int8_t STORAGE_IsWriteProtected (uint8_t lun)
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_Read (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len)
|
||||
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf,
|
||||
uint32_t blk_addr, uint16_t blk_len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -162,10 +156,8 @@ int8_t STORAGE_Read (uint8_t lun,
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_Write (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len)
|
||||
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf,
|
||||
uint32_t blk_addr, uint16_t blk_len)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
@@ -176,7 +168,7 @@ int8_t STORAGE_Write (uint8_t lun,
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_GetMaxLun (void)
|
||||
int8_t STORAGE_GetMaxLun(void)
|
||||
{
|
||||
return (STORAGE_LUN_NBR - 1);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
#define __USB_TEMPLATE_CORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -83,32 +83,32 @@
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_TEMPLATE_GetCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc (uint16_t *length);
|
||||
static uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_EP0_TxReady (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -137,7 +137,7 @@ USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver =
|
||||
};
|
||||
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
/* USB TEMPLATE device Configuration Descriptor */
|
||||
static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] =
|
||||
@@ -159,7 +159,7 @@ static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] =
|
||||
};
|
||||
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
/* USB Standard Device Descriptor */
|
||||
static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] =
|
||||
@@ -191,8 +191,8 @@ static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] =
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
|
||||
@@ -207,8 +207,8 @@ static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev,
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -221,37 +221,37 @@ static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -264,9 +264,9 @@ static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_TEMPLATE_GetCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_TEMPLATE_CfgDesc);
|
||||
*length = sizeof(USBD_TEMPLATE_CfgDesc);
|
||||
return USBD_TEMPLATE_CfgDesc;
|
||||
}
|
||||
|
||||
@@ -276,9 +276,9 @@ static uint8_t *USBD_TEMPLATE_GetCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor (uint16_t *length)
|
||||
uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_TEMPLATE_DeviceQualifierDesc);
|
||||
*length = sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -290,8 +290,8 @@ uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor (uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -303,7 +303,7 @@ static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev,
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -314,7 +314,7 @@ static uint8_t USBD_TEMPLATE_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -325,7 +325,7 @@ static uint8_t USBD_TEMPLATE_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -337,7 +337,7 @@ static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -349,7 +349,7 @@ static uint8_t USBD_TEMPLATE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -361,8 +361,8 @@ static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
@@ -374,9 +374,9 @@ static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc (uint16_t *length)
|
||||
uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_TEMPLATE_DeviceQualifierDesc);
|
||||
*length = sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user