Prusa MINI Firmware overview
USBH_CTLREQ_Private_Functions
Collaboration diagram for USBH_CTLREQ_Private_Functions:

Functions

USBH_StatusTypeDef USBH_Get_DevDesc (USBH_HandleTypeDef *phost, uint8_t length)
 USBH_Get_DevDesc Issue Get Device Descriptor command to the device. Once the response received, it parses the device descriptor and updates the status. More...
 
USBH_StatusTypeDef USBH_Get_CfgDesc (USBH_HandleTypeDef *phost, uint16_t length)
 USBH_Get_CfgDesc Issues Configuration Descriptor to the device. Once the response received, it parses the configuration descriptor and updates the status. More...
 
USBH_StatusTypeDef USBH_Get_StringDesc (USBH_HandleTypeDef *phost, uint8_t string_index, uint8_t *buff, uint16_t length)
 USBH_Get_StringDesc Issues string Descriptor command to the device. Once the response received, it parses the string descriptor and updates the status. More...
 
USBH_StatusTypeDef USBH_GetDescriptor (USBH_HandleTypeDef *phost, uint8_t req_type, uint16_t value_idx, uint8_t *buff, uint16_t length)
 USBH_GetDescriptor Issues Descriptor command to the device. Once the response received, it parses the descriptor and updates the status. More...
 
USBH_StatusTypeDef USBH_SetAddress (USBH_HandleTypeDef *phost, uint8_t DeviceAddress)
 USBH_SetAddress This command sets the address to the connected device. More...
 
USBH_StatusTypeDef USBH_SetCfg (USBH_HandleTypeDef *phost, uint16_t cfg_idx)
 USBH_SetCfg The command sets the configuration value to the connected device. More...
 
USBH_StatusTypeDef USBH_SetInterface (USBH_HandleTypeDef *phost, uint8_t ep_num, uint8_t altSetting)
 USBH_SetInterface The command sets the Interface value to the connected device. More...
 
USBH_StatusTypeDef USBH_ClrFeature (USBH_HandleTypeDef *phost, uint8_t ep_num)
 USBH_ClrFeature This request is used to clear or disable a specific feature. More...
 
USBH_DescHeader_tUSBH_GetNextDesc (uint8_t *pbuf, uint16_t *ptr)
 USBH_GetNextDesc This function return the next descriptor header. More...
 
USBH_StatusTypeDef USBH_CtlReq (USBH_HandleTypeDef *phost, uint8_t *buff, uint16_t length)
 USBH_CtlReq USBH_CtlReq sends a control request and provide the status after completion of the request. More...
 
static void USBH_ParseDevDesc (USBH_DevDescTypeDef *dev_desc, uint8_t *buf, uint16_t length)
 USBH_ParseDevDesc This function Parses the device descriptor. More...
 
static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef *cfg_desc, uint8_t *buf, uint16_t length)
 USBH_ParseCfgDesc This function Parses the configuration descriptor. More...
 
static void USBH_ParseInterfaceDesc (USBH_InterfaceDescTypeDef *if_descriptor, uint8_t *buf)
 USBH_ParseInterfaceDesc This function Parses the interface descriptor. More...
 
static void USBH_ParseEPDesc (USBH_EpDescTypeDef *ep_descriptor, uint8_t *buf)
 USBH_ParseEPDesc This function Parses the endpoint descriptor. More...
 
static void USBH_ParseStringDesc (uint8_t *psrc, uint8_t *pdest, uint16_t length)
 USBH_ParseStringDesc This function Parses the string descriptor. More...
 
static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost)
 USBH_HandleControl Handles the USB control transfer state machine. More...
 

Detailed Description

Function Documentation

◆ USBH_Get_DevDesc()

USBH_StatusTypeDef USBH_Get_DevDesc ( USBH_HandleTypeDef phost,
uint8_t  length 
)

USBH_Get_DevDesc Issue Get Device Descriptor command to the device. Once the response received, it parses the device descriptor and updates the status.

Parameters
phostHost Handle
lengthLength of the descriptor
Return values
USBHStatus
113 {
115 
116  if((status = USBH_GetDescriptor(phost,
119  phost->device.Data,
120  length)) == USBH_OK)
121  {
122  /* Commands successfully sent and Response Received */
123  USBH_ParseDevDesc(&phost->device.DevDesc, phost->device.Data, length);
124  }
125  return status;
126 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_Get_CfgDesc()

USBH_StatusTypeDef USBH_Get_CfgDesc ( USBH_HandleTypeDef phost,
uint16_t  length 
)

USBH_Get_CfgDesc Issues Configuration Descriptor to the device. Once the response received, it parses the configuration descriptor and updates the status.

Parameters
phostHost Handle
lengthLength of the descriptor
Return values
USBHStatus
140 {
142  uint8_t *pData;
143 #if (USBH_KEEP_CFG_DESCRIPTOR == 1)
144  pData = phost->device.CfgDesc_Raw;
145 #else
146  pData = phost->device.Data;
147 #endif
148  if((status = USBH_GetDescriptor(phost,
151  pData,
152  length)) == USBH_OK)
153  {
154 
155  /* Commands successfully sent and Response Received */
157  pData,
158  length);
159 
160  }
161  return status;
162 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_Get_StringDesc()

USBH_StatusTypeDef USBH_Get_StringDesc ( USBH_HandleTypeDef phost,
uint8_t  string_index,
uint8_t buff,
uint16_t  length 
)

USBH_Get_StringDesc Issues string Descriptor command to the device. Once the response received, it parses the string descriptor and updates the status.

Parameters
phostHost Handle
string_indexString index for the descriptor
buffBuffer address for the descriptor
lengthLength of the descriptor
Return values
USBHStatus
179 {
181  if((status = USBH_GetDescriptor(phost,
183  USB_DESC_STRING | string_index,
184  phost->device.Data,
185  length)) == USBH_OK)
186  {
187  /* Commands successfully sent and Response Received */
188  USBH_ParseStringDesc(phost->device.Data,buff, length);
189  }
190  return status;
191 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_GetDescriptor()

USBH_StatusTypeDef USBH_GetDescriptor ( USBH_HandleTypeDef phost,
uint8_t  req_type,
uint16_t  value_idx,
uint8_t buff,
uint16_t  length 
)

USBH_GetDescriptor Issues Descriptor command to the device. Once the response received, it parses the descriptor and updates the status.

Parameters
phostHost Handle
req_typeDescriptor type
value_idxValue for the GetDescriptr request
buffBuffer to store the descriptor
lengthLength of the descriptor
Return values
USBHStatus
209 {
210  if(phost->RequestState == CMD_SEND)
211  {
212  phost->Control.setup.b.bmRequestType = USB_D2H | req_type;
214  phost->Control.setup.b.wValue.w = value_idx;
215 
216  if ((value_idx & 0xff00) == USB_DESC_STRING)
217  {
218  phost->Control.setup.b.wIndex.w = 0x0409;
219  }
220  else
221  {
222  phost->Control.setup.b.wIndex.w = 0;
223  }
224  phost->Control.setup.b.wLength.w = length;
225  }
226  return USBH_CtlReq(phost, buff , length );
227 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_SetAddress()

USBH_StatusTypeDef USBH_SetAddress ( USBH_HandleTypeDef phost,
uint8_t  DeviceAddress 
)

USBH_SetAddress This command sets the address to the connected device.

Parameters
phostHost Handle
DeviceAddressDevice address to assign
Return values
USBHStatus
238 {
239  if(phost->RequestState == CMD_SEND)
240  {
242  USB_REQ_TYPE_STANDARD;
243 
245 
246  phost->Control.setup.b.wValue.w = (uint16_t)DeviceAddress;
247  phost->Control.setup.b.wIndex.w = 0;
248  phost->Control.setup.b.wLength.w = 0;
249  }
250  return USBH_CtlReq(phost, 0 , 0 );
251 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_SetCfg()

USBH_StatusTypeDef USBH_SetCfg ( USBH_HandleTypeDef phost,
uint16_t  cfg_idx 
)

USBH_SetCfg The command sets the configuration value to the connected device.

Parameters
phostHost Handle
cfg_idxConfiguration value
Return values
USBHStatus
262 {
263  if(phost->RequestState == CMD_SEND)
264  {
266  USB_REQ_TYPE_STANDARD;
268  phost->Control.setup.b.wValue.w = cfg_idx;
269  phost->Control.setup.b.wIndex.w = 0;
270  phost->Control.setup.b.wLength.w = 0;
271  }
272 
273  return USBH_CtlReq(phost, 0 , 0 );
274 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_SetInterface()

USBH_StatusTypeDef USBH_SetInterface ( USBH_HandleTypeDef phost,
uint8_t  ep_num,
uint8_t  altSetting 
)

USBH_SetInterface The command sets the Interface value to the connected device.

Parameters
phostHost Handle
altSettingInterface value
Return values
USBHStatus
285 {
286 
287  if(phost->RequestState == CMD_SEND)
288  {
290  USB_REQ_TYPE_STANDARD;
291 
293  phost->Control.setup.b.wValue.w = altSetting;
294  phost->Control.setup.b.wIndex.w = ep_num;
295  phost->Control.setup.b.wLength.w = 0;
296  }
297  return USBH_CtlReq(phost, 0 , 0 );
298 }
Here is the call graph for this function:

◆ USBH_ClrFeature()

USBH_StatusTypeDef USBH_ClrFeature ( USBH_HandleTypeDef phost,
uint8_t  ep_num 
)

USBH_ClrFeature This request is used to clear or disable a specific feature.

Parameters
phostHost Handle
ep_numendpoint number
hc_numHost channel number
Return values
USBHStatus
310 {
311  if(phost->RequestState == CMD_SEND)
312  {
313  phost->Control.setup.b.bmRequestType = USB_H2D |
316 
319  phost->Control.setup.b.wIndex.w = ep_num;
320  phost->Control.setup.b.wLength.w = 0;
321  }
322  return USBH_CtlReq(phost, 0 , 0 );
323 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_GetNextDesc()

USBH_DescHeader_t* USBH_GetNextDesc ( uint8_t pbuf,
uint16_t *  ptr 
)

USBH_GetNextDesc This function return the next descriptor header.

Parameters
bufBuffer where the cfg descriptor is available
ptrdata pointer inside the cfg descriptor
Return values
nextheader
510 {
511  USBH_DescHeader_t *pnext;
512 
513  *ptr += ((USBH_DescHeader_t *)pbuf)->bLength;
514  pnext = (USBH_DescHeader_t *)((uint8_t *)pbuf + \
515  ((USBH_DescHeader_t *)pbuf)->bLength);
516 
517  return(pnext);
518 }
Here is the caller graph for this function:

◆ USBH_CtlReq()

USBH_StatusTypeDef USBH_CtlReq ( USBH_HandleTypeDef phost,
uint8_t buff,
uint16_t  length 
)

USBH_CtlReq USBH_CtlReq sends a control request and provide the status after completion of the request.

Parameters
phostHost Handle
reqSetup Request Structure
buffdata buffer address to store the response
lengthlength of the response
Return values
USBHStatus
534 {
536  status = USBH_BUSY;
537 
538  switch (phost->RequestState)
539  {
540  case CMD_SEND:
541  /* Start a SETUP transfer */
542  phost->Control.buff = buff;
543  phost->Control.length = length;
544  phost->Control.state = CTRL_SETUP;
545  phost->RequestState = CMD_WAIT;
546  status = USBH_BUSY;
547 #if (USBH_USE_OS == 1)
548  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
549 #endif
550  break;
551 
552  case CMD_WAIT:
553  status = USBH_HandleControl(phost);
554  if (status == USBH_OK)
555  {
556  /* Commands successfully sent and Response Received */
557  phost->RequestState = CMD_SEND;
558  phost->Control.state =CTRL_IDLE;
559  status = USBH_OK;
560  }
561  else if (status == USBH_FAIL)
562  {
563  /* Failure Mode */
564  phost->RequestState = CMD_SEND;
565  status = USBH_FAIL;
566  }
567  break;
568 
569  default:
570  break;
571  }
572  return status;
573 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_ParseDevDesc()

static void USBH_ParseDevDesc ( USBH_DevDescTypeDef dev_desc,
uint8_t buf,
uint16_t  length 
)
static

USBH_ParseDevDesc This function Parses the device descriptor.

Parameters
dev_descdevice_descriptor destination address
bufBuffer where the source descriptor is available
lengthLength of the descriptor
Return values
None
336 {
337  dev_desc->bLength = *(uint8_t *) (buf + 0);
338  dev_desc->bDescriptorType = *(uint8_t *) (buf + 1);
339  dev_desc->bcdUSB = LE16 (buf + 2);
340  dev_desc->bDeviceClass = *(uint8_t *) (buf + 4);
341  dev_desc->bDeviceSubClass = *(uint8_t *) (buf + 5);
342  dev_desc->bDeviceProtocol = *(uint8_t *) (buf + 6);
343  dev_desc->bMaxPacketSize = *(uint8_t *) (buf + 7);
344 
345  if (length > 8)
346  { /* For 1st time after device connection, Host may issue only 8 bytes for
347  Device Descriptor Length */
348  dev_desc->idVendor = LE16 (buf + 8);
349  dev_desc->idProduct = LE16 (buf + 10);
350  dev_desc->bcdDevice = LE16 (buf + 12);
351  dev_desc->iManufacturer = *(uint8_t *) (buf + 14);
352  dev_desc->iProduct = *(uint8_t *) (buf + 15);
353  dev_desc->iSerialNumber = *(uint8_t *) (buf + 16);
354  dev_desc->bNumConfigurations = *(uint8_t *) (buf + 17);
355  }
356 }
Here is the caller graph for this function:

◆ USBH_ParseCfgDesc()

static void USBH_ParseCfgDesc ( USBH_CfgDescTypeDef cfg_desc,
uint8_t buf,
uint16_t  length 
)
static

USBH_ParseCfgDesc This function Parses the configuration descriptor.

Parameters
cfg_descConfiguration Descriptor address
bufBuffer where the source descriptor is available
lengthLength of the descriptor
Return values
None
369 {
371  USBH_EpDescTypeDef *pep;
372  USBH_DescHeader_t *pdesc = (USBH_DescHeader_t *)buf;
373  uint16_t ptr;
374  int8_t if_ix = 0;
375  int8_t ep_ix = 0;
376 
377  pdesc = (USBH_DescHeader_t *)buf;
378 
379  /* Parse configuration descriptor */
380  cfg_desc->bLength = *(uint8_t *) (buf + 0);
381  cfg_desc->bDescriptorType = *(uint8_t *) (buf + 1);
382  cfg_desc->wTotalLength = LE16 (buf + 2);
383  cfg_desc->bNumInterfaces = *(uint8_t *) (buf + 4);
384  cfg_desc->bConfigurationValue = *(uint8_t *) (buf + 5);
385  cfg_desc->iConfiguration = *(uint8_t *) (buf + 6);
386  cfg_desc->bmAttributes = *(uint8_t *) (buf + 7);
387  cfg_desc->bMaxPower = *(uint8_t *) (buf + 8);
388 
389 
391  {
392  ptr = USB_LEN_CFG_DESC;
393  pif = (USBH_InterfaceDescTypeDef *)0;
394 
395 
396  while ((if_ix < USBH_MAX_NUM_INTERFACES ) && (ptr < cfg_desc->wTotalLength))
397  {
398  pdesc = USBH_GetNextDesc((uint8_t *)pdesc, &ptr);
400  {
401  pif = &cfg_desc->Itf_Desc[if_ix];
402  USBH_ParseInterfaceDesc (pif, (uint8_t *)pdesc);
403 
404  ep_ix = 0;
405  pep = (USBH_EpDescTypeDef *)0;
406  while ((ep_ix < pif->bNumEndpoints) && (ptr < cfg_desc->wTotalLength))
407  {
408  pdesc = USBH_GetNextDesc((uint8_t*) pdesc, &ptr);
410  {
411  pep = &cfg_desc->Itf_Desc[if_ix].Ep_Desc[ep_ix];
412  USBH_ParseEPDesc (pep, (uint8_t *)pdesc);
413  ep_ix++;
414  }
415  }
416  if_ix++;
417  }
418  }
419  }
420 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_ParseInterfaceDesc()

static void USBH_ParseInterfaceDesc ( USBH_InterfaceDescTypeDef if_descriptor,
uint8_t buf 
)
static

USBH_ParseInterfaceDesc This function Parses the interface descriptor.

Parameters
if_descriptor: Interface descriptor destination
bufBuffer where the descriptor data is available
Return values
None
433 {
434  if_descriptor->bLength = *(uint8_t *) (buf + 0);
435  if_descriptor->bDescriptorType = *(uint8_t *) (buf + 1);
436  if_descriptor->bInterfaceNumber = *(uint8_t *) (buf + 2);
437  if_descriptor->bAlternateSetting = *(uint8_t *) (buf + 3);
438  if_descriptor->bNumEndpoints = *(uint8_t *) (buf + 4);
439  if_descriptor->bInterfaceClass = *(uint8_t *) (buf + 5);
440  if_descriptor->bInterfaceSubClass = *(uint8_t *) (buf + 6);
441  if_descriptor->bInterfaceProtocol = *(uint8_t *) (buf + 7);
442  if_descriptor->iInterface = *(uint8_t *) (buf + 8);
443 }
Here is the caller graph for this function:

◆ USBH_ParseEPDesc()

static void USBH_ParseEPDesc ( USBH_EpDescTypeDef ep_descriptor,
uint8_t buf 
)
static

USBH_ParseEPDesc This function Parses the endpoint descriptor.

Parameters
ep_descriptorEndpoint descriptor destination address
bufBuffer where the parsed descriptor stored
Return values
None
454 {
455 
456  ep_descriptor->bLength = *(uint8_t *) (buf + 0);
457  ep_descriptor->bDescriptorType = *(uint8_t *) (buf + 1);
458  ep_descriptor->bEndpointAddress = *(uint8_t *) (buf + 2);
459  ep_descriptor->bmAttributes = *(uint8_t *) (buf + 3);
460  ep_descriptor->wMaxPacketSize = LE16 (buf + 4);
461  ep_descriptor->bInterval = *(uint8_t *) (buf + 6);
462 }
Here is the caller graph for this function:

◆ USBH_ParseStringDesc()

static void USBH_ParseStringDesc ( uint8_t psrc,
uint8_t pdest,
uint16_t  length 
)
static

USBH_ParseStringDesc This function Parses the string descriptor.

Parameters
psrcSource pointer containing the descriptor data
pdestDestination address pointer
lengthLength of the descriptor
Return values
None
475 {
476  uint16_t strlength;
477  uint16_t idx;
478 
479  /* The UNICODE string descriptor is not NULL-terminated. The string length is
480  computed by substracting two from the value of the first byte of the descriptor.
481  */
482 
483  /* Check which is lower size, the Size of string or the length of bytes read
484  from the device */
485 
486  if ( psrc[1] == USB_DESC_TYPE_STRING)
487  { /* Make sure the Descriptor is String Type */
488 
489  /* psrc[0] contains Size of Descriptor, subtract 2 to get the length of string */
490  strlength = ( ( (psrc[0]-2) <= length) ? (psrc[0]-2) :length);
491  psrc += 2; /* Adjust the offset ignoring the String Len and Descriptor type */
492 
493  for (idx = 0; idx < strlength; idx+=2 )
494  {/* Copy Only the string and ignore the UNICODE ID, hence add the src */
495  *pdest = psrc[idx];
496  pdest++;
497  }
498  *pdest = 0; /* mark end of string */
499  }
500 }
Here is the caller graph for this function:

◆ USBH_HandleControl()

static USBH_StatusTypeDef USBH_HandleControl ( USBH_HandleTypeDef phost)
static

USBH_HandleControl Handles the USB control transfer state machine.

Parameters
phostHost Handle
Return values
USBHStatus
582 {
585  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
586 
587  switch (phost->Control.state)
588  {
589  case CTRL_SETUP:
590  /* send a SETUP packet */
591  USBH_CtlSendSetup (phost,
592  (uint8_t *)phost->Control.setup.d8 ,
593  phost->Control.pipe_out);
594 
595  phost->Control.state = CTRL_SETUP_WAIT;
596  break;
597 
598  case CTRL_SETUP_WAIT:
599 
600  URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_out);
601  /* case SETUP packet sent successfully */
602  if(URB_Status == USBH_URB_DONE)
603  {
605 
606  /* check if there is a data stage */
607  if (phost->Control.setup.b.wLength.w != 0 )
608  {
609  if (direction == USB_D2H)
610  {
611  /* Data Direction is IN */
612  phost->Control.state = CTRL_DATA_IN;
613  }
614  else
615  {
616  /* Data Direction is OUT */
617  phost->Control.state = CTRL_DATA_OUT;
618  }
619  }
620  /* No DATA stage */
621  else
622  {
623  /* If there is No Data Transfer Stage */
624  if (direction == USB_D2H)
625  {
626  /* Data Direction is IN */
627  phost->Control.state = CTRL_STATUS_OUT;
628  }
629  else
630  {
631  /* Data Direction is OUT */
632  phost->Control.state = CTRL_STATUS_IN;
633  }
634  }
635 #if (USBH_USE_OS == 1)
636  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
637 #endif
638  }
639  else if(URB_Status == USBH_URB_ERROR)
640  {
641  phost->Control.state = CTRL_ERROR;
642 #if (USBH_USE_OS == 1)
643  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
644 #endif
645  }
646  break;
647 
648  case CTRL_DATA_IN:
649  /* Issue an IN token */
650  phost->Control.timer = phost->Timer;
651  USBH_CtlReceiveData(phost,
652  phost->Control.buff,
653  phost->Control.length,
654  phost->Control.pipe_in);
655 
657  break;
658 
659  case CTRL_DATA_IN_WAIT:
660 
661  URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_in);
662 
663  /* check is DATA packet transferred successfully */
664  if (URB_Status == USBH_URB_DONE)
665  {
666  phost->Control.state = CTRL_STATUS_OUT;
667 #if (USBH_USE_OS == 1)
668  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
669 #endif
670  }
671 
672  /* manage error cases*/
673  if (URB_Status == USBH_URB_STALL)
674  {
675  /* In stall case, return to previous machine state*/
677 #if (USBH_USE_OS == 1)
678  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
679 #endif
680  }
681  else if (URB_Status == USBH_URB_ERROR)
682  {
683  /* Device error */
684  phost->Control.state = CTRL_ERROR;
685 #if (USBH_USE_OS == 1)
686  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
687 #endif
688  }
689  break;
690 
691  case CTRL_DATA_OUT:
692 
693  USBH_CtlSendData (phost,
694  phost->Control.buff,
695  phost->Control.length ,
696  phost->Control.pipe_out,
697  1);
698  phost->Control.timer = phost->Timer;
700  break;
701 
702  case CTRL_DATA_OUT_WAIT:
703 
704  URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_out);
705 
706  if (URB_Status == USBH_URB_DONE)
707  { /* If the Setup Pkt is sent successful, then change the state */
708  phost->Control.state = CTRL_STATUS_IN;
709 #if (USBH_USE_OS == 1)
710  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
711 #endif
712  }
713 
714  /* handle error cases */
715  else if (URB_Status == USBH_URB_STALL)
716  {
717  /* In stall case, return to previous machine state*/
718  phost->Control.state = CTRL_STALLED;
720 #if (USBH_USE_OS == 1)
721  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
722 #endif
723  }
724  else if (URB_Status == USBH_URB_NOTREADY)
725  {
726  /* Nack received from device */
727  phost->Control.state = CTRL_DATA_OUT;
728 
729 #if (USBH_USE_OS == 1)
730  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
731 #endif
732  }
733  else if (URB_Status == USBH_URB_ERROR)
734  {
735  /* device error */
736  phost->Control.state = CTRL_ERROR;
737  status = USBH_FAIL;
738 
739 #if (USBH_USE_OS == 1)
740  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
741 #endif
742  }
743  break;
744 
745 
746  case CTRL_STATUS_IN:
747  /* Send 0 bytes out packet */
748  USBH_CtlReceiveData (phost,
749  0,
750  0,
751  phost->Control.pipe_in);
752  phost->Control.timer = phost->Timer;
754 
755  break;
756 
757  case CTRL_STATUS_IN_WAIT:
758 
759  URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_in);
760 
761  if ( URB_Status == USBH_URB_DONE)
762  { /* Control transfers completed, Exit the State Machine */
763  phost->Control.state = CTRL_COMPLETE;
764  status = USBH_OK;
765 #if (USBH_USE_OS == 1)
766  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
767 #endif
768  }
769 
770  else if (URB_Status == USBH_URB_ERROR)
771  {
772  phost->Control.state = CTRL_ERROR;
773 #if (USBH_USE_OS == 1)
774  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
775 #endif
776  }
777  else if(URB_Status == USBH_URB_STALL)
778  {
779  /* Control transfers completed, Exit the State Machine */
781 
782 #if (USBH_USE_OS == 1)
783  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
784 #endif
785  }
786  break;
787 
788  case CTRL_STATUS_OUT:
789  USBH_CtlSendData (phost,
790  0,
791  0,
792  phost->Control.pipe_out,
793  1);
794  phost->Control.timer = phost->Timer;
796  break;
797 
799 
800  URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_out);
801  if (URB_Status == USBH_URB_DONE)
802  {
803  status = USBH_OK;
804  phost->Control.state = CTRL_COMPLETE;
805 
806 #if (USBH_USE_OS == 1)
807  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
808 #endif
809  }
810  else if (URB_Status == USBH_URB_NOTREADY)
811  {
812  phost->Control.state = CTRL_STATUS_OUT;
813 
814 #if (USBH_USE_OS == 1)
815  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
816 #endif
817  }
818  else if (URB_Status == USBH_URB_ERROR)
819  {
820  phost->Control.state = CTRL_ERROR;
821 
822 #if (USBH_USE_OS == 1)
823  osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
824 #endif
825  }
826  break;
827 
828  case CTRL_ERROR:
829  /*
830  After a halt condition is encountered or an error is detected by the
831  host, a control endpoint is allowed to recover by accepting the next Setup
832  PID; i.e., recovery actions via some other pipe are not required for control
833  endpoints. For the Default Control Pipe, a device reset will ultimately be
834  required to clear the halt or error condition if the next Setup PID is not
835  accepted.
836  */
837  if (++ phost->Control.errorcount <= USBH_MAX_ERROR_COUNT)
838  {
839  /* try to recover control */
840  USBH_LL_Stop(phost);
841 
842  /* Do the transmission again, starting from SETUP Packet */
843  phost->Control.state = CTRL_SETUP;
844  phost->RequestState = CMD_SEND;
845  }
846  else
847  {
848  phost->pUser(phost, HOST_USER_UNRECOVERED_ERROR);
849  phost->Control.errorcount = 0;
850  USBH_ErrLog("Control error");
851  status = USBH_FAIL;
852  }
853  break;
854 
855  default:
856  break;
857  }
858  return status;
859 }
Here is the call graph for this function:
Here is the caller graph for this function:
CMD_WAIT
Definition: usbh_def.h:381
USBH_URB_ERROR
Definition: usbh_def.h:389
USB_REQ_SET_ADDRESS
#define USB_REQ_SET_ADDRESS
Definition: usbd_def.h:86
_DeviceDescriptor::idVendor
uint16_t idVendor
Definition: usbh_def.h:249
USB_DESC_TYPE_STRING
#define USB_DESC_TYPE_STRING
Definition: usbd_def.h:97
USBH_CtrlTypeDef::setup
USB_Setup_TypeDef setup
Definition: usbh_def.h:412
USB_REQ_SET_CONFIGURATION
#define USB_REQ_SET_CONFIGURATION
Definition: usbd_def.h:90
direction
uint8_t direction
Definition: UsbCore.h:185
CTRL_DATA_IN
Definition: usbh_def.h:362
USBH_CtrlTypeDef::buff
uint8_t * buff
Definition: usbh_def.h:409
CTRL_STALLED
Definition: usbh_def.h:371
_DeviceDescriptor::bDeviceClass
uint8_t bDeviceClass
Definition: usbh_def.h:242
CTRL_STATUS_IN_WAIT
Definition: usbh_def.h:367
_ConfigurationDescriptor::bLength
uint8_t bLength
Definition: usbh_def.h:288
_InterfaceDescriptor::bNumEndpoints
uint8_t bNumEndpoints
Definition: usbh_def.h:276
USB_DESC_TYPE_ENDPOINT
#define USB_DESC_TYPE_ENDPOINT
Definition: usbd_def.h:99
CTRL_DATA_OUT_WAIT
Definition: usbh_def.h:365
USBH_URB_NOTREADY
Definition: usbh_def.h:387
_ConfigurationDescriptor::Itf_Desc
USBH_InterfaceDescTypeDef Itf_Desc[USBH_MAX_NUM_INTERFACES]
Definition: usbh_def.h:296
_USB_Setup::_SetupPkt_Struc::bRequest
uint8_t bRequest
Definition: usbh_def.h:222
USBH_HandleControl
static USBH_StatusTypeDef USBH_HandleControl(USBH_HandleTypeDef *phost)
USBH_HandleControl Handles the USB control transfer state machine.
Definition: usbh_ctlreq.c:581
_InterfaceDescriptor::Ep_Desc
USBH_EpDescTypeDef Ep_Desc[USBH_MAX_NUM_ENDPOINTS]
Definition: usbh_def.h:281
_USBH_HandleTypeDef::RequestState
CMD_StateTypeDef RequestState
Definition: usbh_def.h:454
USBH_DeviceTypeDef::Data
uint8_t Data[USBH_MAX_DATA_BUFFER]
Definition: usbh_def.h:424
USB_REQ_CLEAR_FEATURE
#define USB_REQ_CLEAR_FEATURE
Definition: usbd_def.h:84
USBH_DeviceTypeDef::DevDesc
USBH_DevDescTypeDef DevDesc
Definition: usbh_def.h:429
_InterfaceDescriptor::bInterfaceNumber
uint8_t bInterfaceNumber
Definition: usbh_def.h:274
USBH_ErrLog
#define USBH_ErrLog(...)
Definition: usbh_conf.h:176
_USB_Setup::_SetupPkt_Struc::wIndex
uint16_t_uint8_t wIndex
Definition: usbh_def.h:224
USBH_URB_DONE
Definition: usbh_def.h:386
USBH_CtrlTypeDef::length
uint16_t length
Definition: usbh_def.h:410
_ConfigurationDescriptor::bConfigurationValue
uint8_t bConfigurationValue
Definition: usbh_def.h:292
USBH_ParseDevDesc
static void USBH_ParseDevDesc(USBH_DevDescTypeDef *, uint8_t *buf, uint16_t length)
USBH_ParseDevDesc This function Parses the device descriptor.
Definition: usbh_ctlreq.c:333
USBH_CtlSendData
USBH_StatusTypeDef USBH_CtlSendData(USBH_HandleTypeDef *phost, uint8_t *buff, uint16_t length, uint8_t hc_num, uint8_t do_ping)
USBH_CtlSendData Sends a data Packet to the Device.
Definition: usbh_ioreq.c:126
_DeviceDescriptor::bcdDevice
uint16_t bcdDevice
Definition: usbh_def.h:251
USB_CONFIGURATION_DESC_SIZE
#define USB_CONFIGURATION_DESC_SIZE
Definition: usbh_def.h:151
_DeviceDescriptor::bcdUSB
uint16_t bcdUSB
Definition: usbh_def.h:241
USBH_ParseEPDesc
static void USBH_ParseEPDesc(USBH_EpDescTypeDef *ep_descriptor, uint8_t *buf)
USBH_ParseEPDesc This function Parses the endpoint descriptor.
Definition: usbh_ctlreq.c:452
_DeviceDescriptor::bDeviceProtocol
uint8_t bDeviceProtocol
Definition: usbh_def.h:244
_USBH_HandleTypeDef::Timer
__IO uint32_t Timer
Definition: usbh_def.h:461
CTRL_DATA_IN_WAIT
Definition: usbh_def.h:363
_DeviceDescriptor::iManufacturer
uint8_t iManufacturer
Definition: usbh_def.h:252
USB_REQ_SET_INTERFACE
#define USB_REQ_SET_INTERFACE
Definition: usbd_def.h:92
_DescHeader
Definition: usbh_def.h:230
_USBH_HandleTypeDef::Control
USBH_CtrlTypeDef Control
Definition: usbh_def.h:455
USBH_URB_IDLE
Definition: usbh_def.h:385
_USB_Setup::_SetupPkt_Struc::wValue
uint16_t_uint8_t wValue
Definition: usbh_def.h:223
_InterfaceDescriptor
Definition: usbh_def.h:270
USBH_LL_Stop
USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost)
Stop the low level portion of the host driver.
Definition: usbh_conf.c:283
USB_DESC_STRING
#define USB_DESC_STRING
Definition: usbh_def.h:160
USB_REQ_RECIPIENT_DEVICE
#define USB_REQ_RECIPIENT_DEVICE
Definition: usbd_def.h:78
USB_REQ_RECIPIENT_INTERFACE
#define USB_REQ_RECIPIENT_INTERFACE
Definition: usbd_def.h:79
USBH_CtlReceiveData
USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, uint8_t *buff, uint16_t length, uint8_t hc_num)
USBH_CtlReceiveData Receives the Device Response to the Setup Packet.
Definition: usbh_ioreq.c:159
CTRL_DATA_OUT
Definition: usbh_def.h:364
USB_REQ_GET_DESCRIPTOR
#define USB_REQ_GET_DESCRIPTOR
Definition: usbd_def.h:87
_EndpointDescriptor
Definition: usbh_def.h:259
USBH_DeviceTypeDef::CfgDesc
USBH_CfgDescTypeDef CfgDesc
Definition: usbh_def.h:430
FEATURE_SELECTOR_ENDPOINT
#define FEATURE_SELECTOR_ENDPOINT
Definition: usbh_ctlreq.h:57
_DeviceDescriptor::bNumConfigurations
uint8_t bNumConfigurations
Definition: usbh_def.h:255
_ConfigurationDescriptor::bDescriptorType
uint8_t bDescriptorType
Definition: usbh_def.h:289
CMD_SEND
Definition: usbh_def.h:380
_USB_Setup::_SetupPkt_Struc::wLength
uint16_t_uint8_t wLength
Definition: usbh_def.h:225
CTRL_COMPLETE
Definition: usbh_def.h:372
USBH_OK
Definition: usbh_def.h:304
osMessagePut
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
Put a Message to a Queue.
Definition: cmsis_os.c:1113
CTRL_STATUS_OUT
Definition: usbh_def.h:368
_USBH_HandleTypeDef::device
USBH_DeviceTypeDef device
Definition: usbh_def.h:456
CTRL_SETUP_WAIT
Definition: usbh_def.h:361
USBH_CONTROL_EVENT
Definition: usbh_def.h:397
USBH_CtrlTypeDef::state
CTRL_StateTypeDef state
Definition: usbh_def.h:413
_EndpointDescriptor::bmAttributes
uint8_t bmAttributes
Definition: usbh_def.h:264
_DeviceDescriptor::iProduct
uint8_t iProduct
Definition: usbh_def.h:253
_DeviceDescriptor::bMaxPacketSize
uint8_t bMaxPacketSize
Definition: usbh_def.h:248
USBH_URB_STALL
Definition: usbh_def.h:390
_ConfigurationDescriptor::bNumInterfaces
uint8_t bNumInterfaces
Definition: usbh_def.h:291
_DeviceDescriptor::bLength
uint8_t bLength
Definition: usbh_def.h:239
USBH_LL_GetURBState
USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, uint8_t)
Get a URB state from the low level driver.
Definition: usbh_conf.c:519
USBH_CtrlTypeDef::pipe_in
uint8_t pipe_in
Definition: usbh_def.h:406
_ConfigurationDescriptor::iConfiguration
uint8_t iConfiguration
Definition: usbh_def.h:293
USBH_ParseStringDesc
static void USBH_ParseStringDesc(uint8_t *psrc, uint8_t *pdest, uint16_t length)
USBH_ParseStringDesc This function Parses the string descriptor.
Definition: usbh_ctlreq.c:472
uint8_t
const uint8_t[]
Definition: 404_html.c:3
CTRL_STATUS_IN
Definition: usbh_def.h:366
USBH_ParseCfgDesc
static void USBH_ParseCfgDesc(USBH_CfgDescTypeDef *cfg_desc, uint8_t *buf, uint16_t length)
USBH_ParseCfgDesc This function Parses the configuration descriptor.
Definition: usbh_ctlreq.c:366
USBH_CtlReq
USBH_StatusTypeDef USBH_CtlReq(USBH_HandleTypeDef *phost, uint8_t *buff, uint16_t length)
USBH_CtlReq USBH_CtlReq sends a control request and provide the status after completion of the reques...
Definition: usbh_ctlreq.c:531
_EndpointDescriptor::bDescriptorType
uint8_t bDescriptorType
Definition: usbh_def.h:262
_USB_Setup::b
struct _USB_Setup::_SetupPkt_Struc b
USBH_StatusTypeDef
USBH_StatusTypeDef
Definition: usbh_def.h:302
_DeviceDescriptor::idProduct
uint16_t idProduct
Definition: usbh_def.h:250
CTRL_SETUP
Definition: usbh_def.h:360
_ConfigurationDescriptor::bMaxPower
uint8_t bMaxPower
Definition: usbh_def.h:295
_InterfaceDescriptor::bInterfaceProtocol
uint8_t bInterfaceProtocol
Definition: usbh_def.h:279
_InterfaceDescriptor::bInterfaceSubClass
uint8_t bInterfaceSubClass
Definition: usbh_def.h:278
_DeviceDescriptor::bDeviceSubClass
uint8_t bDeviceSubClass
Definition: usbh_def.h:243
USBH_CtrlTypeDef::timer
uint16_t timer
Definition: usbh_def.h:411
USBH_CtrlTypeDef::errorcount
uint8_t errorcount
Definition: usbh_def.h:414
_DescHeader::bLength
uint8_t bLength
Definition: usbh_def.h:232
status
static status_t status
Definition: filament_sensor.c:37
USB_H2D
#define USB_H2D
Definition: usbh_def.h:108
USBH_CtlSendSetup
USBH_StatusTypeDef USBH_CtlSendSetup(USBH_HandleTypeDef *phost, uint8_t *buff, uint8_t hc_num)
USBH_CtlSendSetup Sends the Setup Packet to the Device.
Definition: usbh_ioreq.c:100
USBH_CtrlTypeDef::pipe_out
uint8_t pipe_out
Definition: usbh_def.h:407
_InterfaceDescriptor::iInterface
uint8_t iInterface
Definition: usbh_def.h:280
CTRL_IDLE
Definition: usbh_def.h:359
uint16_t_uint8_t::w
uint16_t w
Definition: usbh_def.h:204
_DeviceDescriptor::iSerialNumber
uint8_t iSerialNumber
Definition: usbh_def.h:254
USB_REQ_RECIPIENT_ENDPOINT
#define USB_REQ_RECIPIENT_ENDPOINT
Definition: usbd_def.h:80
USBH_GetNextDesc
USBH_DescHeader_t * USBH_GetNextDesc(uint8_t *pbuf, uint16_t *ptr)
USBH_GetNextDesc This function return the next descriptor header.
Definition: usbh_ctlreq.c:509
USBH_GetDescriptor
USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost, uint8_t req_type, uint16_t value_idx, uint8_t *buff, uint16_t length)
USBH_GetDescriptor Issues Descriptor command to the device. Once the response received,...
Definition: usbh_ctlreq.c:204
USB_DESC_TYPE_INTERFACE
#define USB_DESC_TYPE_INTERFACE
Definition: usbd_def.h:98
USBH_FAIL
Definition: usbh_def.h:306
USB_D2H
#define USB_D2H
Definition: usbh_def.h:109
USBH_BUSY
Definition: usbh_def.h:305
USB_DESC_CONFIGURATION
#define USB_DESC_CONFIGURATION
Definition: usbh_def.h:159
_ConfigurationDescriptor::wTotalLength
uint16_t wTotalLength
Definition: usbh_def.h:290
USB_DESC_DEVICE
#define USB_DESC_DEVICE
Definition: usbh_def.h:158
_DescHeader::bDescriptorType
uint8_t bDescriptorType
Definition: usbh_def.h:233
USBH_MAX_ERROR_COUNT
#define USBH_MAX_ERROR_COUNT
Definition: usbh_def.h:184
_EndpointDescriptor::bInterval
uint8_t bInterval
Definition: usbh_def.h:266
_USBH_HandleTypeDef::pUser
void(* pUser)(struct _USBH_HandleTypeDef *pHandle, uint8_t id)
Definition: usbh_def.h:464
USBH_MAX_NUM_INTERFACES
#define USBH_MAX_NUM_INTERFACES
Definition: usbh_conf.h:102
USB_REQ_TYPE_STANDARD
#define USB_REQ_TYPE_STANDARD
Definition: usbd_def.h:73
length
png_uint_32 length
Definition: png.c:2247
_InterfaceDescriptor::bDescriptorType
uint8_t bDescriptorType
Definition: usbh_def.h:273
USBH_URBStateTypeDef
USBH_URBStateTypeDef
Definition: usbh_def.h:384
_USB_Setup::_SetupPkt_Struc::bmRequestType
uint8_t bmRequestType
Definition: usbh_def.h:221
_EndpointDescriptor::bLength
uint8_t bLength
Definition: usbh_def.h:261
USBH_ParseInterfaceDesc
static void USBH_ParseInterfaceDesc(USBH_InterfaceDescTypeDef *if_descriptor, uint8_t *buf)
USBH_ParseInterfaceDesc This function Parses the interface descriptor.
Definition: usbh_ctlreq.c:431
_ConfigurationDescriptor::bmAttributes
uint8_t bmAttributes
Definition: usbh_def.h:294
LE16
#define LE16(addr)
Definition: usbh_def.h:69
pbuf
Definition: pbuf.h:142
HOST_USER_UNRECOVERED_ERROR
#define HOST_USER_UNRECOVERED_ERROR
Definition: usbh_core.h:69
_DeviceDescriptor::bDescriptorType
uint8_t bDescriptorType
Definition: usbh_def.h:240
_InterfaceDescriptor::bAlternateSetting
uint8_t bAlternateSetting
Definition: usbh_def.h:275
_EndpointDescriptor::wMaxPacketSize
uint16_t wMaxPacketSize
Definition: usbh_def.h:265
USB_REQ_DIR_MASK
#define USB_REQ_DIR_MASK
Definition: usbh_def.h:107
_EndpointDescriptor::bEndpointAddress
uint8_t bEndpointAddress
Definition: usbh_def.h:263
USBH_NOT_SUPPORTED
Definition: usbh_def.h:307
USB_LEN_CFG_DESC
#define USB_LEN_CFG_DESC
Definition: usbd_def.h:59
_USB_Setup::d8
uint32_t d8[2]
Definition: usbh_def.h:217
_InterfaceDescriptor::bLength
uint8_t bLength
Definition: usbh_def.h:272
_InterfaceDescriptor::bInterfaceClass
uint8_t bInterfaceClass
Definition: usbh_def.h:277
CTRL_STATUS_OUT_WAIT
Definition: usbh_def.h:369
CTRL_ERROR
Definition: usbh_def.h:370