usbd_msc_core.c
Go to the documentation of this file.
1 
43 /* Includes ------------------------------------------------------------------*/
44 #include "usbd_msc_mem.h"
45 #include "usbd_msc_core.h"
46 #include "usbd_msc_bot.h"
47 #include "usbd_req.h"
48 
49 #define UNUSED(x) (void)(x)
50 
89 uint8_t USBD_MSC_Init (void *pdev,
90  uint8_t cfgidx);
91 
92 uint8_t USBD_MSC_DeInit (void *pdev,
93  uint8_t cfgidx);
94 
95 uint8_t USBD_MSC_Setup (void *pdev,
96  USB_SETUP_REQ *req);
97 
98 uint8_t USBD_MSC_DataIn (void *pdev,
99  uint8_t epnum);
100 
101 
102 uint8_t USBD_MSC_DataOut (void *pdev,
103  uint8_t epnum);
104 
105 uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed,
106  uint16_t *length);
107 
108 #ifdef USB_OTG_HS_CORE
109 uint8_t *USBD_MSC_GetOtherCfgDesc (uint8_t speed,
110  uint16_t *length);
111 #endif
112 
113 
115 
116 
117 
118 
130 {
134  NULL, /*EP0_TxSent*/
135  NULL, /*EP0_RxReady*/
138  NULL, /*SOF */
139  NULL,
140  NULL,
142 #ifdef USB_OTG_HS_CORE
143  USBD_MSC_GetOtherCfgDesc,
144 #endif
145 };
146 
147 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
148  #if defined ( __ICCARM__ )
149  #pragma data_alignment=4
150  #endif
151 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
152 /* USB Mass storage device Configuration Descriptor */
153 /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
155 {
156 
157  0x09, /* bLength: Configuation Descriptor size */
158  USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
160 
161  0x00,
162  0x01, /* bNumInterfaces: 1 interface */
163  0x01, /* bConfigurationValue: */
164  0x04, /* iConfiguration: */
165  0xC0, /* bmAttributes: */
166  0x32, /* MaxPower 100 mA */
167 
168  /******************** Mass Storage interface ********************/
169  0x09, /* bLength: Interface Descriptor size */
170  0x04, /* bDescriptorType: */
171  0x00, /* bInterfaceNumber: Number of Interface */
172  0x00, /* bAlternateSetting: Alternate setting */
173  0x02, /* bNumEndpoints*/
174  0x08, /* bInterfaceClass: MSC Class */
175  0x06, /* bInterfaceSubClass : SCSI transparent*/
176  0x50, /* nInterfaceProtocol */
177  0x05, /* iInterface: */
178  /******************** Mass Storage Endpoints ********************/
179  0x07, /*Endpoint descriptor length = 7*/
180  0x05, /*Endpoint descriptor type */
181  MSC_IN_EP, /*Endpoint address (IN, address 1) */
182  0x02, /*Bulk endpoint type */
185  0x00, /*Polling interval in milliseconds */
186 
187  0x07, /*Endpoint descriptor length = 7 */
188  0x05, /*Endpoint descriptor type */
189  MSC_OUT_EP, /*Endpoint address (OUT, address 1) */
190  0x02, /*Bulk endpoint type */
193  0x00 /*Polling interval in milliseconds*/
194 };
195 #ifdef USB_OTG_HS_CORE
196  #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
197  #if defined ( __ICCARM__ )
198  #pragma data_alignment=4
199  #endif
200  #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
201 __ALIGN_BEGIN uint8_t USBD_MSC_OtherCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
202 {
203 
204  0x09, /* bLength: Configuation Descriptor size */
207 
208  0x00,
209  0x01, /* bNumInterfaces: 1 interface */
210  0x01, /* bConfigurationValue: */
211  0x04, /* iConfiguration: */
212  0xC0, /* bmAttributes: */
213  0x32, /* MaxPower 100 mA */
214 
215  /******************** Mass Storage interface ********************/
216  0x09, /* bLength: Interface Descriptor size */
217  0x04, /* bDescriptorType: */
218  0x00, /* bInterfaceNumber: Number of Interface */
219  0x00, /* bAlternateSetting: Alternate setting */
220  0x02, /* bNumEndpoints*/
221  0x08, /* bInterfaceClass: MSC Class */
222  0x06, /* bInterfaceSubClass : SCSI transparent command set*/
223  0x50, /* nInterfaceProtocol */
224  0x05, /* iInterface: */
225  /******************** Mass Storage Endpoints ********************/
226  0x07, /*Endpoint descriptor length = 7*/
227  0x05, /*Endpoint descriptor type */
228  MSC_IN_EP, /*Endpoint address (IN, address 1) */
229  0x02, /*Bulk endpoint type */
230  0x40,
231  0x00,
232  0x00, /*Polling interval in milliseconds */
233 
234  0x07, /*Endpoint descriptor length = 7 */
235  0x05, /*Endpoint descriptor type */
236  MSC_OUT_EP, /*Endpoint address (OUT, address 1) */
237  0x02, /*Bulk endpoint type */
238  0x40,
239  0x00,
240  0x00 /*Polling interval in milliseconds*/
241 };
242 #endif
243 
244 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
245  #if defined ( __ICCARM__ )
246  #pragma data_alignment=4
247  #endif
248 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
249 __ALIGN_BEGIN static uint8_t USBD_MSC_MaxLun __ALIGN_END = 0;
250 
251 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
252  #if defined ( __ICCARM__ )
253  #pragma data_alignment=4
254  #endif
255 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
256 __ALIGN_BEGIN static uint8_t USBD_MSC_AltSet __ALIGN_END = 0;
257 
274 uint8_t USBD_MSC_Init (void *pdev,
275  uint8_t cfgidx)
276 {
277  USBD_MSC_DeInit(pdev , cfgidx );
278 
279  /* Open EP IN */
280  DCD_EP_Open(pdev,
281  MSC_IN_EP,
284 
285  /* Open EP OUT */
286  DCD_EP_Open(pdev,
287  MSC_OUT_EP,
290 
291  /* Init the BOT layer */
292  MSC_BOT_Init(pdev);
293 
294  return USBD_OK;
295 }
296 
304 uint8_t USBD_MSC_DeInit (void *pdev,
305  uint8_t cfgidx)
306 {
307  UNUSED(cfgidx);
308  /* Close MSC EPs */
309  DCD_EP_Close (pdev , MSC_IN_EP);
310  DCD_EP_Close (pdev , MSC_OUT_EP);
311 
312  /* Un Init the BOT layer */
313  MSC_BOT_DeInit(pdev);
314  return USBD_OK;
315 }
323 uint8_t USBD_MSC_Setup (void *pdev, USB_SETUP_REQ *req)
324 {
325 
326  switch (req->bmRequest & USB_REQ_TYPE_MASK)
327  {
328 
329  /* Class request */
330  case USB_REQ_TYPE_CLASS :
331  switch (req->bRequest)
332  {
333  case BOT_GET_MAX_LUN :
334 
335  if((req->wValue == 0) &&
336  (req->wLength == 1) &&
337  ((req->bmRequest & 0x80) == 0x80))
338  {
339  USBD_MSC_MaxLun = USBD_STORAGE_fops->GetMaxLun();
340  if(USBD_MSC_MaxLun > 0)
341  {
342  USBD_CtlSendData (pdev,
343  &USBD_MSC_MaxLun,
344  1);
345  }
346  else
347  {
348  USBD_CtlError(pdev , req);
349  return USBD_FAIL;
350 
351  }
352  }
353  else
354  {
355  USBD_CtlError(pdev , req);
356  return USBD_FAIL;
357  }
358  break;
359 
360  case BOT_RESET :
361  if((req->wValue == 0) &&
362  (req->wLength == 0) &&
363  ((req->bmRequest & 0x80) != 0x80))
364  {
365  MSC_BOT_Reset(pdev);
366  }
367  else
368  {
369  USBD_CtlError(pdev , req);
370  return USBD_FAIL;
371  }
372  break;
373 
374  default:
375  USBD_CtlError(pdev , req);
376  return USBD_FAIL;
377  }
378  break;
379  /* Interface & Endpoint request */
381  switch (req->bRequest)
382  {
383  case USB_REQ_GET_INTERFACE :
384  USBD_CtlSendData (pdev,
385  &USBD_MSC_AltSet,
386  1);
387  break;
388 
389  case USB_REQ_SET_INTERFACE :
390  USBD_MSC_AltSet = (uint8_t)(req->wValue);
391  break;
392 
394 
395  /* Flush the FIFO and Clear the stall status */
396  DCD_EP_Flush(pdev, (uint8_t)req->wIndex);
397 
398  /* Re-activate the EP */
399  DCD_EP_Close (pdev , (uint8_t)req->wIndex);
400  if((((uint8_t)req->wIndex) & 0x80) == 0x80)
401  {
402  DCD_EP_Open(pdev,
403  ((uint8_t)req->wIndex),
406  }
407  else
408  {
409  DCD_EP_Open(pdev,
410  ((uint8_t)req->wIndex),
413  }
414 
415  /* Handle BOT error */
416  MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
417  break;
418 
419  }
420  break;
421 
422  default:
423  break;
424  }
425  return USBD_OK;
426 }
427 
435 uint8_t USBD_MSC_DataIn (void *pdev,
436  uint8_t epnum)
437 {
438  MSC_BOT_DataIn(pdev , epnum);
439  return USBD_OK;
440 }
441 
449 uint8_t USBD_MSC_DataOut (void *pdev,
450  uint8_t epnum)
451 {
452  MSC_BOT_DataOut(pdev , epnum);
453  return USBD_OK;
454 }
455 
463 uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed, uint16_t *length)
464 {
465  UNUSED(speed);
466  *length = sizeof (USBD_MSC_CfgDesc);
467  return USBD_MSC_CfgDesc;
468 }
469 
477 #ifdef USB_OTG_HS_CORE
478 uint8_t *USBD_MSC_GetOtherCfgDesc (uint8_t speed,
479  uint16_t *length)
480 {
481  *length = sizeof (USBD_MSC_OtherCfgDesc);
482  return USBD_MSC_OtherCfgDesc;
483 }
484 #endif
485 
499 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void USBD_CtlError(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req)
USBD_CtlError Handle USB low level Error.
Definition: usbd_req.c:813
#define USB_REQ_TYPE_STANDARD
Definition: usbd_def.h:67
#define BOT_RESET
Definition: usbd_msc_core.h:50
uint8_t USBD_MSC_DeInit(void *pdev, uint8_t cfgidx)
USBD_MSC_DeInit DeInitilaize the mass storage configuration.
#define MSC_IN_EP
Definition: usbd_conf.h:66
header file for the usbd_req.c file
uint32_t DCD_EP_Close(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr)
called when an EP is disabled
Definition: usb_dcd.c:204
void MSC_BOT_DeInit(USB_OTG_CORE_HANDLE *pdev)
MSC_BOT_DeInit Uninitialize the BOT Machine.
Definition: usbd_msc_bot.c:168
uint8_t USBD_MSC_Init(void *pdev, uint8_t cfgidx)
USBD_MSC_Init Initialize the mass storage configuration.
#define USB_REQ_TYPE_CLASS
Definition: usbd_def.h:68
USBD_Status USBD_CtlSendData(USB_OTG_CORE_HANDLE *pdev, uint8_t *buf, uint16_t len)
USBD_CtlSendData send data on the ctl pipe.
Definition: usbd_ioreq.c:95
#define USB_REQ_SET_INTERFACE
Definition: usbd_def.h:86
#define USB_REQ_GET_INTERFACE
Definition: usbd_def.h:85
uint32_t DCD_EP_Flush(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
This Function flushes the FIFOs.
Definition: usb_dcd.c:360
#define UNUSED(x)
Definition: usbd_msc_core.c:49
header for the STORAGE DISK file file
header for the usbd_msc_core.c file
void MSC_BOT_Reset(USB_OTG_CORE_HANDLE *pdev)
MSC_BOT_Reset Reset the BOT Machine.
Definition: usbd_msc_bot.c:151
uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ]
uint8_t USBD_MSC_DataIn(void *pdev, uint8_t epnum)
USBD_MSC_DataIn handle data IN Stage.
uint8_t USBD_MSC_DataOut(void *pdev, uint8_t epnum)
USBD_MSC_DataOut handle data OUT Stage.
uint16_t wIndex
Definition: usb_core.h:185
uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
Configure an EP.
Definition: usb_dcd.c:165
#define __ALIGN_BEGIN
uint8_t bmRequest
Definition: usb_core.h:182
#define USB_OTG_EP_BULK
Definition: usb_dcd.h:51
int8_t(* GetMaxLun)(void)
Definition: usbd_msc_mem.h:66
#define MSC_OUT_EP
Definition: usbd_conf.h:67
#define USB_REQ_CLEAR_FEATURE
Definition: usbd_def.h:78
USBD_Class_cb_TypeDef USBD_MSC_cb
void MSC_BOT_DataIn(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
MSC_BOT_DataIn Handle BOT IN data stage.
Definition: usbd_msc_bot.c:181
USBD_STORAGE_cb_TypeDef * USBD_STORAGE_fops
uint16_t wLength
Definition: usb_core.h:186
void MSC_BOT_CplClrFeature(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
MSC_BOT_CplClrFeature Complete the clear feature request.
Definition: usbd_msc_bot.c:377
uint8_t bRequest
Definition: usb_core.h:183
uint8_t USBD_MSC_Setup(void *pdev, USB_SETUP_REQ *req)
USBD_MSC_Setup Handle the MSC specific requests.
#define NULL
Definition: usbd_def.h:50
#define HIBYTE(x)
Definition: usbd_def.h:126
#define LOBYTE(x)
Definition: usbd_def.h:125
#define BOT_GET_MAX_LUN
Definition: usbd_msc_core.h:49
#define USB_MSC_CONFIG_DESC_SIZ
Definition: usbd_msc_core.h:51
#define MSC_EPOUT_SIZE
Definition: usbd_msc_core.h:54
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION
Definition: usbd_def.h:95
#define MSC_EPIN_SIZE
Definition: usbd_msc_core.h:53
#define USB_DESC_TYPE_CONFIGURATION
Definition: usbd_def.h:90
#define USB_REQ_TYPE_MASK
Definition: usbd_def.h:70
__ALIGN_BEGIN uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END
header for the usbd_msc_bot.c file
void MSC_BOT_Init(USB_OTG_CORE_HANDLE *pdev)
MSC_BOT_Init Initialize the BOT Process.
Definition: usbd_msc_bot.c:130
#define MSC_MAX_PACKET
Definition: usbd_conf.h:75
uint16_t wValue
Definition: usb_core.h:184
void MSC_BOT_DataOut(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
MSC_BOT_DataOut Proccess MSC OUT data.
Definition: usbd_msc_bot.c:213
uint8_t * USBD_MSC_GetCfgDesc(uint8_t speed, uint16_t *length)
USBD_MSC_GetCfgDesc return configuration descriptor.


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:26