Prusa MINI Firmware overview
USBH_MSC_BOT_Exported_FunctionsPrototype
Collaboration diagram for USBH_MSC_BOT_Exported_FunctionsPrototype:

Functions

USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset (USBH_HandleTypeDef *phost)
 USBH_MSC_BOT_REQ_Reset The function the MSC BOT Reset request. More...
 
USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN (USBH_HandleTypeDef *phost, uint8_t *Maxlun)
 USBH_MSC_BOT_REQ_GetMaxLUN The function the MSC BOT GetMaxLUN request. More...
 
USBH_StatusTypeDef USBH_MSC_BOT_Init (USBH_HandleTypeDef *phost)
 USBH_MSC_BOT_Init The function Initializes the BOT protocol. More...
 
USBH_StatusTypeDef USBH_MSC_BOT_Process (USBH_HandleTypeDef *phost, uint8_t lun)
 USBH_MSC_BOT_Process The function handle the BOT protocol. More...
 
USBH_StatusTypeDef USBH_MSC_BOT_Error (USBH_HandleTypeDef *phost, uint8_t lun)
 

Detailed Description

Function Documentation

◆ USBH_MSC_BOT_REQ_Reset()

USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset ( USBH_HandleTypeDef phost)

USBH_MSC_BOT_REQ_Reset The function the MSC BOT Reset request.

Parameters
phostHost handle
Return values
USBHStatus
110 {
111 
113  USB_REQ_RECIPIENT_INTERFACE;
114 
116  phost->Control.setup.b.wValue.w = 0;
117  phost->Control.setup.b.wIndex.w = 0;
118  phost->Control.setup.b.wLength.w = 0;
119 
120  return USBH_CtlReq(phost, 0 , 0 );
121 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_MSC_BOT_REQ_GetMaxLUN()

USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN ( USBH_HandleTypeDef phost,
uint8_t Maxlun 
)

USBH_MSC_BOT_REQ_GetMaxLUN The function the MSC BOT GetMaxLUN request.

Parameters
phostHost handle
Maxlunpointer to Maxlun variable
Return values
USBHStatus
131 {
133  USB_REQ_RECIPIENT_INTERFACE;
134 
136  phost->Control.setup.b.wValue.w = 0;
137  phost->Control.setup.b.wIndex.w = 0;
138  phost->Control.setup.b.wLength.w = 1;
139 
140  return USBH_CtlReq(phost, Maxlun , 1 );
141 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_MSC_BOT_Init()

USBH_StatusTypeDef USBH_MSC_BOT_Init ( USBH_HandleTypeDef phost)

USBH_MSC_BOT_Init The function Initializes the BOT protocol.

Parameters
phostHost handle
Return values
USBHStatus
152 {
153 
154  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
155 
156  MSC_Handle->hbot.cbw.field.Signature = BOT_CBW_SIGNATURE;
157  MSC_Handle->hbot.cbw.field.Tag = BOT_CBW_TAG;
158  MSC_Handle->hbot.state = BOT_SEND_CBW;
159  MSC_Handle->hbot.cmd_state = BOT_CMD_SEND;
160 
161  return USBH_OK;
162 }
Here is the caller graph for this function:

◆ USBH_MSC_BOT_Process()

USBH_StatusTypeDef USBH_MSC_BOT_Process ( USBH_HandleTypeDef phost,
uint8_t  lun 
)

USBH_MSC_BOT_Process The function handle the BOT protocol.

Parameters
phostHost handle
lunLogical Unit Number
Return values
USBHStatus
174 {
178  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
179  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
180  uint8_t toggle = 0;
181 
182  switch (MSC_Handle->hbot.state)
183  {
184  case BOT_SEND_CBW:
185  MSC_Handle->hbot.cbw.field.LUN = lun;
186  MSC_Handle->hbot.state = BOT_SEND_CBW_WAIT;
187  USBH_BulkSendData (phost,
188  MSC_Handle->hbot.cbw.data,
190  MSC_Handle->OutPipe,
191  1);
192 
193  break;
194 
195  case BOT_SEND_CBW_WAIT:
196 
197  URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe);
198 
199  if(URB_Status == USBH_URB_DONE)
200  {
201  if ( MSC_Handle->hbot.cbw.field.DataTransferLength != 0 )
202  {
203  /* If there is Data Transfer Stage */
204  if (((MSC_Handle->hbot.cbw.field.Flags) & USB_REQ_DIR_MASK) == USB_D2H)
205  {
206  /* Data Direction is IN */
207  MSC_Handle->hbot.state = BOT_DATA_IN;
208  }
209  else
210  {
211  /* Data Direction is OUT */
212  MSC_Handle->hbot.state = BOT_DATA_OUT;
213  }
214  }
215 
216  else
217  {/* If there is NO Data Transfer Stage */
218  MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
219  }
220 #if (USBH_USE_OS == 1)
221  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
222 #endif
223 
224  }
225  else if(URB_Status == USBH_URB_NOTREADY)
226  {
227  /* Re-send CBW */
228  MSC_Handle->hbot.state = BOT_SEND_CBW;
229 #if (USBH_USE_OS == 1)
230  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
231 #endif
232  }
233  else if(URB_Status == USBH_URB_STALL)
234  {
235  MSC_Handle->hbot.state = BOT_ERROR_OUT;
236 #if (USBH_USE_OS == 1)
237  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
238 #endif
239  }
240  break;
241 
242  case BOT_DATA_IN:
243  /* Send first packet */
244  USBH_BulkReceiveData (phost,
245  MSC_Handle->hbot.pbuf,
246  MSC_Handle->InEpSize ,
247  MSC_Handle->InPipe);
248 
249  MSC_Handle->hbot.state = BOT_DATA_IN_WAIT;
250 
251  break;
252 
253  case BOT_DATA_IN_WAIT:
254 
255  URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe);
256 
257  if(URB_Status == USBH_URB_DONE)
258  {
259  /* Adjust Data pointer and data length */
260  if(MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->InEpSize)
261  {
262  MSC_Handle->hbot.pbuf += MSC_Handle->InEpSize;
263  MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->InEpSize;
264  }
265  else
266  {
267  MSC_Handle->hbot.cbw.field.DataTransferLength = 0;
268  }
269 
270  /* More Data To be Received */
271  if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0)
272  {
273  /* Send next packet */
274  USBH_BulkReceiveData (phost,
275  MSC_Handle->hbot.pbuf,
276  MSC_Handle->InEpSize ,
277  MSC_Handle->InPipe);
278 
279  }
280  else
281  {
282  /* If value was 0, and successful transfer, then change the state */
283  MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
284 #if (USBH_USE_OS == 1)
285  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
286 #endif
287  }
288  }
289  else if(URB_Status == USBH_URB_STALL)
290  {
291  /* This is Data IN Stage STALL Condition */
292  MSC_Handle->hbot.state = BOT_ERROR_IN;
293 
294  /* Refer to USB Mass-Storage Class : BOT (www.usb.org)
295  6.7.2 Host expects to receive data from the device
296  3. On a STALL condition receiving data, then:
297  The host shall accept the data received.
298  The host shall clear the Bulk-In pipe.
299  4. The host shall attempt to receive a CSW.*/
300 
301 #if (USBH_USE_OS == 1)
302  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
303 #endif
304  }
305  break;
306 
307  case BOT_DATA_OUT:
308 
309  USBH_BulkSendData (phost,
310  MSC_Handle->hbot.pbuf,
311  MSC_Handle->OutEpSize ,
312  MSC_Handle->OutPipe,
313  1);
314 
315 
316  MSC_Handle->hbot.state = BOT_DATA_OUT_WAIT;
317  break;
318 
319  case BOT_DATA_OUT_WAIT:
320  URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe);
321 
322  if(URB_Status == USBH_URB_DONE)
323  {
324  /* Adjust Data pointer and data length */
325  if(MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->OutEpSize)
326  {
327  MSC_Handle->hbot.pbuf += MSC_Handle->OutEpSize;
328  MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->OutEpSize;
329  }
330  else
331  {
332  MSC_Handle->hbot.cbw.field.DataTransferLength = 0;
333  }
334 
335  /* More Data To be Sent */
336  if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0)
337  {
338  USBH_BulkSendData (phost,
339  MSC_Handle->hbot.pbuf,
340  MSC_Handle->OutEpSize ,
341  MSC_Handle->OutPipe,
342  1);
343  }
344  else
345  {
346  /* If value was 0, and successful transfer, then change the state */
347  MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
348  }
349 #if (USBH_USE_OS == 1)
350  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
351 #endif
352  }
353 
354  else if(URB_Status == USBH_URB_NOTREADY)
355  {
356  /* Resend same data */
357  MSC_Handle->hbot.state = BOT_DATA_OUT;
358 #if (USBH_USE_OS == 1)
359  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
360 #endif
361  }
362 
363  else if(URB_Status == USBH_URB_STALL)
364  {
365  MSC_Handle->hbot.state = BOT_ERROR_OUT;
366 
367  /* Refer to USB Mass-Storage Class : BOT (www.usb.org)
368  6.7.3 Ho - Host expects to send data to the device
369  3. On a STALL condition sending data, then:
370  " The host shall clear the Bulk-Out pipe.
371  4. The host shall attempt to receive a CSW.
372  */
373 #if (USBH_USE_OS == 1)
374  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
375 #endif
376  }
377  break;
378 
379  case BOT_RECEIVE_CSW:
380 
381  USBH_BulkReceiveData (phost,
382  MSC_Handle->hbot.csw.data,
384  MSC_Handle->InPipe);
385 
386  MSC_Handle->hbot.state = BOT_RECEIVE_CSW_WAIT;
387  break;
388 
390 
391  URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe);
392 
393  /* Decode CSW */
394  if(URB_Status == USBH_URB_DONE)
395  {
396  MSC_Handle->hbot.state = BOT_SEND_CBW;
397  MSC_Handle->hbot.cmd_state = BOT_CMD_SEND;
398  CSW_Status = USBH_MSC_DecodeCSW(phost);
399 
400  if(CSW_Status == BOT_CSW_CMD_PASSED)
401  {
402  status = USBH_OK;
403  }
404  else
405  {
406  status = USBH_FAIL;
407  }
408 #if (USBH_USE_OS == 1)
409  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
410 #endif
411  }
412  else if(URB_Status == USBH_URB_STALL)
413  {
414  MSC_Handle->hbot.state = BOT_ERROR_IN;
415 #if (USBH_USE_OS == 1)
416  osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
417 #endif
418  }
419  break;
420 
421  case BOT_ERROR_IN:
422  error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_IN);
423 
424  if (error == USBH_OK)
425  {
426  MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
427  }
428  else if (error == USBH_UNRECOVERED_ERROR)
429  {
430  /* This means that there is a STALL Error limit, Do Reset Recovery */
431  MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR;
432  }
433  break;
434 
435  case BOT_ERROR_OUT:
436  error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_OUT);
437 
438  if ( error == USBH_OK)
439  {
440 
441  toggle = USBH_LL_GetToggle(phost, MSC_Handle->OutPipe);
442  USBH_LL_SetToggle(phost, MSC_Handle->OutPipe, 1- toggle);
443  USBH_LL_SetToggle(phost, MSC_Handle->InPipe, 0);
444  MSC_Handle->hbot.state = BOT_ERROR_IN;
445  }
446  else if (error == USBH_UNRECOVERED_ERROR)
447  {
448  MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR;
449  }
450  break;
451 
452 
455  if ( status == USBH_OK)
456  {
457  MSC_Handle->hbot.state = BOT_SEND_CBW;
458  }
459  break;
460 
461  default:
462  break;
463  }
464  return status;
465 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_MSC_BOT_Error()

USBH_StatusTypeDef USBH_MSC_BOT_Error ( USBH_HandleTypeDef phost,
uint8_t  lun 
)
USBH_CtrlTypeDef::setup
USB_Setup_TypeDef setup
Definition: usbh_def.h:412
BOT_CBWTypeDef::__CBW::LUN
uint8_t LUN
Definition: usbh_msc_bot.h:110
USBH_BulkSendData
USBH_StatusTypeDef USBH_BulkSendData(USBH_HandleTypeDef *phost, uint8_t *buff, uint16_t length, uint8_t hc_num, uint8_t do_ping)
USBH_BulkSendData Sends the Bulk Packet to the device.
Definition: usbh_ioreq.c:186
USBH_UNRECOVERED_ERROR
Definition: usbh_def.h:308
auto_build.error
bool error
Definition: auto_build.py:637
BOT_CBW_TAG
#define BOT_CBW_TAG
Definition: usbh_msc_bot.h:155
USBH_URB_NOTREADY
Definition: usbh_def.h:387
BOT_ERROR_IN
Definition: usbh_msc_bot.h:96
BOT_CBW_LENGTH
#define BOT_CBW_LENGTH
Definition: usbh_msc_bot.h:157
_USB_Setup::_SetupPkt_Struc::bRequest
uint8_t bRequest
Definition: usbh_def.h:222
BOT_CSWTypeDef::data
uint8_t data[13]
Definition: usbh_msc_bot.h:127
BOT_CBWTypeDef::__CBW::Tag
uint32_t Tag
Definition: usbh_msc_bot.h:107
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
BOT_DATA_IN_WAIT
Definition: usbh_msc_bot.h:91
BOT_CBWTypeDef::data
uint8_t data[31]
Definition: usbh_msc_bot.h:114
BOT_RECEIVE_CSW_WAIT
Definition: usbh_msc_bot.h:95
BOT_DIR_IN
#define BOT_DIR_IN
Definition: usbh_msc_bot.h:165
BOT_HandleTypeDef::cbw
BOT_CBWTypeDef cbw
Definition: usbh_msc_bot.h:137
BOT_CBW_SIGNATURE
#define BOT_CBW_SIGNATURE
Definition: usbh_msc_bot.h:154
_USB_Setup::_SetupPkt_Struc::wIndex
uint16_t_uint8_t wIndex
Definition: usbh_def.h:224
USBH_URB_DONE
Definition: usbh_def.h:386
BOT_CBWTypeDef::field
struct BOT_CBWTypeDef::__CBW field
USBH_BulkReceiveData
USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, uint8_t *buff, uint16_t length, uint8_t hc_num)
USBH_BulkReceiveData Receives IN bulk packet from device.
Definition: usbh_ioreq.c:218
BOT_HandleTypeDef::cmd_state
BOT_CMDStateTypeDef cmd_state
Definition: usbh_msc_bot.h:136
_MSC_Process::OutEpSize
uint16_t OutEpSize
Definition: usbh_msc.h:123
_MSC_Process::hbot
BOT_HandleTypeDef hbot
Definition: usbh_msc.h:129
USBH_ClassTypeDef::pData
void * pData
Definition: usbh_def.h:446
_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
_MSC_Process::InPipe
uint8_t InPipe
Definition: usbh_msc.h:119
BOT_RECEIVE_CSW
Definition: usbh_msc_bot.h:94
USBH_LL_GetToggle
uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t)
Return the current toggle of a pipe.
Definition: usbh_conf.c:583
_USB_Setup::_SetupPkt_Struc::wLength
uint16_t_uint8_t wLength
Definition: usbh_def.h:225
USBH_URB_EVENT
Definition: usbh_def.h:396
BOT_DATA_OUT
Definition: usbh_msc_bot.h:92
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
BOT_CSW_CMD_PASSED
Definition: usbh_msc_bot.h:81
USB_REQ_TYPE_CLASS
#define USB_REQ_TYPE_CLASS
Definition: usbd_def.h:74
BOT_CMD_SEND
Definition: usbh_msc_bot.h:72
USBH_MSC_BOT_REQ_Reset
USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost)
USBH_MSC_BOT_REQ_Reset The function the MSC BOT Reset request.
Definition: usbh_msc_bot.c:109
BOT_CBWTypeDef::__CBW::Flags
uint8_t Flags
Definition: usbh_msc_bot.h:109
BOT_CBWTypeDef::__CBW::Signature
uint32_t Signature
Definition: usbh_msc_bot.h:106
USBH_URB_STALL
Definition: usbh_def.h:390
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
BOT_HandleTypeDef::csw
BOT_CSWTypeDef csw
Definition: usbh_msc_bot.h:139
BOT_CSWStatusTypeDef
BOT_CSWStatusTypeDef
Definition: usbh_msc_bot.h:78
uint8_t
const uint8_t[]
Definition: 404_html.c:3
BOT_ERROR_OUT
Definition: usbh_msc_bot.h:97
_USB_Setup::b
struct _USB_Setup::_SetupPkt_Struc b
USBH_StatusTypeDef
USBH_StatusTypeDef
Definition: usbh_def.h:302
BOT_DATA_IN
Definition: usbh_msc_bot.h:90
USBH_MSC_DecodeCSW
static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost)
USBH_MSC_BOT_DecodeCSW This function decodes the CSW received by the device and updates the same to u...
Definition: usbh_msc_bot.c:514
BOT_HandleTypeDef::state
BOT_StateTypeDef state
Definition: usbh_msc_bot.h:134
_MSC_Process::InEpSize
uint16_t InEpSize
Definition: usbh_msc.h:124
USBH_LL_SetToggle
USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t, uint8_t)
Set toggle for a pipe.
Definition: usbh_conf.c:564
BOT_HandleTypeDef::pbuf
uint8_t * pbuf
Definition: usbh_msc_bot.h:141
status
static status_t status
Definition: filament_sensor.c:37
USB_H2D
#define USB_H2D
Definition: usbh_def.h:108
BOT_UNRECOVERED_ERROR
Definition: usbh_msc_bot.h:98
USB_REQ_BOT_RESET
#define USB_REQ_BOT_RESET
Definition: usbh_msc.h:148
_MSC_Process::OutPipe
uint8_t OutPipe
Definition: usbh_msc.h:120
uint16_t_uint8_t::w
uint16_t w
Definition: usbh_def.h:204
USBH_FAIL
Definition: usbh_def.h:306
USB_D2H
#define USB_D2H
Definition: usbh_def.h:109
USBH_BUSY
Definition: usbh_def.h:305
BOT_CSW_CMD_FAILED
Definition: usbh_msc_bot.h:82
USBH_URBStateTypeDef
USBH_URBStateTypeDef
Definition: usbh_def.h:384
_USB_Setup::_SetupPkt_Struc::bmRequestType
uint8_t bmRequestType
Definition: usbh_def.h:221
_USBH_HandleTypeDef::pActiveClass
USBH_ClassTypeDef * pActiveClass
Definition: usbh_def.h:458
BOT_SEND_CBW_WAIT
Definition: usbh_msc_bot.h:89
BOT_CBWTypeDef::__CBW::DataTransferLength
uint32_t DataTransferLength
Definition: usbh_msc_bot.h:108
BOT_DIR_OUT
#define BOT_DIR_OUT
Definition: usbh_msc_bot.h:166
BOT_SEND_CBW
Definition: usbh_msc_bot.h:88
USB_REQ_GET_MAX_LUN
#define USB_REQ_GET_MAX_LUN
Definition: usbh_msc.h:149
BOT_CSW_LENGTH
#define BOT_CSW_LENGTH
Definition: usbh_msc_bot.h:158
_MSC_Process
Definition: usbh_msc.h:116
USBH_MSC_BOT_Abort
static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir)
USBH_MSC_BOT_Abort The function handle the BOT Abort process.
Definition: usbh_msc_bot.c:475
USB_REQ_DIR_MASK
#define USB_REQ_DIR_MASK
Definition: usbh_def.h:107
BOT_DATA_OUT_WAIT
Definition: usbh_msc_bot.h:93