mirror of
https://github.com/STMicroelectronics/stm32-mw-usb-device.git
synced 2026-02-08 20:18:07 -05:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5a58ee226 | ||
|
|
d14efc2a3c |
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USB_AUDIO_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -101,13 +101,13 @@
|
|||||||
/* Total size of the audio transfer buffer */
|
/* Total size of the audio transfer buffer */
|
||||||
#define AUDIO_TOTAL_BUF_SIZE ((uint16_t)(AUDIO_OUT_PACKET * AUDIO_OUT_PACKET_NUM))
|
#define AUDIO_TOTAL_BUF_SIZE ((uint16_t)(AUDIO_OUT_PACKET * AUDIO_OUT_PACKET_NUM))
|
||||||
|
|
||||||
/* Audio Commands enumeration */
|
/* Audio Commands enumeration */
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
AUDIO_CMD_START = 1,
|
AUDIO_CMD_START = 1,
|
||||||
AUDIO_CMD_PLAY,
|
AUDIO_CMD_PLAY,
|
||||||
AUDIO_CMD_STOP,
|
AUDIO_CMD_STOP,
|
||||||
}AUDIO_CMD_TypeDef;
|
} AUDIO_CMD_TypeDef;
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -126,12 +126,12 @@ AUDIO_OffsetTypeDef;
|
|||||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
uint8_t data[USB_MAX_EP0_SIZE];
|
uint8_t data[USB_MAX_EP0_SIZE];
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
uint8_t unit;
|
uint8_t unit;
|
||||||
}
|
}
|
||||||
USBD_AUDIO_ControlTypeDef;
|
USBD_AUDIO_ControlTypeDef;
|
||||||
|
|
||||||
@@ -152,14 +152,14 @@ USBD_AUDIO_HandleTypeDef;
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int8_t (*Init) (uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
int8_t (*Init)(uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||||
int8_t (*DeInit) (uint32_t options);
|
int8_t (*DeInit)(uint32_t options);
|
||||||
int8_t (*AudioCmd) (uint8_t* pbuf, uint32_t size, uint8_t cmd);
|
int8_t (*AudioCmd)(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||||
int8_t (*VolumeCtl) (uint8_t vol);
|
int8_t (*VolumeCtl)(uint8_t vol);
|
||||||
int8_t (*MuteCtl) (uint8_t cmd);
|
int8_t (*MuteCtl)(uint8_t cmd);
|
||||||
int8_t (*PeriodicTC) (uint8_t cmd);
|
int8_t (*PeriodicTC)(uint8_t cmd);
|
||||||
int8_t (*GetState) (void);
|
int8_t (*GetState)(void);
|
||||||
}USBD_AUDIO_ItfTypeDef;
|
} USBD_AUDIO_ItfTypeDef;
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -187,10 +187,10 @@ extern USBD_ClassTypeDef USBD_AUDIO;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_AUDIO_ItfTypeDef *fops);
|
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
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_AUDIO_IF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* ===================================================================
|
* ===================================================================
|
||||||
* AUDIO Class Description
|
* 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".
|
* Audio Devices V1.0 Mar 18, 98".
|
||||||
* This driver implements the following aspects of the specification:
|
* This driver implements the following aspects of the specification:
|
||||||
* - Device descriptor management
|
* - Device descriptor management
|
||||||
@@ -48,16 +48,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}.c"
|
- "stm32xxxxx_{eval}{discovery}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_audio.h"
|
#include "usbd_audio.h"
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
/** @defgroup USBD_AUDIO_Private_Macros
|
/** @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), \
|
#define AUDIO_PACKET_SZE(frq) (uint8_t)(((frq * 2U * 2U)/1000U) & 0xFFU), \
|
||||||
(uint8_t)((((frq * 2U * 2U)/1000U) >> 8) & 0xFFU)
|
(uint8_t)((((frq * 2U * 2U)/1000U) >> 8) & 0xFFU)
|
||||||
@@ -103,42 +103,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_AUDIO_Private_FunctionPrototypes
|
/** @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_Setup(USBD_HandleTypeDef *pdev,
|
||||||
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,
|
|
||||||
USBD_SetupReqTypedef *req);
|
USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length);
|
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length);
|
||||||
|
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(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_DataIn (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_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
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_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_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
static void AUDIO_REQ_SetCurrent(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 */
|
/* 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_LEN_DEV_QUALIFIER_DESC,
|
||||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
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
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @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;
|
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;
|
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Allocate Audio structure */
|
/* 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;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||||
haudio->alt_setting = 0U;
|
haudio->alt_setting = 0U;
|
||||||
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
||||||
haudio->wr_ptr = 0U;
|
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,
|
USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, haudio->buffer,
|
||||||
AUDIO_OUT_PACKET);
|
AUDIO_OUT_PACKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,18 +376,17 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
USBD_LL_CloseEP(pdev, AUDIO_OUT_EP);
|
USBD_LL_CloseEP(pdev, AUDIO_OUT_EP);
|
||||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* 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);
|
USBD_free(pdev->pClassData);
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
@@ -417,8 +401,8 @@ static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
@@ -426,96 +410,96 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
uint8_t ret = USBD_OK;
|
uint8_t ret = USBD_OK;
|
||||||
|
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS :
|
||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
case AUDIO_REQ_GET_CUR:
|
case AUDIO_REQ_GET_CUR:
|
||||||
AUDIO_REQ_GetCurrent(pdev, req);
|
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;
|
break;
|
||||||
|
|
||||||
case AUDIO_REQ_SET_CUR:
|
case USB_REQ_TYPE_STANDARD:
|
||||||
AUDIO_REQ_SetCurrent(pdev, req);
|
switch (req->bRequest)
|
||||||
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_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:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
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;
|
return ret;
|
||||||
@@ -529,9 +513,10 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_AUDIO_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,10 +527,8 @@ static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Only OUT data are processed */
|
/* Only OUT data are processed */
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -556,17 +539,18 @@ static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
if (haudio->control.cmd == AUDIO_REQ_SET_CUR)
|
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)
|
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.cmd = 0U;
|
||||||
haudio->control.len = 0U;
|
haudio->control.len = 0U;
|
||||||
}
|
}
|
||||||
@@ -580,7 +564,7 @@ static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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 */
|
/* Only OUT control data are processed */
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -591,7 +575,7 @@ static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -602,15 +586,15 @@ static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
uint32_t cmd = 0U;
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
haudio->offset = offset;
|
haudio->offset = offset;
|
||||||
|
|
||||||
if(haudio->rd_enable == 1U)
|
if (haudio->rd_enable == 1U)
|
||||||
{
|
{
|
||||||
haudio->rd_ptr += (uint16_t)(AUDIO_TOTAL_BUF_SIZE / 2U);
|
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;
|
cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U;
|
||||||
}
|
}
|
||||||
else
|
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;
|
cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U;
|
||||||
}
|
}
|
||||||
@@ -637,25 +621,25 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
|||||||
}
|
}
|
||||||
else
|
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;
|
cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U;
|
||||||
}
|
}
|
||||||
else
|
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;
|
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],
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||||
cmd,
|
cmd,
|
||||||
AUDIO_CMD_PLAY);
|
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
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -678,9 +661,8 @@ static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t ep
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -690,11 +672,10 @@ static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t e
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
if (epnum == AUDIO_OUT_EP)
|
if (epnum == AUDIO_OUT_EP)
|
||||||
{
|
{
|
||||||
@@ -707,16 +688,16 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
/* All buffers are full: roll back */
|
/* All buffers are full: roll back */
|
||||||
haudio->wr_ptr = 0U;
|
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],
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||||
AUDIO_TOTAL_BUF_SIZE / 2U,
|
AUDIO_TOTAL_BUF_SIZE / 2U,
|
||||||
AUDIO_CMD_START);
|
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))
|
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)
|
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
memset(haudio->control.data, 0, 64U);
|
memset(haudio->control.data, 0, 64U);
|
||||||
|
|
||||||
/* Send the current mute state */
|
/* 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)
|
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
if (req->wLength)
|
if (req->wLength)
|
||||||
{
|
{
|
||||||
/* Prepare the reception of the buffer over EP0 */
|
/* Prepare the reception of the buffer over EP0 */
|
||||||
USBD_CtlPrepareRx (pdev,
|
USBD_CtlPrepareRx(pdev, haudio->control.data, req->wLength);
|
||||||
haudio->control.data,
|
|
||||||
req->wLength);
|
|
||||||
|
|
||||||
haudio->control.cmd = AUDIO_REQ_SET_CUR; /* Set the request value */
|
haudio->control.cmd = AUDIO_REQ_SET_CUR; /* Set the request value */
|
||||||
haudio->control.len = (uint8_t)req->wLength; /* Set the request data length */
|
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
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_AUDIO_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,13 +773,14 @@ static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length)
|
|||||||
* @param fops: Audio interface callback
|
* @param fops: Audio interface callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_AUDIO_ItfTypeDef *fops)
|
USBD_AUDIO_ItfTypeDef *fops)
|
||||||
{
|
{
|
||||||
if(fops != NULL)
|
if (fops != NULL)
|
||||||
{
|
{
|
||||||
pdev->pUserData= fops;
|
pdev->pUserData = fops;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}.c"
|
- "stm32xxxxx_{eval}{discovery}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_audio_if_template.h"
|
#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_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||||
static int8_t TEMPLATE_DeInit (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_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||||
static int8_t TEMPLATE_VolumeCtl (uint8_t vol);
|
static int8_t TEMPLATE_VolumeCtl(uint8_t vol);
|
||||||
static int8_t TEMPLATE_MuteCtl (uint8_t cmd);
|
static int8_t TEMPLATE_MuteCtl(uint8_t cmd);
|
||||||
static int8_t TEMPLATE_PeriodicTC (uint8_t cmd);
|
static int8_t TEMPLATE_PeriodicTC(uint8_t cmd);
|
||||||
static int8_t TEMPLATE_GetState (void);
|
static int8_t TEMPLATE_GetState(void);
|
||||||
|
|
||||||
USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
||||||
{
|
{
|
||||||
@@ -123,9 +123,8 @@ static int8_t TEMPLATE_DeInit(uint32_t options)
|
|||||||
* @param cmd: command opcode
|
* @param cmd: command opcode
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @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);
|
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)
|
* @param vol: volume level (0..100)
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,9 +143,8 @@ static int8_t TEMPLATE_VolumeCtl (uint8_t vol)
|
|||||||
* @param cmd: vmute command
|
* @param cmd: vmute command
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,9 +153,8 @@ static int8_t TEMPLATE_MuteCtl (uint8_t cmd)
|
|||||||
* @param cmd
|
* @param cmd
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,9 +163,8 @@ static int8_t TEMPLATE_PeriodicTC (uint8_t cmd)
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @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);
|
return (0);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USB_CDC_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -46,11 +46,11 @@
|
|||||||
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
||||||
|
|
||||||
#ifndef CDC_HS_BINTERVAL
|
#ifndef CDC_HS_BINTERVAL
|
||||||
#define CDC_HS_BINTERVAL 0x10U
|
#define CDC_HS_BINTERVAL 0x10U
|
||||||
#endif /* CDC_HS_BINTERVAL */
|
#endif /* CDC_HS_BINTERVAL */
|
||||||
|
|
||||||
#ifndef CDC_FS_BINTERVAL
|
#ifndef CDC_FS_BINTERVAL
|
||||||
#define CDC_FS_BINTERVAL 0x10U
|
#define CDC_FS_BINTERVAL 0x10U
|
||||||
#endif /* CDC_FS_BINTERVAL */
|
#endif /* CDC_FS_BINTERVAL */
|
||||||
|
|
||||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
/* 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 format;
|
||||||
uint8_t paritytype;
|
uint8_t paritytype;
|
||||||
uint8_t datatype;
|
uint8_t datatype;
|
||||||
}USBD_CDC_LineCodingTypeDef;
|
} USBD_CDC_LineCodingTypeDef;
|
||||||
|
|
||||||
typedef struct _USBD_CDC_Itf
|
typedef struct _USBD_CDC_Itf
|
||||||
{
|
{
|
||||||
int8_t (* Init) (void);
|
int8_t (* Init)(void);
|
||||||
int8_t (* DeInit) (void);
|
int8_t (* DeInit)(void);
|
||||||
int8_t (* Control) (uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||||
int8_t (* Receive) (uint8_t* Buf, uint32_t *Len);
|
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||||
|
|
||||||
}USBD_CDC_ItfTypeDef;
|
} USBD_CDC_ItfTypeDef;
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -146,19 +146,19 @@ extern USBD_ClassTypeDef USBD_CDC;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_ItfTypeDef *fops);
|
USBD_CDC_ItfTypeDef *fops);
|
||||||
|
|
||||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuff,
|
uint8_t *pbuff,
|
||||||
uint16_t length);
|
uint16_t length);
|
||||||
|
|
||||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuff);
|
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
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_CDC_IF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -45,15 +45,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_cdc.h"
|
#include "usbd_cdc.h"
|
||||||
@@ -100,32 +100,32 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req);
|
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);
|
uint8_t epnum);
|
||||||
|
|
||||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
uint8_t epnum);
|
|
||||||
|
|
||||||
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 */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__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*/
|
/*Endpoint 2 Descriptor*/
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
CDC_CMD_EP, /* bEndpointAddress */
|
CDC_CMD_EP, /* bEndpointAddress */
|
||||||
0x03, /* bmAttributes: Interrupt */
|
0x03, /* bmAttributes: Interrupt */
|
||||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
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
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @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;
|
uint8_t ret = 0U;
|
||||||
USBD_CDC_HandleTypeDef *hcdc;
|
USBD_CDC_HandleTypeDef *hcdc;
|
||||||
|
|
||||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
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);
|
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->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;
|
ret = 1U;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
/* Init physical Interface components */
|
/* Init physical Interface components */
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
((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->TxState = 0U;
|
||||||
hcdc->RxState = 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 */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
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
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @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;
|
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;
|
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassData);
|
||||||
@@ -580,88 +580,88 @@ static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
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;
|
uint8_t ifalt = 0U;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
uint8_t ret = USBD_OK;
|
uint8_t ret = USBD_OK;
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS :
|
||||||
if (req->wLength)
|
if (req->wLength)
|
||||||
{
|
{
|
||||||
if (req->bmRequest & 0x80U)
|
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,
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||||
(uint8_t *)(void *)hcdc->data,
|
(uint8_t *)(void *)req, 0U);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_TYPE_STANDARD:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
USBD_CtlSendData (pdev, &ifalt, 1U);
|
case USB_REQ_GET_STATUS:
|
||||||
}
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
else
|
{
|
||||||
{
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||||
USBD_CtlError (pdev, req);
|
}
|
||||||
ret = USBD_FAIL;
|
else
|
||||||
}
|
{
|
||||||
break;
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlSendData(pdev, &ifalt, 1U);
|
||||||
ret = USBD_FAIL;
|
}
|
||||||
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
USBD_CtlError (pdev, req);
|
|
||||||
ret = USBD_FAIL;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -674,20 +674,20 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param epnum: endpoint number
|
* @param epnum: endpoint number
|
||||||
* @retval status
|
* @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;
|
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 */
|
/* Update the packet total length */
|
||||||
pdev->ep_in[epnum].total_length = 0U;
|
pdev->ep_in[epnum].total_length = 0U;
|
||||||
|
|
||||||
/* Send ZLP */
|
/* Send ZLP */
|
||||||
USBD_LL_Transmit (pdev, epnum, NULL, 0U);
|
USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -708,16 +708,16 @@ static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
* @param epnum: endpoint number
|
* @param epnum: endpoint number
|
||||||
* @retval status
|
* @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 */
|
/* 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
|
/* USB data will be immediately processed, this allow next USB traffic being
|
||||||
NAKed till the end of the application Xfer */
|
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);
|
((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
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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,
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
||||||
(uint8_t *)(void *)hcdc->data,
|
(uint8_t *)(void *)hcdc->data,
|
||||||
(uint16_t)hcdc->CmdLength);
|
(uint16_t)hcdc->CmdLength);
|
||||||
hcdc->CmdOpCode = 0xFFU;
|
hcdc->CmdOpCode = 0xFFU;
|
||||||
|
|
||||||
}
|
}
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -757,9 +757,9 @@ static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CDC_CfgFSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,9 +770,9 @@ static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CDC_CfgHSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -783,9 +783,9 @@ static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CDC_OtherSpeedCfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -795,9 +795,9 @@ static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CDC_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -807,14 +807,14 @@ uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length)
|
|||||||
* @param fops: CD Interface callback
|
* @param fops: CD Interface callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_ItfTypeDef *fops)
|
USBD_CDC_ItfTypeDef *fops)
|
||||||
{
|
{
|
||||||
uint8_t ret = USBD_FAIL;
|
uint8_t ret = USBD_FAIL;
|
||||||
|
|
||||||
if(fops != NULL)
|
if (fops != NULL)
|
||||||
{
|
{
|
||||||
pdev->pUserData= fops;
|
pdev->pUserData = fops;
|
||||||
ret = USBD_OK;
|
ret = USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -827,11 +827,11 @@ uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pbuff: Tx Buffer
|
* @param pbuff: Tx Buffer
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuff,
|
uint8_t *pbuff,
|
||||||
uint16_t length)
|
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->TxBuffer = pbuff;
|
||||||
hcdc->TxLength = length;
|
hcdc->TxLength = length;
|
||||||
@@ -846,10 +846,10 @@ uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pbuff: Rx Buffer
|
* @param pbuff: Rx Buffer
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuff)
|
uint8_t *pbuff)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
hcdc->RxBuffer = pbuff;
|
hcdc->RxBuffer = pbuff;
|
||||||
|
|
||||||
@@ -864,11 +864,11 @@ uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_TransmitPacket(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 */
|
/* Tx Transfer in progress */
|
||||||
hcdc->TxState = 1U;
|
hcdc->TxState = 1U;
|
||||||
@@ -902,12 +902,12 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_ReceivePacket(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 */
|
/* 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 */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
USBD_LL_PrepareReceive(pdev,
|
USBD_LL_PrepareReceive(pdev,
|
||||||
|
|||||||
@@ -12,15 +12,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_cdc_if_template.h"
|
#include "usbd_cdc_if_template.h"
|
||||||
@@ -64,10 +64,10 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int8_t TEMPLATE_Init (void);
|
static int8_t TEMPLATE_Init(void);
|
||||||
static int8_t TEMPLATE_DeInit (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_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_Receive(uint8_t *pbuf, uint32_t *Len);
|
||||||
|
|
||||||
USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
||||||
{
|
{
|
||||||
@@ -78,12 +78,12 @@ USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
|||||||
};
|
};
|
||||||
|
|
||||||
USBD_CDC_LineCodingTypeDef linecoding =
|
USBD_CDC_LineCodingTypeDef linecoding =
|
||||||
{
|
{
|
||||||
115200, /* baud rate*/
|
115200, /* baud rate*/
|
||||||
0x00, /* stop bits-1*/
|
0x00, /* stop bits-1*/
|
||||||
0x00, /* parity - none*/
|
0x00, /* parity - none*/
|
||||||
0x08 /* nb. of bits 8*/
|
0x08 /* nb. of bits 8*/
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -124,62 +124,62 @@ static int8_t TEMPLATE_DeInit(void)
|
|||||||
* @param Len: Number of data to be sent (in bytes)
|
* @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
|
* @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)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_GET_ENCAPSULATED_RESPONSE:
|
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_SET_COMM_FEATURE:
|
case CDC_SET_COMM_FEATURE:
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_GET_COMM_FEATURE:
|
case CDC_GET_COMM_FEATURE:
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_CLEAR_COMM_FEATURE:
|
case CDC_CLEAR_COMM_FEATURE:
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_SET_LINE_CODING:
|
case CDC_SET_LINE_CODING:
|
||||||
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\
|
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \
|
||||||
(pbuf[2] << 16) | (pbuf[3] << 24));
|
(pbuf[2] << 16) | (pbuf[3] << 24));
|
||||||
linecoding.format = pbuf[4];
|
linecoding.format = pbuf[4];
|
||||||
linecoding.paritytype = pbuf[5];
|
linecoding.paritytype = pbuf[5];
|
||||||
linecoding.datatype = pbuf[6];
|
linecoding.datatype = pbuf[6];
|
||||||
|
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_GET_LINE_CODING:
|
case CDC_GET_LINE_CODING:
|
||||||
pbuf[0] = (uint8_t)(linecoding.bitrate);
|
pbuf[0] = (uint8_t)(linecoding.bitrate);
|
||||||
pbuf[1] = (uint8_t)(linecoding.bitrate >> 8);
|
pbuf[1] = (uint8_t)(linecoding.bitrate >> 8);
|
||||||
pbuf[2] = (uint8_t)(linecoding.bitrate >> 16);
|
pbuf[2] = (uint8_t)(linecoding.bitrate >> 16);
|
||||||
pbuf[3] = (uint8_t)(linecoding.bitrate >> 24);
|
pbuf[3] = (uint8_t)(linecoding.bitrate >> 24);
|
||||||
pbuf[4] = linecoding.format;
|
pbuf[4] = linecoding.format;
|
||||||
pbuf[5] = linecoding.paritytype;
|
pbuf[5] = linecoding.paritytype;
|
||||||
pbuf[6] = linecoding.datatype;
|
pbuf[6] = linecoding.datatype;
|
||||||
|
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_SET_CONTROL_LINE_STATE:
|
case CDC_SET_CONTROL_LINE_STATE:
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_SEND_BREAK:
|
case CDC_SEND_BREAK:
|
||||||
/* Add your code here */
|
/* Add your code here */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
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)
|
* @param Len: Number of data received (in bytes)
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @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);
|
return (0);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USB_CUSTOMHID_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -51,18 +51,18 @@
|
|||||||
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
||||||
|
|
||||||
#ifndef CUSTOM_HID_HS_BINTERVAL
|
#ifndef CUSTOM_HID_HS_BINTERVAL
|
||||||
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||||
#endif /* CUSTOM_HID_HS_BINTERVAL */
|
#endif /* CUSTOM_HID_HS_BINTERVAL */
|
||||||
|
|
||||||
#ifndef CUSTOM_HID_FS_BINTERVAL
|
#ifndef CUSTOM_HID_FS_BINTERVAL
|
||||||
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||||
#endif /* CUSTOM_HID_FS_BINTERVAL */
|
#endif /* CUSTOM_HID_FS_BINTERVAL */
|
||||||
|
|
||||||
#ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE
|
#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 */
|
#endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */
|
||||||
#ifndef USBD_CUSTOM_HID_REPORT_DESC_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 */
|
#endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */
|
||||||
|
|
||||||
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U
|
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U
|
||||||
@@ -94,11 +94,11 @@ CUSTOM_HID_StateTypeDef;
|
|||||||
typedef struct _USBD_CUSTOM_HID_Itf
|
typedef struct _USBD_CUSTOM_HID_Itf
|
||||||
{
|
{
|
||||||
uint8_t *pReport;
|
uint8_t *pReport;
|
||||||
int8_t (* Init) (void);
|
int8_t (* Init)(void);
|
||||||
int8_t (* DeInit) (void);
|
int8_t (* DeInit)(void);
|
||||||
int8_t (* OutEvent) (uint8_t event_idx, uint8_t state);
|
int8_t (* OutEvent)(uint8_t event_idx, uint8_t state);
|
||||||
|
|
||||||
}USBD_CUSTOM_HID_ItfTypeDef;
|
} USBD_CUSTOM_HID_ItfTypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -137,14 +137,14 @@ extern USBD_ClassTypeDef USBD_CUSTOM_HID;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *report,
|
uint8_t *report,
|
||||||
uint16_t len);
|
uint16_t len);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t USBD_CUSTOM_HID_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_CUSTOMHID_IF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -32,15 +32,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_customhid.h"
|
#include "usbd_customhid.h"
|
||||||
@@ -85,27 +85,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req);
|
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_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
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 */
|
CUSTOM_HID_FS_BINTERVAL, /*bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
0x00,
|
||||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 41 */
|
/* 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 */
|
CUSTOM_HID_HS_BINTERVAL, /*bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
0x00,
|
||||||
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 41 */
|
/* 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 */
|
CUSTOM_HID_FS_BINTERVAL, /*bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
0x00,
|
||||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 41 */
|
/* 41 */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -354,8 +354,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUA
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
uint8_t ret = 0U;
|
uint8_t ret = 0U;
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
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->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;
|
ret = 1U;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef*) pdev->pClassData;
|
hhid = (USBD_CUSTOM_HID_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
hhid->state = CUSTOM_HID_IDLE;
|
hhid->state = CUSTOM_HID_IDLE;
|
||||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init();
|
((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
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
/* Close CUSTOM_HID EP IN */
|
/* Close CUSTOM_HID EP IN */
|
||||||
USBD_LL_CloseEP(pdev, CUSTOM_HID_EPIN_ADDR);
|
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;
|
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* FRee allocated memory */
|
/* FRee allocated memory */
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassData);
|
||||||
@@ -428,10 +428,10 @@ static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
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;
|
uint16_t len = 0U;
|
||||||
uint8_t *pbuf = NULL;
|
uint8_t *pbuf = NULL;
|
||||||
uint16_t status_info = 0U;
|
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)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS :
|
||||||
switch (req->bRequest)
|
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)
|
|
||||||
{
|
{
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
case CUSTOM_HID_REQ_SET_PROTOCOL:
|
||||||
}
|
hhid->Protocol = (uint8_t)(req->wValue);
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
USBD_CtlError (pdev, req);
|
case CUSTOM_HID_REQ_GET_PROTOCOL:
|
||||||
ret = USBD_FAIL;
|
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;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_DESCRIPTOR:
|
case USB_REQ_TYPE_STANDARD:
|
||||||
if( req->wValue >> 8 == CUSTOM_HID_REPORT_DESC)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE , req->wLength);
|
case USB_REQ_GET_STATUS:
|
||||||
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport;
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
}
|
{
|
||||||
else
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||||
{
|
}
|
||||||
if( req->wValue >> 8 == CUSTOM_HID_DESCRIPTOR_TYPE)
|
else
|
||||||
{
|
{
|
||||||
pbuf = USBD_CUSTOM_HID_Desc;
|
USBD_CtlError(pdev, req);
|
||||||
len = MIN(USB_CUSTOM_HID_DESC_SIZ , req->wLength);
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
|
|
||||||
USBD_CtlSendData (pdev, pbuf, len);
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
break;
|
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 :
|
USBD_CtlSendData(pdev, pbuf, len);
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
break;
|
||||||
{
|
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
USBD_CtlError (pdev, req);
|
|
||||||
ret = USBD_FAIL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE :
|
case USB_REQ_GET_INTERFACE :
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
USBD_CtlError (pdev, req);
|
|
||||||
ret = USBD_FAIL;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -549,18 +549,18 @@ static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param buff: pointer to report
|
* @param buff: pointer to report
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *report,
|
uint8_t *report,
|
||||||
uint16_t len)
|
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;
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -577,9 +577,9 @@ uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CUSTOM_HID_CfgFSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,9 +590,9 @@ static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CUSTOM_HID_CfgHSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,9 +603,9 @@ static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CUSTOM_HID_OtherSpeedCfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,8 +616,8 @@ static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
/* 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 */
|
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
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
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],
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
|
||||||
hhid->Report_buf[1]);
|
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);
|
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||||
|
|
||||||
return USBD_OK;
|
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)
|
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)
|
if (hhid->IsReportAvailable == 1U)
|
||||||
{
|
{
|
||||||
@@ -674,9 +674,9 @@ static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CUSTOM_HID_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,14 +686,14 @@ static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc (uint16_t *length)
|
|||||||
* @param fops: CUSTOMHID Interface callback
|
* @param fops: CUSTOMHID Interface callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CUSTOM_HID_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
||||||
{
|
{
|
||||||
uint8_t ret = USBD_FAIL;
|
uint8_t ret = USBD_FAIL;
|
||||||
|
|
||||||
if(fops != NULL)
|
if (fops != NULL)
|
||||||
{
|
{
|
||||||
pdev->pUserData= fops;
|
pdev->pUserData = fops;
|
||||||
ret = USBD_OK;
|
ret = USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @file usbd_customhid_if_template.c
|
* @file usbd_customhid_if_template.c
|
||||||
* @author MCD Application Team
|
* @author MCD Application Team
|
||||||
* @brief USB Device Custom HID interface file.
|
* @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.
|
* following user needs.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_customhid_if_template.h"
|
#include "usbd_customhid_if_template.h"
|
||||||
@@ -31,9 +31,9 @@
|
|||||||
/* Private macro -------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_Init (void);
|
static int8_t TEMPLATE_CUSTOM_HID_Init(void);
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_DeInit (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_OutEvent(uint8_t event_idx, uint8_t state);
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
||||||
{
|
{
|
||||||
@@ -79,7 +79,7 @@ static int8_t TEMPLATE_CUSTOM_HID_DeInit(void)
|
|||||||
* @param state: event state
|
* @param state: event state
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @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);
|
return (0);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USB_DFU_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
DFU_DETACH = 0U,
|
DFU_DETACH = 0U,
|
||||||
DFU_DNLOAD ,
|
DFU_DNLOAD,
|
||||||
DFU_UPLOAD,
|
DFU_UPLOAD,
|
||||||
DFU_GETSTATUS,
|
DFU_GETSTATUS,
|
||||||
DFU_CLRSTATUS,
|
DFU_CLRSTATUS,
|
||||||
@@ -144,9 +144,9 @@ typedef void (*pFunction)(void);
|
|||||||
USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ \
|
USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ \
|
||||||
|
|
||||||
#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\
|
#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];
|
uint32_t d32[USBD_DFU_XFER_SIZE / 4U];
|
||||||
uint8_t d8[USBD_DFU_XFER_SIZE];
|
uint8_t d8[USBD_DFU_XFER_SIZE];
|
||||||
}buffer;
|
} buffer;
|
||||||
|
|
||||||
uint32_t wblock_num;
|
uint32_t wblock_num;
|
||||||
uint32_t wlength;
|
uint32_t wlength;
|
||||||
@@ -179,12 +179,12 @@ USBD_DFU_HandleTypeDef;
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const uint8_t* pStrDesc;
|
const uint8_t *pStrDesc;
|
||||||
uint16_t (* Init) (void);
|
uint16_t (* Init)(void);
|
||||||
uint16_t (* DeInit) (void);
|
uint16_t (* DeInit)(void);
|
||||||
uint16_t (* Erase) (uint32_t Add);
|
uint16_t (* Erase)(uint32_t Add);
|
||||||
uint16_t (* Write) (uint8_t *src, uint8_t *dest, uint32_t Len);
|
uint16_t (* Write)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint8_t* (* Read) (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);
|
uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
|
||||||
}
|
}
|
||||||
USBD_DFU_MediaTypeDef;
|
USBD_DFU_MediaTypeDef;
|
||||||
@@ -215,8 +215,8 @@ extern USBD_ClassTypeDef USBD_DFU;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
||||||
USBD_DFU_MediaTypeDef *fops);
|
USBD_DFU_MediaTypeDef *fops);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_DFU_MEDIA_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -42,15 +42,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_dfu.h"
|
#include "usbd_dfu.h"
|
||||||
@@ -100,52 +100,52 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req);
|
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)
|
#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_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||||
#endif
|
#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_GetCfgDesc,
|
USBD_DFU_GetCfgDesc,
|
||||||
USBD_DFU_GetDeviceQualifierDesc,
|
USBD_DFU_GetDeviceQualifierDesc,
|
||||||
#if (USBD_SUPPORT_USER_STRING == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
USBD_DFU_GetUsrStringDesc
|
USBD_DFU_GetUsrStringDesc
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@@ -275,21 +275,21 @@ __ALIGN_BEGIN static uint8_t USBD_DFU_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu;
|
USBD_DFU_HandleTypeDef *hdfu;
|
||||||
|
|
||||||
/* Allocate Audio structure */
|
/* Allocate Audio structure */
|
||||||
pdev->pClassData = USBD_malloc(sizeof (USBD_DFU_HandleTypeDef));
|
pdev->pClassData = USBD_malloc(sizeof(USBD_DFU_HandleTypeDef));
|
||||||
|
|
||||||
if(pdev->pClassData == NULL)
|
if (pdev->pClassData == NULL)
|
||||||
{
|
{
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
hdfu->alt_setting = 0U;
|
hdfu->alt_setting = 0U;
|
||||||
hdfu->data_ptr = USBD_DFU_APP_DEFAULT_ADD;
|
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
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu;
|
USBD_DFU_HandleTypeDef *hdfu;
|
||||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
hdfu->wblock_num = 0U;
|
hdfu->wblock_num = 0U;
|
||||||
hdfu->wlength = 0U;
|
hdfu->wlength = 0U;
|
||||||
@@ -336,7 +336,7 @@ static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
hdfu->dev_status[4] = DFU_STATE_IDLE;
|
hdfu->dev_status[4] = DFU_STATE_IDLE;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData != NULL)
|
||||||
{
|
{
|
||||||
/* De-Initialize Hardware layer */
|
/* De-Initialize Hardware layer */
|
||||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit();
|
||||||
@@ -354,8 +354,8 @@ static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu;
|
USBD_DFU_HandleTypeDef *hdfu;
|
||||||
uint8_t *pbuf = 0U;
|
uint8_t *pbuf = 0U;
|
||||||
@@ -363,117 +363,117 @@ static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
uint8_t ret = USBD_OK;
|
uint8_t ret = USBD_OK;
|
||||||
|
|
||||||
hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData;
|
hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData;
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS:
|
case USB_REQ_TYPE_CLASS:
|
||||||
switch (req->bRequest)
|
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)
|
|
||||||
{
|
{
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
case DFU_DNLOAD:
|
||||||
}
|
DFU_Download(pdev, req);
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
USBD_CtlError (pdev, req);
|
|
||||||
ret = USBD_FAIL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USB_REQ_GET_DESCRIPTOR:
|
case DFU_UPLOAD:
|
||||||
if( (req->wValue >> 8) == DFU_DESCRIPTOR_TYPE)
|
DFU_Upload(pdev, req);
|
||||||
{
|
break;
|
||||||
pbuf = USBD_DFU_CfgDesc + (9U * (USBD_DFU_MAX_ITF_NUM + 1U));
|
|
||||||
len = MIN(USB_DFU_DESC_SIZ , req->wLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
USBD_CtlSendData (pdev, pbuf, len);
|
case DFU_GETSTATUS:
|
||||||
break;
|
DFU_GetStatus(pdev);
|
||||||
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE:
|
case DFU_CLRSTATUS:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
DFU_ClearStatus(pdev);
|
||||||
{
|
break;
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hdfu->alt_setting, 1U);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
USBD_CtlError (pdev, req);
|
|
||||||
ret = USBD_FAIL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE:
|
case DFU_GETSTATE:
|
||||||
if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM)
|
DFU_GetState(pdev);
|
||||||
{
|
break;
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
|
||||||
{
|
case DFU_ABORT:
|
||||||
hdfu->alt_setting = (uint8_t)(req->wValue);
|
DFU_Abort(pdev);
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
case DFU_DETACH:
|
||||||
USBD_CtlError (pdev, req);
|
DFU_Detach(pdev, req);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_TYPE_STANDARD:
|
||||||
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
/* Call the error management function (command will be nacked */
|
case USB_REQ_GET_STATUS:
|
||||||
USBD_CtlError (pdev, req);
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
ret = USBD_FAIL;
|
{
|
||||||
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
USBD_CtlError (pdev, req);
|
|
||||||
ret = USBD_FAIL;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -487,9 +487,9 @@ static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_DFU_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,8 +500,8 @@ static uint8_t *USBD_DFU_GetCfgDesc (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_DFU_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_DFU_DataIn(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -513,7 +513,7 @@ static uint8_t USBD_DFU_DataIn (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
@@ -524,13 +524,13 @@ static uint8_t USBD_DFU_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
uint32_t addr;
|
||||||
USBD_SetupReqTypedef req;
|
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_DNLOAD_BUSY)
|
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) */
|
/* Call the error management function (command will be nacked) */
|
||||||
req.bmRequest = 0U;
|
req.bmRequest = 0U;
|
||||||
req.wLength = 1U;
|
req.wLength = 1U;
|
||||||
USBD_CtlError (pdev, &req);
|
USBD_CtlError(pdev, &req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Regular Download Command */
|
/* Regular Download Command */
|
||||||
@@ -581,7 +581,7 @@ static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
/* Preform the write operation */
|
/* Preform the write operation */
|
||||||
if (((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Write(hdfu->buffer.d8,
|
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;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
@@ -618,7 +618,7 @@ static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_DFU_SOF (USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -630,7 +630,7 @@ static uint8_t USBD_DFU_SOF (USBD_HandleTypeDef *pdev)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
@@ -642,7 +642,7 @@ static uint8_t USBD_DFU_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnu
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
@@ -654,8 +654,8 @@ static uint8_t USBD_DFU_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epn
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_DFU_DataOut (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_DFU_DataOut(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -667,9 +667,9 @@ static uint8_t USBD_DFU_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_DFU_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,14 +681,14 @@ static uint8_t *USBD_DFU_GetDeviceQualifierDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to the descriptor table or NULL if the descriptor is not supported.
|
* @retval pointer to the descriptor table or NULL if the descriptor is not supported.
|
||||||
*/
|
*/
|
||||||
#if (USBD_SUPPORT_USER_STRING == 1U)
|
#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_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length)
|
||||||
{
|
{
|
||||||
static uint8_t USBD_StrDesc[255];
|
static uint8_t USBD_StrDesc[255];
|
||||||
/* Check if the requested string interface is supported */
|
/* Check if the requested string interface is supported */
|
||||||
if (index <= (USBD_IDX_INTERFACE_STR + USBD_DFU_MAX_ITF_NUM))
|
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;
|
return USBD_StrDesc;
|
||||||
}
|
}
|
||||||
/* Not supported Interface Descriptor index */
|
/* 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
|
* @param fops: storage callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
||||||
USBD_DFU_MediaTypeDef *fops)
|
USBD_DFU_MediaTypeDef *fops)
|
||||||
{
|
{
|
||||||
if(fops != NULL)
|
if (fops != NULL)
|
||||||
{
|
{
|
||||||
pdev->pUserData= fops;
|
pdev->pUserData = fops;
|
||||||
}
|
}
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
@@ -726,13 +726,13 @@ uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
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
|
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_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 */
|
/* Update the state machine */
|
||||||
hdfu->dev_state = DFU_STATE_IDLE;
|
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)
|
if ((USBD_DFU_CfgDesc[12U + (9U * USBD_DFU_MAX_ITF_NUM)]) & DFU_DETACH_MASK)
|
||||||
{
|
{
|
||||||
/* Perform an Attach-Detach operation on USB bus */
|
/* Perform an Attach-Detach operation on USB bus */
|
||||||
USBD_Stop (pdev);
|
USBD_Stop(pdev);
|
||||||
USBD_Start (pdev);
|
USBD_Start(pdev);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Wait for the period of time specified in Detach request */
|
/* 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)
|
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 */
|
/* Data setup request */
|
||||||
if (req->wLength > 0U)
|
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;
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
|
||||||
/* Prepare the reception of the buffer over EP0 */
|
/* Prepare the reception of the buffer over EP0 */
|
||||||
USBD_CtlPrepareRx (pdev, (uint8_t*)hdfu->buffer.d8,
|
USBD_CtlPrepareRx(pdev, (uint8_t *)hdfu->buffer.d8,
|
||||||
(uint16_t)hdfu->wlength);
|
(uint16_t)hdfu->wlength);
|
||||||
}
|
}
|
||||||
/* Unsupported state */
|
/* Unsupported state */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Call the error management function (command will be nacked */
|
/* Call the error management function (command will be nacked */
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 0 Data DNLOAD request */
|
/* 0 Data DNLOAD request */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* End of DNLOAD operation*/
|
/* 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->manif_state = DFU_MANIFEST_IN_PROGRESS;
|
||||||
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
|
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
|
||||||
@@ -813,7 +813,7 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Call the error management function (command will be nacked */
|
/* 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)
|
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;
|
uint8_t *phaddr = NULL;
|
||||||
uint32_t addr = 0U;
|
uint32_t addr = 0U;
|
||||||
@@ -847,7 +847,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
if (hdfu->wblock_num == 0U)
|
if (hdfu->wblock_num == 0U)
|
||||||
{
|
{
|
||||||
/* Update the state machine */
|
/* 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[1] = 0U;
|
||||||
hdfu->dev_status[2] = 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;
|
hdfu->buffer.d8[2] = DFU_CMD_ERASE;
|
||||||
|
|
||||||
/* Send the status data over EP0 */
|
/* 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)
|
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);
|
phaddr = ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Read((uint8_t *)addr, hdfu->buffer.d8, hdfu->wlength);
|
||||||
|
|
||||||
/* Send the status data over EP0 */
|
/* 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 */
|
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;
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
|
||||||
/* Call the error management function (command will be nacked */
|
/* Call the error management function (command will be nacked */
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Unsupported state */
|
/* Unsupported state */
|
||||||
@@ -898,7 +898,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
hdfu->wlength = 0U;
|
hdfu->wlength = 0U;
|
||||||
hdfu->wblock_num = 0U;
|
hdfu->wblock_num = 0U;
|
||||||
/* Call the error management function (command will be nacked */
|
/* Call the error management function (command will be nacked */
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* No Data setup request */
|
/* 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)
|
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)
|
switch (hdfu->dev_state)
|
||||||
{
|
{
|
||||||
case DFU_STATE_DNLOAD_SYNC:
|
case DFU_STATE_DNLOAD_SYNC:
|
||||||
if (hdfu->wlength != 0U)
|
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))
|
|
||||||
{
|
{
|
||||||
((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);
|
hdfu->dev_state = DFU_STATE_DNLOAD_IDLE;
|
||||||
}
|
|
||||||
}
|
|
||||||
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_status[1] = 0U;
|
hdfu->dev_status[1] = 0U;
|
||||||
hdfu->dev_status[2] = 0U;
|
hdfu->dev_status[2] = 0U;
|
||||||
hdfu->dev_status[3] = 0U;
|
hdfu->dev_status[3] = 0U;
|
||||||
hdfu->dev_status[4] = hdfu->dev_state;
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default :
|
case DFU_STATE_MANIFEST_SYNC :
|
||||||
break;
|
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 */
|
/* 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)
|
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)
|
if (hdfu->dev_state == DFU_STATE_ERROR)
|
||||||
{
|
{
|
||||||
@@ -1013,7 +1013,8 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
|
|||||||
hdfu->dev_status[5] = 0U;/*iString*/
|
hdfu->dev_status[5] = 0U;/*iString*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /*State Error*/
|
{
|
||||||
|
/*State Error*/
|
||||||
hdfu->dev_state = DFU_STATE_ERROR;
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
hdfu->dev_status[0] = DFU_ERROR_UNKNOWN;/*bStatus*/
|
hdfu->dev_status[0] = DFU_ERROR_UNKNOWN;/*bStatus*/
|
||||||
hdfu->dev_status[1] = 0U;
|
hdfu->dev_status[1] = 0U;
|
||||||
@@ -1032,12 +1033,12 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void DFU_GetState(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 */
|
/* 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)
|
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
|
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_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_state = DFU_STATE_IDLE;
|
||||||
hdfu->dev_status[0] = DFU_ERROR_NONE;
|
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)
|
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)
|
if ((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U)
|
||||||
{
|
{
|
||||||
@@ -1095,7 +1096,6 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
hdfu->dev_state = DFU_STATE_MANIFEST_WAIT_RESET;
|
hdfu->dev_state = DFU_STATE_MANIFEST_WAIT_RESET;
|
||||||
|
|
||||||
hdfu->dev_status[1] = 0U;
|
hdfu->dev_status[1] = 0U;
|
||||||
@@ -1104,7 +1104,7 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
|||||||
hdfu->dev_status[4] = hdfu->dev_state;
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
|
||||||
/* Disconnect the USB device */
|
/* Disconnect the USB device */
|
||||||
USBD_Stop (pdev);
|
USBD_Stop(pdev);
|
||||||
|
|
||||||
/* DeInitilialize the MAL(Media Access Layer) */
|
/* DeInitilialize the MAL(Media Access Layer) */
|
||||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit();
|
||||||
@@ -1112,8 +1112,7 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
|||||||
/* Generate system reset to allow jumping to the user code */
|
/* Generate system reset to allow jumping to the user code */
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
|
|
||||||
/* This instruction will not be reached (system reset) */
|
/* The next instructions will not be reached (system reset) */
|
||||||
for(;;){}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,15 +12,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_dfu_media_template.h"
|
#include "usbd_dfu_media_template.h"
|
||||||
@@ -34,21 +34,21 @@
|
|||||||
/* Extern function prototypes ------------------------------------------------*/
|
/* Extern function prototypes ------------------------------------------------*/
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
uint16_t MEM_If_Init(void);
|
uint16_t MEM_If_Init(void);
|
||||||
uint16_t MEM_If_Erase (uint32_t Add);
|
uint16_t MEM_If_Erase(uint32_t Add);
|
||||||
uint16_t MEM_If_Write (uint8_t *src, uint8_t *dest, uint32_t Len);
|
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);
|
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint16_t MEM_If_DeInit(void);
|
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 =
|
USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
||||||
{
|
{
|
||||||
(uint8_t *)"DFU MEDIA",
|
(uint8_t *)"DFU MEDIA",
|
||||||
MEM_If_Init,
|
MEM_If_Init,
|
||||||
MEM_If_DeInit,
|
MEM_If_DeInit,
|
||||||
MEM_If_Erase,
|
MEM_If_Erase,
|
||||||
MEM_If_Write,
|
MEM_If_Write,
|
||||||
MEM_If_Read,
|
MEM_If_Read,
|
||||||
MEM_If_GetStatus,
|
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).
|
* @param Len: Number of data to be read (in bytes).
|
||||||
* @retval Pointer to the physical address where data should be read.
|
* @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 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).
|
* @param cmd: Number of data to be read (in bytes).
|
||||||
* @retval Pointer to the physical address where data should be read.
|
* @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)
|
switch (Cmd)
|
||||||
{
|
{
|
||||||
case DFU_MEDIA_PROGRAM:
|
case DFU_MEDIA_PROGRAM:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DFU_MEDIA_ERASE:
|
case DFU_MEDIA_ERASE:
|
||||||
default:
|
default:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USB_HID_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -52,11 +52,11 @@
|
|||||||
#define HID_REPORT_DESC 0x22U
|
#define HID_REPORT_DESC 0x22U
|
||||||
|
|
||||||
#ifndef HID_HS_BINTERVAL
|
#ifndef HID_HS_BINTERVAL
|
||||||
#define HID_HS_BINTERVAL 0x07U
|
#define HID_HS_BINTERVAL 0x07U
|
||||||
#endif /* HID_HS_BINTERVAL */
|
#endif /* HID_HS_BINTERVAL */
|
||||||
|
|
||||||
#ifndef HID_FS_BINTERVAL
|
#ifndef HID_FS_BINTERVAL
|
||||||
#define HID_FS_BINTERVAL 0x0AU
|
#define HID_FS_BINTERVAL 0x0AU
|
||||||
#endif /* HID_FS_BINTERVAL */
|
#endif /* HID_FS_BINTERVAL */
|
||||||
|
|
||||||
#define HID_REQ_SET_PROTOCOL 0x0BU
|
#define HID_REQ_SET_PROTOCOL 0x0BU
|
||||||
@@ -118,11 +118,11 @@ extern USBD_ClassTypeDef USBD_HID;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *report,
|
uint8_t *report,
|
||||||
uint16_t len);
|
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
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_hid.h"
|
#include "usbd_hid.h"
|
||||||
@@ -90,24 +90,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req);
|
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
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @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 */
|
/* Open EP IN */
|
||||||
USBD_LL_OpenEP(pdev, HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE);
|
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->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)
|
if (pdev->pClassData == NULL)
|
||||||
{
|
{
|
||||||
@@ -405,15 +405,15 @@ static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
/* Close HID EPs */
|
/* Close HID EPs */
|
||||||
USBD_LL_CloseEP(pdev, HID_EPIN_ADDR);
|
USBD_LL_CloseEP(pdev, HID_EPIN_ADDR);
|
||||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* FRee allocated memory */
|
/* FRee allocated memory */
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData != NULL)
|
||||||
{
|
{
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassData);
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
@@ -429,10 +429,10 @@ static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
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;
|
uint16_t len = 0U;
|
||||||
uint8_t *pbuf = NULL;
|
uint8_t *pbuf = NULL;
|
||||||
uint16_t status_info = 0U;
|
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)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS :
|
||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
case HID_REQ_SET_PROTOCOL:
|
case HID_REQ_SET_PROTOCOL:
|
||||||
hhid->Protocol = (uint8_t)(req->wValue);
|
hhid->Protocol = (uint8_t)(req->wValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_GET_PROTOCOL:
|
case HID_REQ_GET_PROTOCOL:
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_SET_IDLE:
|
case HID_REQ_SET_IDLE:
|
||||||
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_GET_IDLE:
|
case HID_REQ_GET_IDLE:
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
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;
|
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:
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
if(req->wValue >> 8 == HID_REPORT_DESC)
|
if (req->wValue >> 8 == HID_REPORT_DESC)
|
||||||
{
|
{
|
||||||
len = MIN(HID_MOUSE_REPORT_DESC_SIZE , req->wLength);
|
len = MIN(HID_MOUSE_REPORT_DESC_SIZE, req->wLength);
|
||||||
pbuf = HID_MOUSE_ReportDesc;
|
pbuf = HID_MOUSE_ReportDesc;
|
||||||
}
|
}
|
||||||
else if(req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||||
{
|
{
|
||||||
pbuf = USBD_HID_Desc;
|
pbuf = USBD_HID_Desc;
|
||||||
len = MIN(USB_HID_DESC_SIZ, req->wLength);
|
len = MIN(USB_HID_DESC_SIZ, req->wLength);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
USBD_CtlSendData (pdev, pbuf, len);
|
USBD_CtlSendData(pdev, pbuf, len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE :
|
case USB_REQ_GET_INTERFACE :
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE :
|
case USB_REQ_SET_INTERFACE :
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
USBD_CtlError (pdev, req);
|
|
||||||
ret = USBD_FAIL;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -547,21 +547,21 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param buff: pointer to report
|
* @param buff: pointer to report
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *report,
|
uint8_t *report,
|
||||||
uint16_t len)
|
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;
|
hhid->state = HID_BUSY;
|
||||||
USBD_LL_Transmit (pdev,
|
USBD_LL_Transmit(pdev,
|
||||||
HID_EPIN_ADDR,
|
HID_EPIN_ADDR,
|
||||||
report,
|
report,
|
||||||
len);
|
len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -573,17 +573,17 @@ uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval polling interval
|
* @retval polling interval
|
||||||
*/
|
*/
|
||||||
uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev)
|
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
uint32_t polling_interval = 0U;
|
uint32_t polling_interval = 0U;
|
||||||
|
|
||||||
/* HIGH-speed endpoints */
|
/* 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.
|
/* Sets the data transfer polling interval for high speed transfers.
|
||||||
Values between 1..16 are allowed. Values correspond to interval
|
Values between 1..16 are allowed. Values correspond to interval
|
||||||
of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
|
of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
|
||||||
polling_interval = (((1U <<(HID_HS_BINTERVAL - 1U))) / 8U);
|
polling_interval = (((1U << (HID_HS_BINTERVAL - 1U))) / 8U);
|
||||||
}
|
}
|
||||||
else /* LOW and FULL-speed endpoints */
|
else /* LOW and FULL-speed endpoints */
|
||||||
{
|
{
|
||||||
@@ -602,9 +602,9 @@ uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_HID_CfgFSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,9 +615,9 @@ static uint8_t *USBD_HID_GetFSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_HID_CfgHSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,9 +628,9 @@ static uint8_t *USBD_HID_GetHSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_HID_OtherSpeedCfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,8 +641,8 @@ static uint8_t *USBD_HID_GetOtherSpeedCfgDesc (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
/* 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
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_HID_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_MSC_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -68,16 +68,16 @@
|
|||||||
*/
|
*/
|
||||||
typedef struct _USBD_STORAGE
|
typedef struct _USBD_STORAGE
|
||||||
{
|
{
|
||||||
int8_t (* Init) (uint8_t lun);
|
int8_t (* Init)(uint8_t lun);
|
||||||
int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size);
|
int8_t (* GetCapacity)(uint8_t lun, uint32_t *block_num, uint16_t *block_size);
|
||||||
int8_t (* IsReady) (uint8_t lun);
|
int8_t (* IsReady)(uint8_t lun);
|
||||||
int8_t (* IsWriteProtected) (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 (* 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 (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
||||||
int8_t (* GetMaxLun)(void);
|
int8_t (* GetMaxLun)(void);
|
||||||
int8_t *pInquiry;
|
int8_t *pInquiry;
|
||||||
|
|
||||||
}USBD_StorageTypeDef;
|
} USBD_StorageTypeDef;
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -107,8 +107,8 @@ USBD_MSC_BOT_HandleTypeDef;
|
|||||||
extern USBD_ClassTypeDef USBD_MSC;
|
extern USBD_ClassTypeDef USBD_MSC;
|
||||||
#define USBD_MSC_CLASS &USBD_MSC
|
#define USBD_MSC_CLASS &USBD_MSC
|
||||||
|
|
||||||
uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev,
|
||||||
USBD_StorageTypeDef *fops);
|
USBD_StorageTypeDef *fops);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_MSC_BOT_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -116,20 +116,20 @@ USBD_MSC_BOT_CSWTypeDef;
|
|||||||
/** @defgroup USBD_CORE_Exported_FunctionsPrototypes
|
/** @defgroup USBD_CORE_Exported_FunctionsPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_Init (USBD_HandleTypeDef *pdev);
|
void MSC_BOT_Init(USBD_HandleTypeDef *pdev);
|
||||||
void MSC_BOT_Reset (USBD_HandleTypeDef *pdev);
|
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev);
|
||||||
void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev);
|
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t epnum);
|
||||||
|
|
||||||
|
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum);
|
uint8_t epnum);
|
||||||
|
|
||||||
void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum);
|
uint8_t CSW_Status);
|
||||||
|
|
||||||
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t CSW_Status);
|
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
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_MSC_DATA_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_MSC_SCSI_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -126,14 +126,17 @@ extern uint8_t ReadFormatCapacity_Data [];
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct _SENSE_ITEM {
|
typedef struct _SENSE_ITEM
|
||||||
|
{
|
||||||
char Skey;
|
char Skey;
|
||||||
union {
|
union
|
||||||
struct _ASCs {
|
{
|
||||||
|
struct _ASCs
|
||||||
|
{
|
||||||
char ASC;
|
char ASC;
|
||||||
char ASCQ;
|
char ASCQ;
|
||||||
}b;
|
} b;
|
||||||
uint8_t ASC;
|
uint8_t ASC;
|
||||||
char *pData;
|
char *pData;
|
||||||
} w;
|
} w;
|
||||||
} USBD_SCSI_SenseTypeDef;
|
} USBD_SCSI_SenseTypeDef;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USBD_MSC_STORAGE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -27,16 +27,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc.h"
|
#include "usbd_msc.h"
|
||||||
@@ -80,30 +80,16 @@
|
|||||||
/** @defgroup MSC_CORE_Private_FunctionPrototypes
|
/** @defgroup MSC_CORE_Private_FunctionPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
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_DeInit (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t cfgidx);
|
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
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_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 */
|
/* USB Mass storage device Configuration Descriptor */
|
||||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
/* 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 */
|
0x09, /* bLength: Configuation Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_MSC_CONFIG_DESC_SIZ,
|
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 =
|
__ALIGN_BEGIN uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
|
|
||||||
0x09, /* bLength: Configuation Descriptor size */
|
0x09, /* bLength: Configuation Descriptor size */
|
||||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
||||||
USB_MSC_CONFIG_DESC_SIZ,
|
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
|
* @param cfgidx: configuration index
|
||||||
* @retval status
|
* @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 */
|
/* Open EP OUT */
|
||||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
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);
|
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->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;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
@@ -335,8 +319,8 @@ uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param cfgidx: configuration index
|
* @param cfgidx: configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
/* Close MSC EPs */
|
/* Close MSC EPs */
|
||||||
USBD_LL_CloseEP(pdev, MSC_EPOUT_ADDR);
|
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);
|
USBD_LL_CloseEP(pdev, MSC_EPIN_ADDR);
|
||||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 0U;
|
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* De-Init the BOT layer */
|
/* De-Init the BOT layer */
|
||||||
MSC_BOT_DeInit(pdev);
|
MSC_BOT_DeInit(pdev);
|
||||||
|
|
||||||
/* Free MSC Class Resources */
|
/* Free MSC Class Resources */
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData != NULL)
|
||||||
{
|
{
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassData);
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -364,149 +349,148 @@ uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: USB request
|
* @param req: USB request
|
||||||
* @retval status
|
* @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;
|
uint8_t ret = USBD_OK;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Class request */
|
/* Class request */
|
||||||
case USB_REQ_TYPE_CLASS:
|
case USB_REQ_TYPE_CLASS:
|
||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
|
||||||
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();
|
case BOT_GET_MAX_LUN:
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hmsc->max_lun, 1U);
|
if ((req->wValue == 0U) && (req->wLength == 1U) &&
|
||||||
}
|
((req->bmRequest & 0x80U) == 0x80U))
|
||||||
else
|
{
|
||||||
{
|
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun();
|
||||||
USBD_CtlError(pdev, req);
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hmsc->max_lun, 1U);
|
||||||
ret = USBD_FAIL;
|
}
|
||||||
}
|
else
|
||||||
break;
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case BOT_RESET :
|
case BOT_RESET :
|
||||||
if((req->wValue == 0U) && (req->wLength == 0U) &&
|
if ((req->wValue == 0U) && (req->wLength == 0U) &&
|
||||||
((req->bmRequest & 0x80U) != 0x80U))
|
((req->bmRequest & 0x80U) != 0x80U))
|
||||||
{
|
{
|
||||||
MSC_BOT_Reset(pdev);
|
MSC_BOT_Reset(pdev);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError(pdev , req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError(pdev , req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
/* Interface & Endpoint request */
|
/* Interface & Endpoint request */
|
||||||
case USB_REQ_TYPE_STANDARD:
|
case USB_REQ_TYPE_STANDARD:
|
||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
|
||||||
case USB_REQ_GET_STATUS:
|
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
|
||||||
{
|
{
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
case USB_REQ_GET_STATUS:
|
||||||
}
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
else
|
{
|
||||||
{
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||||
USBD_CtlError (pdev, req);
|
}
|
||||||
ret = USBD_FAIL;
|
else
|
||||||
}
|
{
|
||||||
break;
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hmsc->interface, 1U);
|
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hmsc->interface, 1U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE:
|
case USB_REQ_SET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
hmsc->interface = (uint8_t)(req->wValue);
|
hmsc->interface = (uint8_t)(req->wValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_CLEAR_FEATURE:
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
|
||||||
/* Flush the FIFO and Clear the stall status */
|
/* Flush the FIFO and Clear the stall status */
|
||||||
USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
||||||
|
|
||||||
/* Reactivate the EP */
|
/* Reactivate the EP */
|
||||||
USBD_LL_CloseEP (pdev , (uint8_t)req->wIndex);
|
USBD_LL_CloseEP(pdev, (uint8_t)req->wIndex);
|
||||||
if((((uint8_t)req->wIndex) & 0x80U) == 0x80U)
|
if ((((uint8_t)req->wIndex) & 0x80U) == 0x80U)
|
||||||
{
|
{
|
||||||
pdev->ep_in[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
pdev->ep_in[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
||||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
||||||
MSC_MAX_HS_PACKET);
|
MSC_MAX_HS_PACKET);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
||||||
MSC_MAX_FS_PACKET);
|
MSC_MAX_FS_PACKET);
|
||||||
}
|
}
|
||||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
USBD_CtlError (pdev, req);
|
|
||||||
ret = USBD_FAIL;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -519,10 +503,10 @@ uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
MSC_BOT_DataIn(pdev , epnum);
|
MSC_BOT_DataIn(pdev, epnum);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,10 +517,10 @@ uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev,
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
MSC_BOT_DataOut(pdev , epnum);
|
MSC_BOT_DataOut(pdev, epnum);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,9 +530,10 @@ uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_MSC_CfgHSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,9 +543,10 @@ uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_MSC_CfgFSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,9 +556,10 @@ uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_MSC_OtherSpeedCfgDesc;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -581,9 +568,10 @@ uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_MSC_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,13 +580,14 @@ uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length)
|
|||||||
* @param fops: storage callback
|
* @param fops: storage callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev,
|
||||||
USBD_StorageTypeDef *fops)
|
USBD_StorageTypeDef *fops)
|
||||||
{
|
{
|
||||||
if(fops != NULL)
|
if (fops != NULL)
|
||||||
{
|
{
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData = fops;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc_bot.h"
|
#include "usbd_msc_bot.h"
|
||||||
@@ -76,10 +76,9 @@
|
|||||||
/** @defgroup MSC_BOT_Private_FunctionPrototypes
|
/** @defgroup MSC_BOT_Private_FunctionPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev);
|
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev);
|
||||||
|
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);
|
||||||
uint16_t len);
|
|
||||||
|
|
||||||
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
||||||
/**
|
/**
|
||||||
@@ -99,9 +98,9 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval None
|
* @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_state = USBD_BOT_IDLE;
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
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);
|
USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR);
|
||||||
|
|
||||||
/* Prapare EP to Receive First BOT Cmd */
|
/* Prapare EP to Receive First BOT Cmd */
|
||||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,16 +124,16 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval None
|
* @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_state = USBD_BOT_IDLE;
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
||||||
|
|
||||||
/* Prapare EP to Receive First BOT Cmd */
|
/* Prapare EP to Receive First BOT Cmd */
|
||||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,10 +142,10 @@ void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval None
|
* @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;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||||
hmsc->bot_state = USBD_BOT_IDLE;
|
hmsc->bot_state = USBD_BOT_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,30 +155,27 @@ void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
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)
|
switch (hmsc->bot_state)
|
||||||
{
|
{
|
||||||
case USBD_BOT_DATA_IN:
|
case USBD_BOT_DATA_IN:
|
||||||
if(SCSI_ProcessCmd(pdev,
|
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||||
hmsc->cbw.bLUN,
|
{
|
||||||
&hmsc->cbw.CB[0]) < 0)
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||||
{
|
}
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBD_BOT_SEND_DATA:
|
case USBD_BOT_SEND_DATA:
|
||||||
case USBD_BOT_LAST_DATA_IN:
|
case USBD_BOT_LAST_DATA_IN:
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
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
|
* @param epnum: endpoint index
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
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)
|
switch (hmsc->bot_state)
|
||||||
{
|
{
|
||||||
case USBD_BOT_IDLE:
|
case USBD_BOT_IDLE:
|
||||||
MSC_BOT_CBW_Decode(pdev);
|
MSC_BOT_CBW_Decode(pdev);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USBD_BOT_DATA_OUT:
|
case USBD_BOT_DATA_OUT:
|
||||||
|
|
||||||
if(SCSI_ProcessCmd(pdev,
|
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||||
hmsc->cbw.bLUN,
|
{
|
||||||
&hmsc->cbw.CB[0]) < 0)
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||||
{
|
}
|
||||||
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
|
* @param pdev: device instance
|
||||||
* @retval None
|
* @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.dTag = hmsc->cbw.dTag;
|
||||||
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
|
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.dSignature != USBD_BOT_CBW_SIGNATURE) ||
|
||||||
(hmsc->cbw.bLUN > 1U) ||
|
(hmsc->cbw.bLUN > 1U) ||
|
||||||
(hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U))
|
(hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U))
|
||||||
{
|
{
|
||||||
|
|
||||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||||
@@ -242,11 +235,11 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
else
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -264,7 +257,7 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
else if (hmsc->bot_data_length == 0U)
|
else if (hmsc->bot_data_length == 0U)
|
||||||
{
|
{
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -286,10 +279,10 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
|||||||
* @param len: Data Length
|
* @param len: Data Length
|
||||||
* @retval None
|
* @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)
|
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);
|
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
|
* @param status : CSW status
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t CSW_Status)
|
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.dSignature = USBD_BOT_CSW_SIGNATURE;
|
||||||
hmsc->csw.bStatus = CSW_Status;
|
hmsc->csw.bStatus = CSW_Status;
|
||||||
hmsc->bot_state = USBD_BOT_IDLE;
|
hmsc->bot_state = USBD_BOT_IDLE;
|
||||||
|
|
||||||
USBD_LL_Transmit (pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw,
|
USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw,
|
||||||
USBD_BOT_CSW_LENGTH);
|
USBD_BOT_CSW_LENGTH);
|
||||||
|
|
||||||
/* Prepare EP to Receive next Cmd */
|
/* Prepare EP to Receive next Cmd */
|
||||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -331,23 +324,23 @@ void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
|||||||
* @retval status
|
* @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) &&
|
if ((hmsc->cbw.bmFlags == 0U) &&
|
||||||
(hmsc->cbw.dDataLength != 0U) &&
|
(hmsc->cbw.dDataLength != 0U) &&
|
||||||
(hmsc->bot_status == USBD_BOT_STATUS_NORMAL))
|
(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);
|
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_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,18 +352,18 @@ static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev)
|
|||||||
* @retval None
|
* @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);
|
USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc_data.h"
|
#include "usbd_msc_data.h"
|
||||||
@@ -67,36 +67,39 @@
|
|||||||
|
|
||||||
|
|
||||||
/* USB Mass storage Page 0 Inquiry Data */
|
/* USB Mass storage Page 0 Inquiry Data */
|
||||||
const uint8_t MSC_Page00_Inquiry_Data[] = {
|
const uint8_t MSC_Page00_Inquiry_Data[] =
|
||||||
0x00,
|
{
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
(LENGTH_INQUIRY_PAGE00 - 4U),
|
0x00,
|
||||||
0x00,
|
(LENGTH_INQUIRY_PAGE00 - 4U),
|
||||||
0x80,
|
0x00,
|
||||||
0x83
|
0x80,
|
||||||
|
0x83
|
||||||
};
|
};
|
||||||
/* USB Mass storage sense 6 Data */
|
/* USB Mass storage sense 6 Data */
|
||||||
const uint8_t MSC_Mode_Sense6_data[] = {
|
const uint8_t MSC_Mode_Sense6_data[] =
|
||||||
0x00,
|
{
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00
|
0x00,
|
||||||
|
0x00
|
||||||
};
|
};
|
||||||
/* USB Mass storage sense 10 Data */
|
/* USB Mass storage sense 10 Data */
|
||||||
const uint8_t MSC_Mode_Sense10_data[] = {
|
const uint8_t MSC_Mode_Sense10_data[] =
|
||||||
0x00,
|
{
|
||||||
0x06,
|
0x00,
|
||||||
0x00,
|
0x06,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00
|
0x00,
|
||||||
|
0x00
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc_bot.h"
|
#include "usbd_msc_bot.h"
|
||||||
@@ -78,22 +78,22 @@
|
|||||||
/** @defgroup MSC_SCSI_Private_FunctionPrototypes
|
/** @defgroup MSC_SCSI_Private_FunctionPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
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_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_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_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_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_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_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_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_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_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_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||||
static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||||
uint32_t blk_offset, uint32_t blk_nbr);
|
uint32_t blk_offset, uint32_t blk_nbr);
|
||||||
|
|
||||||
static int8_t SCSI_ProcessRead (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);
|
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])
|
switch (cmd[0])
|
||||||
{
|
{
|
||||||
case SCSI_TEST_UNIT_READY:
|
case SCSI_TEST_UNIT_READY:
|
||||||
SCSI_TestUnitReady(pdev, lun, cmd);
|
SCSI_TestUnitReady(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_REQUEST_SENSE:
|
case SCSI_REQUEST_SENSE:
|
||||||
SCSI_RequestSense (pdev, lun, cmd);
|
SCSI_RequestSense(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
case SCSI_INQUIRY:
|
case SCSI_INQUIRY:
|
||||||
SCSI_Inquiry(pdev, lun, cmd);
|
SCSI_Inquiry(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_START_STOP_UNIT:
|
case SCSI_START_STOP_UNIT:
|
||||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_ALLOW_MEDIUM_REMOVAL:
|
case SCSI_ALLOW_MEDIUM_REMOVAL:
|
||||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_MODE_SENSE6:
|
case SCSI_MODE_SENSE6:
|
||||||
SCSI_ModeSense6 (pdev, lun, cmd);
|
SCSI_ModeSense6(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_MODE_SENSE10:
|
case SCSI_MODE_SENSE10:
|
||||||
SCSI_ModeSense10 (pdev, lun, cmd);
|
SCSI_ModeSense10(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_READ_FORMAT_CAPACITIES:
|
case SCSI_READ_FORMAT_CAPACITIES:
|
||||||
SCSI_ReadFormatCapacity(pdev, lun, cmd);
|
SCSI_ReadFormatCapacity(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_READ_CAPACITY10:
|
case SCSI_READ_CAPACITY10:
|
||||||
SCSI_ReadCapacity10(pdev, lun, cmd);
|
SCSI_ReadCapacity10(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_READ10:
|
case SCSI_READ10:
|
||||||
SCSI_Read10(pdev, lun, cmd);
|
SCSI_Read10(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_WRITE10:
|
case SCSI_WRITE10:
|
||||||
SCSI_Write10(pdev, lun, cmd);
|
SCSI_Write10(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCSI_VERIFY10:
|
case SCSI_VERIFY10:
|
||||||
SCSI_Verify10(pdev, lun, cmd);
|
SCSI_Verify10(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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)
|
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 */
|
/* case 9 : Hi > D0 */
|
||||||
if (hmsc->cbw.dDataLength != 0U)
|
if (hmsc->cbw.dDataLength != 0U)
|
||||||
@@ -190,7 +191,7 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
return -1;
|
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);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
hmsc->bot_state = USBD_BOT_NO_DATA;
|
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)
|
static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
uint8_t* pPage;
|
uint8_t *pPage;
|
||||||
uint16_t len;
|
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*/
|
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
|
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;
|
len = (uint16_t)pPage[4] + 5U;
|
||||||
|
|
||||||
if (params[4] <= len)
|
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)
|
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);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
return -1;
|
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)
|
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;
|
uint16_t blk_size;
|
||||||
uint32_t blk_nbr;
|
uint32_t blk_nbr;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
for(i = 0U; i < 12U ; i++)
|
for (i = 0U; i < 12U ; i++)
|
||||||
{
|
{
|
||||||
hmsc->bot_data[i] = 0U;
|
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);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -329,9 +330,9 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, ui
|
|||||||
* @param params: Command parameters
|
* @param params: Command parameters
|
||||||
* @retval status
|
* @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;
|
uint16_t len = 8U;
|
||||||
hmsc->bot_data_length = len;
|
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
|
* @param params: Command parameters
|
||||||
* @retval status
|
* @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;
|
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;
|
hmsc->bot_data_length = len;
|
||||||
|
|
||||||
@@ -374,20 +375,21 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
* @retval status
|
* @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;
|
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[i] = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmsc->bot_data[0] = 0x70U;
|
hmsc->bot_data[0] = 0x70U;
|
||||||
hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U;
|
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[2] = hmsc->scsi_sense[hmsc->scsi_sense_head].Skey;
|
||||||
hmsc->bot_data[12] = hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASCQ;
|
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)
|
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].Skey = sKey;
|
||||||
hmsc->scsi_sense[hmsc->scsi_sense_tail].w.ASC = ASC << 8;
|
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)
|
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;
|
hmsc->bot_data_length = 0U;
|
||||||
return 0;
|
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)
|
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 */
|
/* case 10 : Ho <> Di */
|
||||||
if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U)
|
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;
|
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);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
return -1;
|
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) |
|
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||||
((uint32_t)params[3] << 16) |
|
((uint32_t)params[3] << 16) |
|
||||||
((uint32_t)params[4] << 8) |
|
((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,
|
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||||
hmsc->scsi_blk_len) < 0)
|
hmsc->scsi_blk_len) < 0)
|
||||||
{
|
{
|
||||||
return -1; /* error */
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
@@ -504,9 +506,9 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
|||||||
* @retval status
|
* @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;
|
uint32_t len;
|
||||||
|
|
||||||
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
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 */
|
/* 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);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check If media is write-protected */
|
/* 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);
|
SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED);
|
||||||
return -1;
|
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) |
|
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||||
((uint32_t)params[3] << 16) |
|
((uint32_t)params[3] << 16) |
|
||||||
((uint32_t)params[4] << 8) |
|
((uint32_t)params[4] << 8) |
|
||||||
(uint32_t)params[5];
|
(uint32_t)params[5];
|
||||||
|
|
||||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) |
|
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 */
|
/* check if LBA address is in the right range */
|
||||||
if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||||
hmsc->scsi_blk_len) < 0)
|
hmsc->scsi_blk_len) < 0)
|
||||||
{
|
{
|
||||||
return -1; /* error */
|
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 */
|
/* Prepare EP to receive first data packet */
|
||||||
hmsc->bot_state = USBD_BOT_DATA_OUT;
|
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 */
|
else /* Write Process ongoing */
|
||||||
{
|
{
|
||||||
@@ -578,18 +580,18 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
|||||||
* @retval status
|
* @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);
|
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||||
return -1; /* Error, Verify Mode Not supported*/
|
return -1; /* Error, Verify Mode Not supported*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||||
hmsc->scsi_blk_len) < 0)
|
hmsc->scsi_blk_len) < 0)
|
||||||
{
|
{
|
||||||
return -1; /* error */
|
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
|
* @param blk_nbr: number of block to be processed
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||||
uint32_t blk_offset, uint32_t blk_nbr)
|
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)
|
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
|
* @param lun: Logical unit number
|
||||||
* @retval status
|
* @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;
|
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||||
|
|
||||||
len = MIN(len, MSC_MEDIA_PACKET);
|
len = MIN(len, MSC_MEDIA_PACKET);
|
||||||
|
|
||||||
if( ((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun,
|
if (((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun,
|
||||||
hmsc->bot_data,
|
hmsc->bot_data,
|
||||||
hmsc->scsi_blk_addr,
|
hmsc->scsi_blk_addr,
|
||||||
(len / hmsc->scsi_blk_size)) < 0)
|
(len / hmsc->scsi_blk_size)) < 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR);
|
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR);
|
||||||
return -1;
|
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_addr += (len / hmsc->scsi_blk_size);
|
||||||
hmsc->scsi_blk_len -= (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
|
* @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;
|
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||||
|
|
||||||
len = MIN(len, MSC_MEDIA_PACKET);
|
len = MIN(len, MSC_MEDIA_PACKET);
|
||||||
|
|
||||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data,
|
if (((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data,
|
||||||
hmsc->scsi_blk_addr,
|
hmsc->scsi_blk_addr,
|
||||||
(len / hmsc->scsi_blk_size)) < 0)
|
(len / hmsc->scsi_blk_size)) < 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT);
|
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)
|
if (hmsc->scsi_blk_len == 0U)
|
||||||
{
|
{
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET);
|
len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET);
|
||||||
/* Prepare EP to Receive next 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;
|
return 0;
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc_storage_template.h"
|
#include "usbd_msc_storage_template.h"
|
||||||
@@ -35,34 +35,30 @@
|
|||||||
/* Extern function prototypes ------------------------------------------------*/
|
/* Extern function prototypes ------------------------------------------------*/
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
#define STORAGE_LUN_NBR 1
|
#define STORAGE_LUN_NBR 1U
|
||||||
#define STORAGE_BLK_NBR 0x10000
|
#define STORAGE_BLK_NBR 0x10000U
|
||||||
#define STORAGE_BLK_SIZ 0x200
|
#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,
|
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num,
|
||||||
uint32_t *block_num,
|
|
||||||
uint16_t *block_size);
|
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,
|
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr,
|
||||||
uint8_t *buf,
|
uint16_t blk_len);
|
||||||
uint32_t blk_addr,
|
|
||||||
uint16_t blk_len);
|
|
||||||
|
|
||||||
int8_t STORAGE_Write (uint8_t lun,
|
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr,
|
||||||
uint8_t *buf,
|
uint16_t blk_len);
|
||||||
uint32_t blk_addr,
|
|
||||||
uint16_t blk_len);
|
|
||||||
|
|
||||||
int8_t STORAGE_GetMaxLun (void);
|
int8_t STORAGE_GetMaxLun(void);
|
||||||
|
|
||||||
/* USB Mass storage Standard Inquiry Data */
|
/* USB Mass storage Standard Inquiry Data */
|
||||||
int8_t STORAGE_Inquirydata[] = {//36
|
int8_t STORAGE_Inquirydata[] = /* 36 */
|
||||||
|
{
|
||||||
|
|
||||||
/* LUN 0 */
|
/* LUN 0 */
|
||||||
0x00,
|
0x00,
|
||||||
@@ -76,7 +72,7 @@ int8_t STORAGE_Inquirydata[] = {//36
|
|||||||
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
|
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
|
||||||
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 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 =
|
USBD_StorageTypeDef USBD_MSC_Template_fops =
|
||||||
@@ -98,7 +94,7 @@ USBD_StorageTypeDef USBD_MSC_Template_fops =
|
|||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_Init (uint8_t lun)
|
int8_t STORAGE_Init(uint8_t lun)
|
||||||
{
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -110,7 +106,7 @@ int8_t STORAGE_Init (uint8_t lun)
|
|||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : 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_num = STORAGE_BLK_NBR;
|
||||||
*block_size = STORAGE_BLK_SIZ;
|
*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.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_IsReady (uint8_t lun)
|
int8_t STORAGE_IsReady(uint8_t lun)
|
||||||
{
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -136,7 +132,7 @@ int8_t STORAGE_IsReady (uint8_t lun)
|
|||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_IsWriteProtected (uint8_t lun)
|
int8_t STORAGE_IsWriteProtected(uint8_t lun)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -148,10 +144,8 @@ int8_t STORAGE_IsWriteProtected (uint8_t lun)
|
|||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_Read (uint8_t lun,
|
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf,
|
||||||
uint8_t *buf,
|
uint32_t blk_addr, uint16_t blk_len)
|
||||||
uint32_t blk_addr,
|
|
||||||
uint16_t blk_len)
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -162,10 +156,8 @@ int8_t STORAGE_Read (uint8_t lun,
|
|||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_Write (uint8_t lun,
|
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf,
|
||||||
uint8_t *buf,
|
uint32_t blk_addr, uint16_t blk_len)
|
||||||
uint32_t blk_addr,
|
|
||||||
uint16_t blk_len)
|
|
||||||
{
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -176,7 +168,7 @@ int8_t STORAGE_Write (uint8_t lun,
|
|||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_GetMaxLun (void)
|
int8_t STORAGE_GetMaxLun(void)
|
||||||
{
|
{
|
||||||
return (STORAGE_LUN_NBR - 1);
|
return (STORAGE_LUN_NBR - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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
|
#define __USB_TEMPLATE_CORE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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,
|
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx);
|
uint8_t cfgidx);
|
||||||
|
|
||||||
static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req);
|
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 */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif
|
||||||
/* USB TEMPLATE device Configuration Descriptor */
|
/* USB TEMPLATE device Configuration Descriptor */
|
||||||
static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] =
|
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 */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] =
|
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
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
uint8_t ret = 0;
|
uint8_t ret = 0;
|
||||||
|
|
||||||
@@ -207,8 +207,8 @@ static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev,
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t cfgidx)
|
uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -221,37 +221,37 @@ static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS :
|
||||||
switch (req->bRequest)
|
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:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
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;
|
return ret;
|
||||||
@@ -264,9 +264,9 @@ static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_TEMPLATE_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,9 +276,9 @@ static uint8_t *USBD_TEMPLATE_GetCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,8 +290,8 @@ uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -303,7 +303,7 @@ static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
@@ -314,7 +314,7 @@ static uint8_t USBD_TEMPLATE_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
@@ -325,7 +325,7 @@ static uint8_t USBD_TEMPLATE_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -337,7 +337,7 @@ static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
@@ -349,7 +349,7 @@ static uint8_t USBD_TEMPLATE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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;
|
return USBD_OK;
|
||||||
@@ -361,8 +361,8 @@ static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum)
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -374,9 +374,9 @@ static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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_CONF_TEMPLATE_H
|
#define __USBD_CONF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
#define USBD_MAX_NUM_INTERFACES 1U
|
#define USBD_MAX_NUM_INTERFACES 1U
|
||||||
#define USBD_MAX_NUM_CONFIGURATION 1U
|
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||||
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
||||||
#define USBD_SUPPORT_USER_STRING 0U
|
#define USBD_SUPPORT_USER_STRING_DESC 0U
|
||||||
#define USBD_SELF_POWERED 1U
|
#define USBD_SELF_POWERED 1U
|
||||||
#define USBD_DEBUG_LEVEL 2U
|
#define USBD_DEBUG_LEVEL 2U
|
||||||
|
|
||||||
@@ -57,18 +57,18 @@
|
|||||||
/* CDC Class Config */
|
/* CDC Class Config */
|
||||||
#define USBD_CDC_INTERVAL 2000U
|
#define USBD_CDC_INTERVAL 2000U
|
||||||
|
|
||||||
/* DFU Class Config */
|
/* DFU Class Config */
|
||||||
#define USBD_DFU_MAX_ITF_NUM 1U
|
#define USBD_DFU_MAX_ITF_NUM 1U
|
||||||
#define USBD_DFU_XFERS_IZE 1024U
|
#define USBD_DFU_XFERS_IZE 1024U
|
||||||
|
|
||||||
/* AUDIO Class Config */
|
/* AUDIO Class Config */
|
||||||
#define USBD_AUDIO_FREQ 22100U
|
#define USBD_AUDIO_FREQ 22100U
|
||||||
|
|
||||||
/** @defgroup USBD_Exported_Macros
|
/** @defgroup USBD_Exported_Macros
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Memory management macros */
|
/* Memory management macros */
|
||||||
#define USBD_malloc malloc
|
#define USBD_malloc malloc
|
||||||
#define USBD_free free
|
#define USBD_free free
|
||||||
#define USBD_memset memset
|
#define USBD_memset memset
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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_CORE_H
|
#define __USBD_CORE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -84,17 +84,17 @@
|
|||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
|
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
|
||||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
|
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
|
||||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata);
|
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata);
|
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||||
@@ -109,33 +109,33 @@ USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
|
|||||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
/* USBD Low Level Driver */
|
/* USBD Low Level Driver */
|
||||||
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t ep_addr,
|
uint8_t ep_addr,
|
||||||
uint8_t ep_type,
|
uint8_t ep_type,
|
||||||
uint16_t ep_mps);
|
uint16_t ep_mps);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
||||||
USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t ep_addr,
|
uint8_t ep_addr,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf,
|
||||||
uint16_t size);
|
uint16_t size);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t ep_addr,
|
uint8_t ep_addr,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf,
|
||||||
uint16_t size);
|
uint16_t size);
|
||||||
|
|
||||||
uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
void USBD_LL_Delay (uint32_t Delay);
|
void USBD_LL_Delay(uint32_t Delay);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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_REQUEST_H
|
#define __USB_REQUEST_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -73,16 +73,16 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
|
|
||||||
void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata);
|
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata);
|
||||||
|
|
||||||
void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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_DEF_H
|
#define __USBD_DEF_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -61,9 +61,9 @@
|
|||||||
#define USBD_SELF_POWERED 1U
|
#define USBD_SELF_POWERED 1U
|
||||||
#endif /*USBD_SELF_POWERED */
|
#endif /*USBD_SELF_POWERED */
|
||||||
|
|
||||||
#ifndef USBD_SUPPORT_USER_STRING
|
#ifndef USBD_SUPPORT_USER_STRING_DESC
|
||||||
#define USBD_SUPPORT_USER_STRING 0U
|
#define USBD_SUPPORT_USER_STRING_DESC 0U
|
||||||
#endif /* USBD_SUPPORT_USER_STRING */
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
|
#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
|
||||||
#define USB_LEN_DEV_DESC 0x12U
|
#define USB_LEN_DEV_DESC 0x12U
|
||||||
@@ -158,37 +158,36 @@
|
|||||||
|
|
||||||
typedef struct usb_setup_req
|
typedef struct usb_setup_req
|
||||||
{
|
{
|
||||||
|
uint8_t bmRequest;
|
||||||
uint8_t bmRequest;
|
uint8_t bRequest;
|
||||||
uint8_t bRequest;
|
uint16_t wValue;
|
||||||
uint16_t wValue;
|
uint16_t wIndex;
|
||||||
uint16_t wIndex;
|
uint16_t wLength;
|
||||||
uint16_t wLength;
|
} USBD_SetupReqTypedef;
|
||||||
}USBD_SetupReqTypedef;
|
|
||||||
|
|
||||||
struct _USBD_HandleTypeDef;
|
struct _USBD_HandleTypeDef;
|
||||||
|
|
||||||
typedef struct _Device_cb
|
typedef struct _Device_cb
|
||||||
{
|
{
|
||||||
uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
|
uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
|
uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
/* Control Endpoints*/
|
/* Control Endpoints*/
|
||||||
uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req);
|
uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev );
|
uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev);
|
||||||
uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev );
|
uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev);
|
||||||
/* Class Specific Endpoints*/
|
/* Class Specific Endpoints*/
|
||||||
uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev);
|
uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev);
|
||||||
uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
|
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
|
||||||
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
|
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
|
||||||
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
|
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
|
||||||
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
||||||
#if (USBD_SUPPORT_USER_STRING == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length);
|
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} USBD_ClassTypeDef;
|
} USBD_ClassTypeDef;
|
||||||
@@ -199,27 +198,28 @@ typedef enum
|
|||||||
USBD_SPEED_HIGH = 0U,
|
USBD_SPEED_HIGH = 0U,
|
||||||
USBD_SPEED_FULL = 1U,
|
USBD_SPEED_FULL = 1U,
|
||||||
USBD_SPEED_LOW = 2U,
|
USBD_SPEED_LOW = 2U,
|
||||||
}USBD_SpeedTypeDef;
|
} USBD_SpeedTypeDef;
|
||||||
|
|
||||||
/* Following USB Device status */
|
/* Following USB Device status */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
USBD_OK = 0U,
|
USBD_OK = 0U,
|
||||||
USBD_BUSY,
|
USBD_BUSY,
|
||||||
USBD_FAIL,
|
USBD_FAIL,
|
||||||
}USBD_StatusTypeDef;
|
} USBD_StatusTypeDef;
|
||||||
|
|
||||||
/* USB Device descriptors structure */
|
/* USB Device descriptors structure */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
#if (USBD_LPM_ENABLED == 1U)
|
#if (USBD_LPM_ENABLED == 1U)
|
||||||
uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
#endif
|
#endif
|
||||||
} USBD_DescriptorsTypeDef;
|
} USBD_DescriptorsTypeDef;
|
||||||
|
|
||||||
@@ -241,8 +241,8 @@ typedef struct _USBD_HandleTypeDef
|
|||||||
uint32_t dev_default_config;
|
uint32_t dev_default_config;
|
||||||
uint32_t dev_config_status;
|
uint32_t dev_config_status;
|
||||||
USBD_SpeedTypeDef dev_speed;
|
USBD_SpeedTypeDef dev_speed;
|
||||||
USBD_EndpointTypeDef ep_in[15];
|
USBD_EndpointTypeDef ep_in[16];
|
||||||
USBD_EndpointTypeDef ep_out[15];
|
USBD_EndpointTypeDef ep_out[16];
|
||||||
uint32_t ep0_state;
|
uint32_t ep0_state;
|
||||||
uint32_t ep0_data_len;
|
uint32_t ep0_data_len;
|
||||||
uint8_t dev_state;
|
uint8_t dev_state;
|
||||||
@@ -272,37 +272,43 @@ typedef struct _USBD_HandleTypeDef
|
|||||||
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
|
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
|
||||||
(((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U))
|
(((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U))
|
||||||
|
|
||||||
#define LOBYTE(x) ((uint8_t)(x & 0x00FFU))
|
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
|
||||||
#define HIBYTE(x) ((uint8_t)((x & 0xFF00U) >> 8U))
|
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __GNUC__ )
|
#if defined ( __GNUC__ )
|
||||||
#ifndef __weak
|
#ifndef __weak
|
||||||
#define __weak __attribute__((weak))
|
#define __weak __attribute__((weak))
|
||||||
#endif /* __weak */
|
#endif /* __weak */
|
||||||
#ifndef __packed
|
#ifndef __packed
|
||||||
#define __packed __attribute__((__packed__))
|
#define __packed __attribute__((__packed__))
|
||||||
#endif /* __packed */
|
#endif /* __packed */
|
||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
|
||||||
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
||||||
with the DMA during the transaction process should be 4-bytes aligned */
|
with the DMA during the transaction process should be 4-bytes aligned */
|
||||||
|
|
||||||
#if defined (__GNUC__) /* GNU Compiler */
|
#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
|
||||||
#define __ALIGN_END __attribute__ ((aligned (4)))
|
#ifndef __ALIGN_END
|
||||||
#define __ALIGN_BEGIN
|
#define __ALIGN_END __attribute__ ((aligned (4U)))
|
||||||
|
#endif /* __ALIGN_END */
|
||||||
|
#ifndef __ALIGN_BEGIN
|
||||||
|
#define __ALIGN_BEGIN
|
||||||
|
#endif /* __ALIGN_BEGIN */
|
||||||
#else
|
#else
|
||||||
#define __ALIGN_END
|
#ifndef __ALIGN_END
|
||||||
#if defined (__CC_ARM) /* ARM Compiler */
|
#define __ALIGN_END
|
||||||
#define __ALIGN_BEGIN __align(4)
|
#endif /* __ALIGN_END */
|
||||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
#ifndef __ALIGN_BEGIN
|
||||||
#define __ALIGN_BEGIN
|
#if defined (__CC_ARM) /* ARM Compiler */
|
||||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
#define __ALIGN_BEGIN __align(4U)
|
||||||
#define __ALIGN_BEGIN __align(4)
|
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||||
#endif /* __CC_ARM */
|
#define __ALIGN_BEGIN
|
||||||
|
#endif /* __CC_ARM */
|
||||||
|
#endif /* __ALIGN_BEGIN */
|
||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* 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_IOREQ_H
|
#define __USBD_IOREQ_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -77,27 +77,27 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf,
|
||||||
uint16_t len);
|
uint16_t len);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf,
|
||||||
uint16_t len);
|
uint16_t len);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf,
|
||||||
uint16_t len);
|
uint16_t len);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf,
|
||||||
uint16_t len);
|
uint16_t len);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
* @file usbd_conf_template.c
|
* @file usbd_conf_template.c
|
||||||
* @author MCD Application Team
|
* @author MCD Application Team
|
||||||
* @brief USB Device configuration and interface file
|
* @brief USB Device configuration and interface file
|
||||||
* This template should be copied to the user folder, renamed and customized
|
* This template should be copied to the user folder,
|
||||||
* following user needs.
|
* renamed and customized following user needs.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -75,10 +75,8 @@ USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
|||||||
* @param ep_mps: Endpoint Max Packet Size
|
* @param ep_mps: Endpoint Max Packet Size
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
uint8_t ep_addr,
|
uint8_t ep_type, uint16_t ep_mps)
|
||||||
uint8_t ep_type,
|
|
||||||
uint16_t ep_mps)
|
|
||||||
{
|
{
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -122,7 +120,8 @@ USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
|||||||
* @param ep_addr: Endpoint Number
|
* @param ep_addr: Endpoint Number
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -135,7 +134,7 @@ USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_add
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,7 +143,8 @@ uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
|||||||
* @param ep_addr: Endpoint Number
|
* @param ep_addr: Endpoint Number
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -157,10 +157,8 @@ USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_a
|
|||||||
* @param size: Data size
|
* @param size: Data size
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
uint8_t ep_addr,
|
uint8_t *pbuf, uint16_t size)
|
||||||
uint8_t *pbuf,
|
|
||||||
uint16_t size)
|
|
||||||
{
|
{
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -174,8 +172,7 @@ USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
|
|||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t ep_addr,
|
uint8_t ep_addr, uint8_t *pbuf,
|
||||||
uint8_t *pbuf,
|
|
||||||
uint16_t size)
|
uint16_t size)
|
||||||
{
|
{
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -189,7 +186,7 @@ USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
/** @defgroup USBD_CORE_Private_TypesDefinitions
|
/** @defgroup USBD_CORE_Private_TypesDefinitions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -50,13 +51,12 @@
|
|||||||
/** @defgroup USBD_CORE_Private_Macros
|
/** @defgroup USBD_CORE_Private_Macros
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Private_FunctionPrototypes
|
/** @defgroup USBD_CORE_Private_FunctionPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
@@ -73,6 +73,7 @@
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Private_Functions
|
/** @defgroup USBD_CORE_Private_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
@@ -85,10 +86,11 @@
|
|||||||
* @param id: Low level core index
|
* @param id: Low level core index
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id)
|
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_DescriptorsTypeDef *pdesc, uint8_t id)
|
||||||
{
|
{
|
||||||
/* Check whether the USB Host handle is valid */
|
/* Check whether the USB Host handle is valid */
|
||||||
if(pdev == NULL)
|
if (pdev == NULL)
|
||||||
{
|
{
|
||||||
#if (USBD_DEBUG_LEVEL > 1U)
|
#if (USBD_DEBUG_LEVEL > 1U)
|
||||||
USBD_ErrLog("Invalid Device handle");
|
USBD_ErrLog("Invalid Device handle");
|
||||||
@@ -97,19 +99,19 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Unlink previous class*/
|
/* Unlink previous class*/
|
||||||
if(pdev->pClass != NULL)
|
if (pdev->pClass != NULL)
|
||||||
{
|
{
|
||||||
pdev->pClass = NULL;
|
pdev->pClass = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assign USBD Descriptors */
|
/* Assign USBD Descriptors */
|
||||||
if(pdesc != NULL)
|
if (pdesc != NULL)
|
||||||
{
|
{
|
||||||
pdev->pDesc = pdesc;
|
pdev->pDesc = pdesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set Device initial State */
|
/* Set Device initial State */
|
||||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||||
pdev->id = id;
|
pdev->id = id;
|
||||||
/* Initialize low level driver */
|
/* Initialize low level driver */
|
||||||
USBD_LL_Init(pdev);
|
USBD_LL_Init(pdev);
|
||||||
@@ -126,12 +128,12 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *
|
|||||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Set Default State */
|
/* Set Default State */
|
||||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||||
|
|
||||||
/* Free Class Resources */
|
/* Free Class Resources */
|
||||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||||
|
|
||||||
/* Stop the low level driver */
|
/* Stop the low level driver */
|
||||||
USBD_LL_Stop(pdev);
|
USBD_LL_Stop(pdev);
|
||||||
|
|
||||||
/* Initialize low level driver */
|
/* Initialize low level driver */
|
||||||
@@ -149,8 +151,8 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
|
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
|
||||||
{
|
{
|
||||||
USBD_StatusTypeDef status = USBD_OK;
|
USBD_StatusTypeDef status = USBD_OK;
|
||||||
if(pclass != 0)
|
if (pclass != NULL)
|
||||||
{
|
{
|
||||||
/* link the class to the USB Device handle */
|
/* link the class to the USB Device handle */
|
||||||
pdev->pClass = pclass;
|
pdev->pClass = pclass;
|
||||||
@@ -173,9 +175,8 @@ USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeD
|
|||||||
* @param pdev: Device Handle
|
* @param pdev: Device Handle
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Start the low level driver */
|
/* Start the low level driver */
|
||||||
USBD_LL_Start(pdev);
|
USBD_LL_Start(pdev);
|
||||||
|
|
||||||
@@ -188,12 +189,12 @@ USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: Device Handle
|
* @param pdev: Device Handle
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Free Class Resources */
|
/* Free Class Resources */
|
||||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||||
|
|
||||||
/* Stop the low level driver */
|
/* Stop the low level driver */
|
||||||
USBD_LL_Stop(pdev);
|
USBD_LL_Stop(pdev);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -205,7 +206,7 @@ USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Prevent unused argument compilation warning */
|
/* Prevent unused argument compilation warning */
|
||||||
UNUSED(pdev);
|
UNUSED(pdev);
|
||||||
@@ -223,12 +224,12 @@ USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
USBD_StatusTypeDef ret = USBD_FAIL;
|
USBD_StatusTypeDef ret = USBD_FAIL;
|
||||||
|
|
||||||
if(pdev->pClass != NULL)
|
if (pdev->pClass != NULL)
|
||||||
{
|
{
|
||||||
/* Set configuration and Start the Class*/
|
/* Set configuration and Start the Class*/
|
||||||
if(pdev->pClass->Init(pdev, cfgidx) == 0U)
|
if (pdev->pClass->Init(pdev, cfgidx) == 0U)
|
||||||
{
|
{
|
||||||
ret = USBD_OK;
|
ret = USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -248,6 +249,7 @@ USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx
|
|||||||
{
|
{
|
||||||
/* Clear configuration and De-initialize the Class process*/
|
/* Clear configuration and De-initialize the Class process*/
|
||||||
pdev->pClass->DeInit(pdev, cfgidx);
|
pdev->pClass->DeInit(pdev, cfgidx);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,21 +270,21 @@ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
|||||||
|
|
||||||
switch (pdev->request.bmRequest & 0x1FU)
|
switch (pdev->request.bmRequest & 0x1FU)
|
||||||
{
|
{
|
||||||
case USB_REQ_RECIPIENT_DEVICE:
|
case USB_REQ_RECIPIENT_DEVICE:
|
||||||
USBD_StdDevReq (pdev, &pdev->request);
|
USBD_StdDevReq(pdev, &pdev->request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_RECIPIENT_INTERFACE:
|
case USB_REQ_RECIPIENT_INTERFACE:
|
||||||
USBD_StdItfReq(pdev, &pdev->request);
|
USBD_StdItfReq(pdev, &pdev->request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_RECIPIENT_ENDPOINT:
|
case USB_REQ_RECIPIENT_ENDPOINT:
|
||||||
USBD_StdEPReq(pdev, &pdev->request);
|
USBD_StdEPReq(pdev, &pdev->request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U));
|
USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
@@ -298,26 +300,25 @@ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
|||||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum, uint8_t *pdata)
|
uint8_t epnum, uint8_t *pdata)
|
||||||
{
|
{
|
||||||
USBD_EndpointTypeDef *pep;
|
USBD_EndpointTypeDef *pep;
|
||||||
|
|
||||||
if(epnum == 0U)
|
if (epnum == 0U)
|
||||||
{
|
{
|
||||||
pep = &pdev->ep_out[0];
|
pep = &pdev->ep_out[0];
|
||||||
|
|
||||||
if ( pdev->ep0_state == USBD_EP0_DATA_OUT)
|
if (pdev->ep0_state == USBD_EP0_DATA_OUT)
|
||||||
{
|
{
|
||||||
if(pep->rem_length > pep->maxpacket)
|
if (pep->rem_length > pep->maxpacket)
|
||||||
{
|
{
|
||||||
pep->rem_length -= pep->maxpacket;
|
pep->rem_length -= pep->maxpacket;
|
||||||
|
|
||||||
USBD_CtlContinueRx (pdev,
|
USBD_CtlContinueRx(pdev, pdata,
|
||||||
pdata,
|
(uint16_t)MIN(pep->rem_length, pep->maxpacket));
|
||||||
(uint16_t)MIN(pep->rem_length, pep->maxpacket));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if((pdev->pClass->EP0_RxReady != NULL)&&
|
if ((pdev->pClass->EP0_RxReady != NULL) &&
|
||||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||||
{
|
{
|
||||||
pdev->pClass->EP0_RxReady(pdev);
|
pdev->pClass->EP0_RxReady(pdev);
|
||||||
}
|
}
|
||||||
@@ -336,8 +337,8 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if((pdev->pClass->DataOut != NULL) &&
|
else if ((pdev->pClass->DataOut != NULL) &&
|
||||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||||
{
|
{
|
||||||
pdev->pClass->DataOut(pdev, epnum);
|
pdev->pClass->DataOut(pdev, epnum);
|
||||||
}
|
}
|
||||||
@@ -357,42 +358,43 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum,
|
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pdata)
|
uint8_t epnum, uint8_t *pdata)
|
||||||
{
|
{
|
||||||
USBD_EndpointTypeDef *pep;
|
USBD_EndpointTypeDef *pep;
|
||||||
|
|
||||||
if(epnum == 0U)
|
if (epnum == 0U)
|
||||||
{
|
{
|
||||||
pep = &pdev->ep_in[0];
|
pep = &pdev->ep_in[0];
|
||||||
|
|
||||||
if ( pdev->ep0_state == USBD_EP0_DATA_IN)
|
if (pdev->ep0_state == USBD_EP0_DATA_IN)
|
||||||
{
|
{
|
||||||
if(pep->rem_length > pep->maxpacket)
|
if (pep->rem_length > pep->maxpacket)
|
||||||
{
|
{
|
||||||
pep->rem_length -= pep->maxpacket;
|
pep->rem_length -= pep->maxpacket;
|
||||||
|
|
||||||
USBD_CtlContinueSendData (pdev, pdata, (uint16_t)pep->rem_length);
|
USBD_CtlContinueSendData(pdev, pdata, (uint16_t)pep->rem_length);
|
||||||
|
|
||||||
/* Prepare endpoint for premature end of transfer */
|
/* Prepare endpoint for premature end of transfer */
|
||||||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U);
|
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* last packet is MPS multiple, so send ZLP packet */
|
{
|
||||||
if((pep->total_length % pep->maxpacket == 0U) &&
|
/* last packet is MPS multiple, so send ZLP packet */
|
||||||
(pep->total_length >= pep->maxpacket) &&
|
if ((pep->total_length % pep->maxpacket == 0U) &&
|
||||||
(pep->total_length < pdev->ep0_data_len))
|
(pep->total_length >= pep->maxpacket) &&
|
||||||
|
(pep->total_length < pdev->ep0_data_len))
|
||||||
{
|
{
|
||||||
USBD_CtlContinueSendData(pdev, NULL, 0U);
|
USBD_CtlContinueSendData(pdev, NULL, 0U);
|
||||||
pdev->ep0_data_len = 0U;
|
pdev->ep0_data_len = 0U;
|
||||||
|
|
||||||
/* Prepare endpoint for premature end of transfer */
|
/* Prepare endpoint for premature end of transfer */
|
||||||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U);
|
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if((pdev->pClass->EP0_TxSent != NULL)&&
|
if ((pdev->pClass->EP0_TxSent != NULL) &&
|
||||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||||
{
|
{
|
||||||
pdev->pClass->EP0_TxSent(pdev);
|
pdev->pClass->EP0_TxSent(pdev);
|
||||||
}
|
}
|
||||||
@@ -416,8 +418,8 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum,
|
|||||||
pdev->dev_test_mode = 0U;
|
pdev->dev_test_mode = 0U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if((pdev->pClass->DataIn != NULL) &&
|
else if ((pdev->pClass->DataIn != NULL) &&
|
||||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||||
{
|
{
|
||||||
pdev->pClass->DataIn(pdev, epnum);
|
pdev->pClass->DataIn(pdev, epnum);
|
||||||
}
|
}
|
||||||
@@ -437,7 +439,7 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum,
|
|||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Open EP0 OUT */
|
/* Open EP0 OUT */
|
||||||
USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
||||||
@@ -450,10 +452,11 @@ USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
|||||||
pdev->ep_in[0x80U & 0xFU].is_used = 1U;
|
pdev->ep_in[0x80U & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
|
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||||
|
|
||||||
/* Upon Reset call user call back */
|
/* Upon Reset call user call back */
|
||||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||||
pdev->ep0_state = USBD_EP0_IDLE;
|
pdev->ep0_state = USBD_EP0_IDLE;
|
||||||
pdev->dev_config= 0U;
|
pdev->dev_config = 0U;
|
||||||
pdev->dev_remote_wakeup = 0U;
|
pdev->dev_remote_wakeup = 0U;
|
||||||
|
|
||||||
if (pdev->pClassData)
|
if (pdev->pClassData)
|
||||||
@@ -470,9 +473,11 @@ USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed)
|
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_SpeedTypeDef speed)
|
||||||
{
|
{
|
||||||
pdev->dev_speed = speed;
|
pdev->dev_speed = speed;
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,10 +488,11 @@ USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef
|
|||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
pdev->dev_old_state = pdev->dev_state;
|
pdev->dev_old_state = pdev->dev_state;
|
||||||
pdev->dev_state = USBD_STATE_SUSPENDED;
|
pdev->dev_state = USBD_STATE_SUSPENDED;
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,9 +503,13 @@ USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
|||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
pdev->dev_state = pdev->dev_old_state;
|
if (pdev->dev_state == USBD_STATE_SUSPENDED)
|
||||||
|
{
|
||||||
|
pdev->dev_state = pdev->dev_old_state;
|
||||||
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,15 +520,16 @@ USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
|||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
if(pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
if(pdev->pClass->SOF != NULL)
|
if (pdev->pClass->SOF != NULL)
|
||||||
{
|
{
|
||||||
pdev->pClass->SOF(pdev);
|
pdev->pClass->SOF(pdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,7 +539,8 @@ USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
/* Prevent unused arguments compilation warning */
|
/* Prevent unused arguments compilation warning */
|
||||||
UNUSED(pdev);
|
UNUSED(pdev);
|
||||||
@@ -543,7 +555,8 @@ USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t ep
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
/* Prevent unused arguments compilation warning */
|
/* Prevent unused arguments compilation warning */
|
||||||
UNUSED(pdev);
|
UNUSED(pdev);
|
||||||
@@ -558,7 +571,7 @@ USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t e
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Prevent unused argument compilation warning */
|
/* Prevent unused argument compilation warning */
|
||||||
UNUSED(pdev);
|
UNUSED(pdev);
|
||||||
@@ -572,7 +585,7 @@ USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Free Class Resources */
|
/* Free Class Resources */
|
||||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,8 +3,8 @@
|
|||||||
* @file usbd_desc_template.c
|
* @file usbd_desc_template.c
|
||||||
* @author MCD Application Team
|
* @author MCD Application Team
|
||||||
* @brief This file provides the USBD descriptors and string formatting method.
|
* @brief This file provides the USBD descriptors and string formatting method.
|
||||||
* This template should be copied to the user folder, renamed and customized
|
* This template should be copied to the user folder,
|
||||||
* following user needs.
|
* renamed and customized following user needs.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -41,17 +41,18 @@
|
|||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
#ifdef USB_SUPPORT_USER_STRING_DESC
|
#ifdef USBD_SUPPORT_USER_STRING_DESC
|
||||||
uint8_t *USBD_Class_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
uint8_t *USBD_Class_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
USBD_DescriptorsTypeDef Class_Desc = {
|
USBD_DescriptorsTypeDef Class_Desc =
|
||||||
|
{
|
||||||
USBD_Class_DeviceDescriptor,
|
USBD_Class_DeviceDescriptor,
|
||||||
USBD_Class_LangIDStrDescriptor,
|
USBD_Class_LangIDStrDescriptor,
|
||||||
USBD_Class_ManufacturerStrDescriptor,
|
USBD_Class_ManufacturerStrDescriptor,
|
||||||
@@ -63,9 +64,10 @@ USBD_DescriptorsTypeDef Class_Desc = {
|
|||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif
|
||||||
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
|
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
0x12, /* bLength */
|
0x12, /* bLength */
|
||||||
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
|
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
|
||||||
0x00, /* bcdUSB */
|
0x00, /* bcdUSB */
|
||||||
@@ -88,9 +90,10 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
|
|||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif
|
||||||
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
|
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
USB_LEN_LANGID_STR_DESC,
|
USB_LEN_LANGID_STR_DESC,
|
||||||
USB_DESC_TYPE_STRING,
|
USB_DESC_TYPE_STRING,
|
||||||
LOBYTE(USBD_LANGID_STRING),
|
LOBYTE(USBD_LANGID_STRING),
|
||||||
@@ -104,12 +107,12 @@ uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif
|
||||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
|
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len);
|
||||||
static void Get_SerialNum(void);
|
static void Get_SerialNum(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,7 +124,7 @@ static void Get_SerialNum(void);
|
|||||||
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof(USBD_DeviceDesc);
|
*length = sizeof(USBD_DeviceDesc);
|
||||||
return (uint8_t*)USBD_DeviceDesc;
|
return (uint8_t *)USBD_DeviceDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,7 +136,7 @@ uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
|||||||
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof(USBD_LangIDDesc);
|
*length = sizeof(USBD_LangIDDesc);
|
||||||
return (uint8_t*)USBD_LangIDDesc;
|
return (uint8_t *)USBD_LangIDDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,7 +147,7 @@ uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
if(speed == USBD_SPEED_HIGH)
|
if (speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
@@ -180,7 +183,7 @@ uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
|
|||||||
/* Update the serial number string descriptor with the data from the unique ID*/
|
/* Update the serial number string descriptor with the data from the unique ID*/
|
||||||
Get_SerialNum();
|
Get_SerialNum();
|
||||||
|
|
||||||
return (uint8_t*)USBD_StringSerial;
|
return (uint8_t *)USBD_StringSerial;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,7 +194,7 @@ uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
if(speed == USBD_SPEED_HIGH)
|
if (speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
@@ -210,7 +213,7 @@ uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
if(speed == USBD_SPEED_HIGH)
|
if (speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
@@ -230,16 +233,16 @@ static void Get_SerialNum(void)
|
|||||||
{
|
{
|
||||||
uint32_t deviceserial0, deviceserial1, deviceserial2;
|
uint32_t deviceserial0, deviceserial1, deviceserial2;
|
||||||
|
|
||||||
deviceserial0 = *(uint32_t*)DEVICE_ID1;
|
deviceserial0 = *(uint32_t *)DEVICE_ID1;
|
||||||
deviceserial1 = *(uint32_t*)DEVICE_ID2;
|
deviceserial1 = *(uint32_t *)DEVICE_ID2;
|
||||||
deviceserial2 = *(uint32_t*)DEVICE_ID3;
|
deviceserial2 = *(uint32_t *)DEVICE_ID3;
|
||||||
|
|
||||||
deviceserial0 += deviceserial2;
|
deviceserial0 += deviceserial2;
|
||||||
|
|
||||||
if (deviceserial0 != 0)
|
if (deviceserial0 != 0U)
|
||||||
{
|
{
|
||||||
IntToUnicode (deviceserial0, &USBD_StringSerial[2] ,8);
|
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8U);
|
||||||
IntToUnicode (deviceserial1, &USBD_StringSerial[18] ,4);
|
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4U);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,24 +253,24 @@ static void Get_SerialNum(void)
|
|||||||
* @param len: buffer length
|
* @param len: buffer length
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
|
||||||
{
|
{
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0U;
|
||||||
|
|
||||||
for( idx = 0 ; idx < len ; idx ++)
|
for (idx = 0U ; idx < len ; idx ++)
|
||||||
{
|
{
|
||||||
if( ((value >> 28)) < 0xA )
|
if (((value >> 28)) < 0xAU)
|
||||||
{
|
{
|
||||||
pbuf[ 2* idx] = (value >> 28) + '0';
|
pbuf[ 2U * idx] = (value >> 28) + '0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pbuf[2* idx] = (value >> 28) + 'A' - 10;
|
pbuf[2U * idx] = (value >> 28) + 'A' - 10U;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = value << 4;
|
value = value << 4;
|
||||||
|
|
||||||
pbuf[ 2* idx + 1] = 0;
|
pbuf[2U * idx + 1] = 0U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -84,16 +84,16 @@
|
|||||||
* @param len: length of data to be sent
|
* @param len: length of data to be sent
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||||
uint16_t len)
|
uint8_t *pbuf, uint16_t len)
|
||||||
{
|
{
|
||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_DATA_IN;
|
pdev->ep0_state = USBD_EP0_DATA_IN;
|
||||||
pdev->ep_in[0].total_length = len;
|
pdev->ep_in[0].total_length = len;
|
||||||
pdev->ep_in[0].rem_length = len;
|
pdev->ep_in[0].rem_length = len;
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
USBD_LL_Transmit (pdev, 0x00U, pbuf, len);
|
USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -106,11 +106,11 @@ USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
|||||||
* @param len: length of data to be sent
|
* @param len: length of data to be sent
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf, uint16_t len)
|
uint8_t *pbuf, uint16_t len)
|
||||||
{
|
{
|
||||||
/* Start the next transfer */
|
/* Start the next transfer */
|
||||||
USBD_LL_Transmit (pdev, 0x00U, pbuf, len);
|
USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -123,8 +123,8 @@ USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
|
|||||||
* @param len: length of data to be received
|
* @param len: length of data to be received
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||||
uint16_t len)
|
uint8_t *pbuf, uint16_t len)
|
||||||
{
|
{
|
||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||||
@@ -132,7 +132,7 @@ USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
|||||||
pdev->ep_out[0].rem_length = len;
|
pdev->ep_out[0].rem_length = len;
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
USBD_LL_PrepareReceive (pdev, 0U, pbuf, len);
|
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -145,8 +145,8 @@ USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
|||||||
* @param len: length of data to be received
|
* @param len: length of data to be received
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||||
uint16_t len)
|
uint8_t *pbuf, uint16_t len)
|
||||||
{
|
{
|
||||||
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
||||||
@@ -176,13 +176,13 @@ USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U);
|
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev)
|
|||||||
* @param ep_addr: endpoint address
|
* @param ep_addr: endpoint address
|
||||||
* @retval Rx Data blength
|
* @retval Rx Data blength
|
||||||
*/
|
*/
|
||||||
uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ Note that:
|
|||||||
USB Device | HAL |
|
USB Device | HAL |
|
||||||
---------- | ---------- |
|
---------- | ---------- |
|
||||||
Tag v2.5.1 | Tag v1.10.2 ([stm32l0xx_hal_driver](https://github.com/STMicroelectronics/stm32l0xx_hal_driver))
|
Tag v2.5.1 | Tag v1.10.2 ([stm32l0xx_hal_driver](https://github.com/STMicroelectronics/stm32l0xx_hal_driver))
|
||||||
|
Tag v2.5.2 | Tag v1.4.0 ([stm32l1xx_hal_driver](https://github.com/STMicroelectronics/stm32l1xx_hal_driver))
|
||||||
|
Tag v2.5.3 | Tag v1.7.3 ([stm32f0xx_hal_driver](https://github.com/STMicroelectronics/stm32f0xx_hal_driver))<br>Tag v1.1.4 ([stm32f1xx_hal_driver](https://github.com/STMicroelectronics/stm32f1xx_hal_driver))<br>Tag v1.2.4 ([stm32f2xx_hal_driver](https://github.com/STMicroelectronics/stm32f2xx_hal_driver))<br>Tag v1.5.3 ([stm32f3xx_hal_driver](https://github.com/STMicroelectronics/stm32f3xx_hal_driver))
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
|
|||||||
@@ -923,7 +923,54 @@ ul
|
|||||||
<tbody><tr style="">
|
<tbody><tr style="">
|
||||||
<td style="padding: 0in;" valign="top">
|
<td style="padding: 0in;" valign="top">
|
||||||
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update History</span></h2>
|
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update History</span></h2>
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.1 / 03-August-2018<br>
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.3 / 30-April-2019</span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
|
Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; color: black;"><o:p></o:p></span></u></p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<ul style="margin-top: 0cm;" type="square"><li>Fix misra-c 2012 high severity violations</li><li>Core driver:</li><ul><li>protect shared macros __ALIGN_BEGIN, __ALIGN_END with C directive #ifndef</li><li>update Core driver and DFU Class driver to use USBD_SUPPORT_USER_STRING_DESC insead of USBD_SUPPORT_USER_STRING</li><li> prevent accessing to NULL pointer if the get descriptor functions are not defined</li><li>Update on USBD_LL_Resume(), restore the device state only if the current state is USBD_STATE_SUSPENDED </li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.2 / 27-Mars-2019</span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
|
Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; color: black;"><o:p></o:p></span></u></p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<ul style="margin-top: 0cm;" type="square"><li><span style="font-family: Verdana; font-size: 10pt;">DFU Class:</span></li><ul><li><span style="font-family: Verdana; font-size: 10pt;"></span><span style="font-size: 10pt; font-family: "Verdana",sans-serif;" lang="EN-US"></span><span style="font-family: Verdana; font-size: 10pt;"></span>fix compilation warning due to <span style="font-size: 11pt; font-family: "Calibri",sans-serif;" lang="EN-US">unreachable
|
||||||
|
</span> instruction code introduced with CMSIS V5.4.0 NVIC_SystemReset() prototype change</li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.1 / 03-August-2018<br>
|
||||||
</span></h3>
|
</span></h3>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user