usbd_dfu_core.c
Go to the documentation of this file.
1 
64 /* Includes ------------------------------------------------------------------*/
65 #include "usbd_dfu_core.h"
66 #include "usbd_desc.h"
67 #include "usbd_req.h"
68 #include "usb_bsp.h"
69 
70 
109 /*********************************************
110  DFU Device library callbacks
111  *********************************************/
112 static uint8_t usbd_dfu_Init (void *pdev,
113  uint8_t cfgidx);
114 
115 static uint8_t usbd_dfu_DeInit (void *pdev,
116  uint8_t cfgidx);
117 
118 static uint8_t usbd_dfu_Setup (void *pdev,
119  USB_SETUP_REQ *req);
120 
121 static uint8_t EP0_TxSent (void *pdev);
122 
123 static uint8_t EP0_RxReady (void *pdev);
124 
125 
126 static uint8_t *USBD_DFU_GetCfgDesc (uint8_t speed,
127  uint16_t *length);
128 
129 
130 #ifdef USB_OTG_HS_CORE
131 static uint8_t *USBD_DFU_GetOtherCfgDesc (uint8_t speed,
132  uint16_t *length);
133 #endif
134 
135 static uint8_t* USBD_DFU_GetUsrStringDesc (uint8_t speed,
136  uint8_t index ,
137  uint16_t *length);
138 
139 /*********************************************
140  DFU Requests management functions
141  *********************************************/
142 static void DFU_Req_DETACH (void *pdev,
143  USB_SETUP_REQ *req);
144 
145 static void DFU_Req_DNLOAD (void *pdev,
146  USB_SETUP_REQ *req);
147 
148 static void DFU_Req_UPLOAD (void *pdev,
149  USB_SETUP_REQ *req);
150 
151 static void DFU_Req_GETSTATUS (void *pdev);
152 
153 static void DFU_Req_CLRSTATUS (void *pdev);
154 
155 static void DFU_Req_GETSTATE (void *pdev);
156 
157 static void DFU_Req_ABORT (void *pdev);
158 
159 static void DFU_LeaveDFUMode (void *pdev);
160 
168 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
169  #if defined ( __ICCARM__ )
170  #pragma data_alignment=4
171  #endif
172 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
174 
175 
176 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
177  #if defined ( __ICCARM__ )
178  #pragma data_alignment=4
179  #endif
180 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
181 __ALIGN_BEGIN uint8_t usbd_dfu_OtherCfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END ;
182 
183 /* The list of Interface String descriptor pointers is defined in usbd_dfu_mal.c
184  file. This list can be updated whenever a memory has to be added or removed */
185 extern const uint8_t* usbd_dfu_StringDesc[];
186 
187 /* State Machine variables */
188 uint8_t DeviceState;
189 uint8_t DeviceStatus[6];
191 /* Data Management variables */
192 static uint32_t wBlockNum = 0, wlength = 0;
193 static uint32_t Pointer = APP_DEFAULT_ADD; /* Base Address to Erase, Program or Read */
194 static __IO uint32_t usbd_dfu_AltSet = 0;
195 
196 extern uint8_t MAL_Buffer[];
197 
198 /* DFU interface class callbacks structure */
200 {
204  EP0_TxSent,
205  EP0_RxReady,
206  NULL, /* DataIn, */
207  NULL, /* DataOut, */
208  NULL, /*SOF */
209  NULL,
210  NULL,
212 #ifdef USB_OTG_HS_CORE
213  USBD_DFU_GetOtherCfgDesc, /* use same cobfig as per FS */
214 #endif
216 };
217 
218 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
219  #if defined ( __ICCARM__ )
220  #pragma data_alignment=4
221  #endif
222 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
223 /* USB DFU device Configuration Descriptor */
224 __ALIGN_BEGIN uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
225 {
226  0x09, /* bLength: Configuation Descriptor size */
227  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
229  /* wTotalLength: Bytes returned */
230  0x00,
231  0x01, /*bNumInterfaces: 1 interface*/
232  0x01, /*bConfigurationValue: Configuration value*/
233  0x02, /*iConfiguration: Index of string descriptor describing the configuration*/
234  0xC0, /*bmAttributes: bus powered and Supprts Remote Wakeup */
235  0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
236  /* 09 */
237 
238  /********** Descriptor of DFU interface 0 Alternate setting 0 **************/
239  USBD_DFU_IF_DESC(0), /* This interface is mandatory for all devices */
240 
241 #if (USBD_ITF_MAX_NUM > 1)
242  /********** Descriptor of DFU interface 0 Alternate setting 1 **************/
243  USBD_DFU_IF_DESC(1),
244 #endif /* (USBD_ITF_MAX_NUM > 1) */
245 
246 #if (USBD_ITF_MAX_NUM > 2)
247  /********** Descriptor of DFU interface 0 Alternate setting 2 **************/
248  USBD_DFU_IF_DESC(2),
249 #endif /* (USBD_ITF_MAX_NUM > 2) */
250 
251 #if (USBD_ITF_MAX_NUM > 3)
252  /********** Descriptor of DFU interface 0 Alternate setting 3 **************/
253  USBD_DFU_IF_DESC(3),
254 #endif /* (USBD_ITF_MAX_NUM > 3) */
255 
256 #if (USBD_ITF_MAX_NUM > 4)
257  /********** Descriptor of DFU interface 0 Alternate setting 4 **************/
258  USBD_DFU_IF_DESC(4),
259 #endif /* (USBD_ITF_MAX_NUM > 4) */
260 
261 #if (USBD_ITF_MAX_NUM > 5)
262  /********** Descriptor of DFU interface 0 Alternate setting 5 **************/
263  USBD_DFU_IF_DESC(5),
264 #endif /* (USBD_ITF_MAX_NUM > 5) */
265 
266 #if (USBD_ITF_MAX_NUM > 6)
267 #error "ERROR: usbd_dfu_core.c: Modify the file to support more descriptors!"
268 #endif /* (USBD_ITF_MAX_NUM > 6) */
269 
270  /******************** DFU Functional Descriptor********************/
271  0x09, /*blength = 9 Bytes*/
272  DFU_DESCRIPTOR_TYPE, /* DFU Functional Descriptor*/
273  0x0B, /*bmAttribute
274  bitCanDnload = 1 (bit 0)
275  bitCanUpload = 1 (bit 1)
276  bitManifestationTolerant = 0 (bit 2)
277  bitWillDetach = 1 (bit 3)
278  Reserved (bit4-6)
279  bitAcceleratedST = 0 (bit 7)*/
280  0xFF, /*DetachTimeOut= 255 ms*/
281  0x00,
282  /*WARNING: In DMA mode the multiple MPS packets feature is still not supported
283  ==> In this case, when using DMA XFERSIZE should be set to 64 in usbd_conf.h */
284  TRANSFER_SIZE_BYTES(XFERSIZE), /* TransferSize = 1024 Byte*/
285  0x1A, /* bcdDFUVersion*/
286  0x01
287  /***********************************************************/
288  /* 9*/
289 } ;
290 
291 #ifdef USE_USB_OTG_HS
292 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
293  #if defined ( __ICCARM__ )
294  #pragma data_alignment=4
295  #endif
296 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
297 
298 __ALIGN_BEGIN uint8_t usbd_dfu_OtherCfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
299 {
300  0x09, /* bLength: Configuation Descriptor size */
301  USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */
303  /* wTotalLength: Bytes returned */
304  0x00,
305  0x01, /*bNumInterfaces: 1 interface*/
306  0x01, /*bConfigurationValue: Configuration value*/
307  0x02, /*iConfiguration: Index of string descriptor describing the configuration*/
308  0xC0, /*bmAttributes: bus powered and Supprts Remote Wakeup */
309  0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
310  /* 09 */
311 
312  /********** Descriptor of DFU interface 0 Alternate setting 0 **************/
313  USBD_DFU_IF_DESC(0), /* This interface is mandatory for all devices */
314 
315 #if (USBD_ITF_MAX_NUM > 1)
316  /********** Descriptor of DFU interface 0 Alternate setting 1 **************/
317  USBD_DFU_IF_DESC(1),
318 #endif /* (USBD_ITF_MAX_NUM > 1) */
319 
320 #if (USBD_ITF_MAX_NUM > 2)
321  /********** Descriptor of DFU interface 0 Alternate setting 2 **************/
322  USBD_DFU_IF_DESC(2),
323 #endif /* (USBD_ITF_MAX_NUM > 2) */
324 
325 #if (USBD_ITF_MAX_NUM > 3)
326  /********** Descriptor of DFU interface 0 Alternate setting 3 **************/
327  USBD_DFU_IF_DESC(3),
328 #endif /* (USBD_ITF_MAX_NUM > 3) */
329 
330 #if (USBD_ITF_MAX_NUM > 4)
331  /********** Descriptor of DFU interface 0 Alternate setting 4 **************/
332  USBD_DFU_IF_DESC(4),
333 #endif /* (USBD_ITF_MAX_NUM > 4) */
334 
335 #if (USBD_ITF_MAX_NUM > 5)
336  /********** Descriptor of DFU interface 0 Alternate setting 5 **************/
337  USBD_DFU_IF_DESC(5),
338 #endif /* (USBD_ITF_MAX_NUM > 5) */
339 
340 #if (USBD_ITF_MAX_NUM > 6)
341 #error "ERROR: usbd_dfu_core.c: Modify the file to support more descriptors!"
342 #endif /* (USBD_ITF_MAX_NUM > 6) */
343 
344  /******************** DFU Functional Descriptor********************/
345  0x09, /*blength = 9 Bytes*/
346  DFU_DESCRIPTOR_TYPE, /* DFU Functional Descriptor*/
347  0x0B, /*bmAttribute
348  bitCanDnload = 1 (bit 0)
349  bitCanUpload = 1 (bit 1)
350  bitManifestationTolerant = 0 (bit 2)
351  bitWillDetach = 1 (bit 3)
352  Reserved (bit4-6)
353  bitAcceleratedST = 0 (bit 7)*/
354  0xFF, /*DetachTimeOut= 255 ms*/
355  0x00,
356  /*WARNING: In DMA mode the multiple MPS packets feature is still not supported
357  ==> In this case, when using DMA XFERSIZE should be set to 64 in usbd_conf.h */
358  TRANSFER_SIZE_BYTES(XFERSIZE), /* TransferSize = 1024 Byte*/
359  0x1A, /* bcdDFUVersion*/
360  0x01
361  /***********************************************************/
362  /* 9*/
363 };
364 #endif /* USE_USB_OTG_HS */
365 
366 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
367  #if defined ( __ICCARM__ )
368  #pragma data_alignment=4
369  #endif
370 
371 __ALIGN_BEGIN static uint8_t usbd_dfu_Desc[USB_DFU_DESC_SIZ] __ALIGN_END =
372 {
373  0x09, /*blength = 9 Bytes*/
374  DFU_DESCRIPTOR_TYPE, /* DFU Functional Descriptor*/
375  0x0B, /*bmAttribute
376  bitCanDnload = 1 (bit 0)
377  bitCanUpload = 1 (bit 1)
378  bitManifestationTolerant = 0 (bit 2)
379  bitWillDetach = 1 (bit 3)
380  Reserved (bit4-6)
381  bitAcceleratedST = 0 (bit 7)*/
382  0xFF, /*DetachTimeOut= 255 ms*/
383  0x00,
384  /*WARNING: In DMA mode the multiple MPS packets feature is still not supported
385  ==> In this case, when using DMA XFERSIZE should be set to 64 in usbd_conf.h */
386  TRANSFER_SIZE_BYTES(XFERSIZE), /* TransferSize = 1024 Byte*/
387  0x1A, /* bcdDFUVersion*/
388  0x01
389 };
390 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
391 
407 static uint8_t usbd_dfu_Init (void *pdev,
408  uint8_t cfgidx)
409 {
410  /* Initilialize the MAL(Media Access Layer) */
411  MAL_Init();
412 
413  /* Initialize the state of the DFU interface */
415  DeviceStatus[0] = STATUS_OK;
417 
418  return USBD_OK;
419 }
420 
428 static uint8_t usbd_dfu_DeInit (void *pdev,
429  uint8_t cfgidx)
430 {
431  /* Restore default state */
433  DeviceStatus[0] = STATUS_OK;
435  wBlockNum = 0;
436  wlength = 0;
437 
438  /* DeInitilialize the MAL(Media Access Layer) */
439  MAL_DeInit();
440 
441  return USBD_OK;
442 }
443 
451 static uint8_t usbd_dfu_Setup (void *pdev,
452  USB_SETUP_REQ *req)
453 {
454  uint16_t len = 0;
455  uint8_t *pbuf = NULL;
456 
457  switch (req->bmRequest & USB_REQ_TYPE_MASK)
458  {
459  /* DFU Class Requests -------------------------------*/
460  case USB_REQ_TYPE_CLASS :
461  switch (req->bRequest)
462  {
463  case DFU_DNLOAD:
464  DFU_Req_DNLOAD(pdev, req);
465  break;
466 
467  case DFU_UPLOAD:
468  DFU_Req_UPLOAD(pdev, req);
469  break;
470 
471  case DFU_GETSTATUS:
472  DFU_Req_GETSTATUS(pdev);
473  break;
474 
475  case DFU_CLRSTATUS:
476  DFU_Req_CLRSTATUS(pdev);
477  break;
478 
479  case DFU_GETSTATE:
480  DFU_Req_GETSTATE(pdev);
481  break;
482 
483  case DFU_ABORT:
484  DFU_Req_ABORT(pdev);
485  break;
486 
487  case DFU_DETACH:
488  DFU_Req_DETACH(pdev, req);
489  break;
490 
491  default:
492  USBD_CtlError (pdev, req);
493  return USBD_FAIL;
494  }
495  break;
496 
497  /* Standard Requests -------------------------------*/
499  switch (req->bRequest)
500  {
502  if( (req->wValue >> 8) == DFU_DESCRIPTOR_TYPE)
503  {
504 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
505  pbuf = usbd_dfu_Desc;
506 #else
507  pbuf = usbd_dfu_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM);
508 #endif
509  len = MIN(USB_DFU_DESC_SIZ , req->wLength);
510  }
511 
512  USBD_CtlSendData (pdev,
513  pbuf,
514  len);
515  break;
516 
517  case USB_REQ_GET_INTERFACE :
518  USBD_CtlSendData (pdev,
519  (uint8_t *)&usbd_dfu_AltSet,
520  1);
521  break;
522 
523  case USB_REQ_SET_INTERFACE :
524  if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM)
525  {
526  usbd_dfu_AltSet = (uint8_t)(req->wValue);
527  }
528  else
529  {
530  /* Call the error management function (command will be nacked */
531  USBD_CtlError (pdev, req);
532  }
533  break;
534  }
535  }
536  return USBD_OK;
537 }
538 
545 static uint8_t EP0_TxSent (void *pdev)
546 {
547  uint32_t Addr;
548  USB_SETUP_REQ req;
549 
551  {
552  /* Decode the Special Command*/
553  if (wBlockNum == 0)
554  {
555  if ((MAL_Buffer[0] == CMD_GETCOMMANDS) && (wlength == 1))
556  {}
557  else if (( MAL_Buffer[0] == CMD_SETADDRESSPOINTER ) && (wlength == 5))
558  {
559  Pointer = MAL_Buffer[1];
560  Pointer += MAL_Buffer[2] << 8;
561  Pointer += MAL_Buffer[3] << 16;
562  Pointer += MAL_Buffer[4] << 24;
563  }
564  else if (( MAL_Buffer[0] == CMD_ERASE ) && (wlength == 5))
565  {
566  Pointer = MAL_Buffer[1];
567  Pointer += MAL_Buffer[2] << 8;
568  Pointer += MAL_Buffer[3] << 16;
569  Pointer += MAL_Buffer[4] << 24;
571  }
572  else
573  {
574  /* Reset the global length and block number */
575  wlength = 0;
576  wBlockNum = 0;
577  /* Call the error management function (command will be nacked) */
578  req.bmRequest = 0;
579  req.wLength = 1;
580  USBD_CtlError (pdev, &req);
581  }
582  }
583  /* Regular Download Command */
584  else if (wBlockNum > 1)
585  {
586  /* Decode the required address */
587  Addr = ((wBlockNum - 2) * XFERSIZE) + Pointer;
588 
589  /* Preform the write operation */
590  MAL_Write(Addr, wlength);
591  }
592  /* Reset the global lenght and block number */
593  wlength = 0;
594  wBlockNum = 0;
595 
596  /* Update the state machine */
599  DeviceStatus[1] = 0;
600  DeviceStatus[2] = 0;
601  DeviceStatus[3] = 0;
602  return USBD_OK;
603  }
604  else if (DeviceState == STATE_dfuMANIFEST)/* Manifestation in progress*/
605  {
606  /* Start leaving DFU mode */
607  DFU_LeaveDFUMode(pdev);
608  }
609 
610  return USBD_OK;
611 }
612 
619 static uint8_t EP0_RxReady (void *pdev)
620 {
621  return USBD_OK;
622 }
623 
624 
625 /******************************************************************************
626  DFU Class requests management
627 ******************************************************************************/
635 static void DFU_Req_DETACH(void *pdev, USB_SETUP_REQ *req)
636 {
640  {
641  /* Update the state machine */
643  DeviceStatus[0] = STATUS_OK;
644  DeviceStatus[1] = 0;
645  DeviceStatus[2] = 0;
646  DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/
648  DeviceStatus[5] = 0; /*iString*/
649  wBlockNum = 0;
650  wlength = 0;
651  }
652 
653  /* Check the detach capability in the DFU functional descriptor */
654  if ((usbd_dfu_CfgDesc[12 + (9 * USBD_ITF_MAX_NUM)]) & DFU_DETACH_MASK)
655  {
656  /* Perform an Attach-Detach operation on USB bus */
657  DCD_DevDisconnect (pdev);
658  DCD_DevConnect (pdev);
659  }
660  else
661  {
662  /* Wait for the period of time specified in Detach request */
663  USB_OTG_BSP_mDelay (req->wValue);
664  }
665 }
666 
674 static void DFU_Req_DNLOAD(void *pdev, USB_SETUP_REQ *req)
675 {
676  /* Data setup request */
677  if (req->wLength > 0)
678  {
680  {
681  /* Update the global length and block number */
682  wBlockNum = req->wValue;
683  wlength = req->wLength;
684 
685  /* Update the state machine */
688 
689  /* Prepare the reception of the buffer over EP0 */
690  USBD_CtlPrepareRx (pdev,
691  (uint8_t*)MAL_Buffer,
692  wlength);
693  }
694  /* Unsupported state */
695  else
696  {
697  /* Call the error management function (command will be nacked */
698  USBD_CtlError (pdev, req);
699  }
700  }
701  /* 0 Data DNLOAD request */
702  else
703  {
704  /* End of DNLOAD operation*/
706  {
709  DeviceStatus[1] = 0;
710  DeviceStatus[2] = 0;
711  DeviceStatus[3] = 0;
713  }
714  else
715  {
716  /* Call the error management function (command will be nacked */
717  USBD_CtlError (pdev, req);
718  }
719  }
720 }
721 
729 static void DFU_Req_UPLOAD(void *pdev, USB_SETUP_REQ *req)
730 {
731  uint8_t *Phy_Addr = NULL;
732  uint32_t Addr = 0;
733 
734  /* Data setup request */
735  if (req->wLength > 0)
736  {
738  {
739  /* Update the global langth and block number */
740  wBlockNum = req->wValue;
741  wlength = req->wLength;
742 
743  /* DFU Get Command */
744  if (wBlockNum == 0)
745  {
746  /* Update the state machine */
749  DeviceStatus[1] = 0;
750  DeviceStatus[2] = 0;
751  DeviceStatus[3] = 0;
752 
753  /* Store the values of all supported commands */
756  MAL_Buffer[2] = CMD_ERASE;
757 
758  /* Send the status data over EP0 */
759  USBD_CtlSendData (pdev,
760  (uint8_t *)(&(MAL_Buffer[0])),
761  3);
762  }
763  else if (wBlockNum > 1)
764  {
767  DeviceStatus[1] = 0;
768  DeviceStatus[2] = 0;
769  DeviceStatus[3] = 0;
770  Addr = ((wBlockNum - 2) * XFERSIZE) + Pointer; /* Change is Accelerated*/
771 
772  /* Return the physical address where data are stored */
773  Phy_Addr = MAL_Read(Addr, wlength);
774 
775  /* Send the status data over EP0 */
776  USBD_CtlSendData (pdev,
777  Phy_Addr,
778  wlength);
779  }
780  else /* unsupported wBlockNum */
781  {
784  DeviceStatus[1] = 0;
785  DeviceStatus[2] = 0;
786  DeviceStatus[3] = 0;
787 
788  /* Call the error management function (command will be nacked */
789  USBD_CtlError (pdev, req);
790  }
791  }
792  /* Unsupported state */
793  else
794  {
795  wlength = 0;
796  wBlockNum = 0;
797  /* Call the error management function (command will be nacked */
798  USBD_CtlError (pdev, req);
799  }
800  }
801  /* No Data setup request */
802  else
803  {
805  DeviceStatus[1] = 0;
806  DeviceStatus[2] = 0;
807  DeviceStatus[3] = 0;
809  }
810 }
811 
818 static void DFU_Req_GETSTATUS(void *pdev)
819 {
820  switch (DeviceState)
821  {
823  if (wlength != 0)
824  {
827  if ((wBlockNum == 0) && (MAL_Buffer[0] == CMD_ERASE))
828  {
830  }
831  else
832  {
834  }
835  }
836  else /* (wlength==0)*/
837  {
840  DeviceStatus[1] = 0;
841  DeviceStatus[2] = 0;
842  DeviceStatus[3] = 0;
843  }
844  break;
845 
848  {
851  DeviceStatus[1] = 1; /*bwPollTimeout = 1ms*/
852  DeviceStatus[2] = 0;
853  DeviceStatus[3] = 0;
854  //break;
855  }
856  else if ((Manifest_State == Manifest_complete) && \
857  ((usbd_dfu_CfgDesc[(11 + (9 * USBD_ITF_MAX_NUM))]) & 0x04))
858  {
861  DeviceStatus[1] = 0;
862  DeviceStatus[2] = 0;
863  DeviceStatus[3] = 0;
864  //break;
865  }
866  break;
867 
868  default :
869  break;
870  }
871 
872  /* Send the status data over EP0 */
873  USBD_CtlSendData (pdev,
874  (uint8_t *)(&(DeviceStatus[0])),
875  6);
876 }
877 
884 static void DFU_Req_CLRSTATUS(void *pdev)
885 {
887  {
889  DeviceStatus[0] = STATUS_OK;/*bStatus*/
890  DeviceStatus[1] = 0;
891  DeviceStatus[2] = 0;
892  DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/
893  DeviceStatus[4] = DeviceState;/*bState*/
894  DeviceStatus[5] = 0;/*iString*/
895  }
896  else
897  { /*State Error*/
899  DeviceStatus[0] = STATUS_ERRUNKNOWN;/*bStatus*/
900  DeviceStatus[1] = 0;
901  DeviceStatus[2] = 0;
902  DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/
903  DeviceStatus[4] = DeviceState;/*bState*/
904  DeviceStatus[5] = 0;/*iString*/
905  }
906 }
907 
914 static void DFU_Req_GETSTATE(void *pdev)
915 {
916  /* Return the current state of the DFU interface */
917  USBD_CtlSendData (pdev,
918  &DeviceState,
919  1);
920 }
921 
928 static void DFU_Req_ABORT(void *pdev)
929 {
933  {
935  DeviceStatus[0] = STATUS_OK;
936  DeviceStatus[1] = 0;
937  DeviceStatus[2] = 0;
938  DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/
940  DeviceStatus[5] = 0; /*iString*/
941  wBlockNum = 0;
942  wlength = 0;
943  }
944 }
945 
953 void DFU_LeaveDFUMode(void *pdev)
954 {
956 
957  if ((usbd_dfu_CfgDesc[(11 + (9 * USBD_ITF_MAX_NUM))]) & 0x04)
958  {
961  DeviceStatus[1] = 0;
962  DeviceStatus[2] = 0;
963  DeviceStatus[3] = 0;
964  return;
965  }
966  else
967  {
970  DeviceStatus[1] = 0;
971  DeviceStatus[2] = 0;
972  DeviceStatus[3] = 0;
973 
974  /* Disconnect the USB device */
975  DCD_DevDisconnect (pdev);
976 
977  /* DeInitilialize the MAL(Media Access Layer) */
978  MAL_DeInit();
979 
980  /* Generate system reset to allow jumping to the user code */
982 
983  /* This instruction will not be reached (system reset) */
984  return;
985  }
986 }
987 
995 static uint8_t *USBD_DFU_GetCfgDesc (uint8_t speed, uint16_t *length)
996 {
997  *length = sizeof (usbd_dfu_CfgDesc);
998  return usbd_dfu_CfgDesc;
999 }
1000 
1001 #ifdef USB_OTG_HS_CORE
1002 
1009 static uint8_t *USBD_DFU_GetOtherCfgDesc (uint8_t speed, uint16_t *length)
1010 {
1011  *length = sizeof (usbd_dfu_OtherCfgDesc);
1012  return usbd_dfu_OtherCfgDesc;
1013 }
1014 #endif
1015 
1024 static uint8_t* USBD_DFU_GetUsrStringDesc (uint8_t speed, uint8_t index , uint16_t *length)
1025 {
1026  /* Check if the requested string interface is supported */
1027  if (index <= (USBD_IDX_INTERFACE_STR + USBD_ITF_MAX_NUM))
1028  {
1029 
1030 
1031  USBD_GetString ((uint8_t *)usbd_dfu_StringDesc[index - USBD_IDX_INTERFACE_STR - 1], USBD_StrDesc, length);
1032  return USBD_StrDesc;
1033  }
1034  /* Not supported Interface Descriptor index */
1035  else
1036  {
1037  return NULL;
1038  }
1039 }
1052 /************************ (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
uint8_t MAL_Buffer[]
Specific api&#39;s relative to the used hardware platform.
header file for the usbd_req.c file
static void DFU_Req_DNLOAD(void *pdev, USB_SETUP_REQ *req)
DFU_Req_DNLOAD Handles the DFU DNLOAD request.
static void DFU_Req_UPLOAD(void *pdev, USB_SETUP_REQ *req)
DFU_Req_UPLOAD Handles the DFU UPLOAD request.
uint16_t MAL_DeInit(void)
MAL_DeInit DeInitializes the Media on the STM32.
Definition: usbd_dfu_mal.c:118
#define USBD_DFU_IF_DESC(n)
#define DFU_DESCRIPTOR_TYPE
Definition: usbd_dfu_core.h:52
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
USBD_GetString Convert Ascii string into unicode one.
Definition: usbd_req.c:831
const uint8_t * usbd_dfu_StringDesc[]
#define STATE_dfuMANIFEST
Definition: usbd_dfu_core.h:73
#define USB_DFU_DESC_SIZ
Definition: usbd_dfu_core.h:50
#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 STATE_dfuDNBUSY
Definition: usbd_dfu_core.h:70
#define DFU_DETACH_MASK
#define STATE_dfuDNLOAD_SYNC
Definition: usbd_dfu_core.h:69
#define USB_REQ_SET_INTERFACE
Definition: usbd_def.h:86
#define USB_REQ_GET_INTERFACE
Definition: usbd_def.h:85
#define STATUS_OK
Definition: usbd_dfu_core.h:82
static void DFU_Req_GETSTATUS(void *pdev)
DFU_Req_GETSTATUS Handles the DFU GETSTATUS request.
#define STATE_dfuIDLE
Definition: usbd_dfu_core.h:68
#define USBD_ITF_MAX_NUM
Definition: usbd_conf.h:33
header file for the usbd_dfu_core.c file.
static uint32_t wlength
static void DFU_Req_DETACH(void *pdev, USB_SETUP_REQ *req)
DFU_Req_DETACH Handles the DFU DETACH request.
void DCD_DevConnect(USB_OTG_CORE_HANDLE *pdev)
Connect device (enable internal pull-up)
Definition: usb_dcd.c:395
#define CMD_ERASE
#define STATE_dfuMANIFEST_SYNC
Definition: usbd_dfu_core.h:72
#define MIN(a, b)
Definition: usb_defines.h:178
static void DFU_Req_GETSTATE(void *pdev)
DFU_Req_GETSTATE Handles the DFU GETSTATE request.
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usbd_cdc_core.h:56
uint16_t MAL_Write(uint32_t SectorAddress, uint32_t DataLength)
MAL_Write Write sectors of memory.
Definition: usbd_dfu_mal.c:176
static uint32_t wBlockNum
__STATIC_INLINE void NVIC_SystemReset(void)
System Reset.
Definition: core_cm0.h:647
#define __IO
Definition: core_cm0.h:198
USBD_Status USBD_CtlPrepareRx(USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len)
USBD_CtlPrepareRx receive data on the ctl pipe.
Definition: usbd_ioreq.c:138
#define USB_DFU_CONFIG_DESC_SIZ
Definition: usbd_dfu_core.h:49
uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ]
Definition: usbd_req.c:95
#define __ALIGN_BEGIN
uint16_t MAL_Init(void)
MAL_Init Initializes the Media on the STM32.
Definition: usbd_dfu_mal.c:95
#define STATUS_ERRUNKNOWN
Definition: usbd_dfu_core.h:96
#define CMD_GETCOMMANDS
uint8_t DeviceState
#define STATE_dfuMANIFEST_WAIT_RESET
Definition: usbd_dfu_core.h:74
void USB_OTG_BSP_mDelay(const uint32_t msec)
USB_OTG_BSP_mDelay This function provides delay time in milli sec.
#define USB_REQ_GET_DESCRIPTOR
Definition: usbd_def.h:81
uint8_t bmRequest
Definition: usb_core.h:182
#define Manifest_In_Progress
#define Manifest_complete
#define STATE_dfuUPLOAD_IDLE
Definition: usbd_dfu_core.h:75
static void DFU_LeaveDFUMode(void *pdev)
DFU_LeaveDFUMode Handles the sub-protocol DFU leave DFU mode request (leaves DFU mode and resets devi...
USBD_Class_cb_TypeDef DFU_cb
static uint8_t EP0_TxSent(void *pdev)
EP0_TxSent Handles the DFU control endpoint data IN stage.
static uint8_t * USBD_DFU_GetCfgDesc(uint8_t speed, uint16_t *length)
USBD_DFU_GetCfgDesc Returns configuration descriptor.
static __IO uint32_t usbd_dfu_AltSet
#define CMD_SETADDRESSPOINTER
static uint8_t * USBD_DFU_GetUsrStringDesc(uint8_t speed, uint8_t index, uint16_t *length)
USBD_DFU_GetUsrStringDesc Manages the transfer of memory interfaces string descriptors.
#define STATE_dfuERROR
Definition: usbd_dfu_core.h:76
uint32_t Manifest_State
#define STATUS_ERRSTALLEDPKT
Definition: usbd_dfu_core.h:97
uint16_t wLength
Definition: usb_core.h:186
#define USBD_IDX_INTERFACE_STR
Definition: usbd_def.h:65
uint16_t MAL_GetStatus(uint32_t SectorAddress, uint8_t Cmd, uint8_t *buffer)
MAL_GetStatus Get the status of a given memory.
Definition: usbd_dfu_mal.c:241
uint8_t bRequest
Definition: usb_core.h:183
static uint8_t usbd_dfu_DeInit(void *pdev, uint8_t cfgidx)
usbd_dfu_Init De-initializes the DFU layer.
static void DFU_Req_ABORT(void *pdev)
DFU_Req_ABORT Handles the DFU ABORT request.
#define NULL
Definition: usbd_def.h:50
#define STATE_dfuDNLOAD_IDLE
Definition: usbd_dfu_core.h:71
static uint32_t Pointer
static uint8_t usbd_dfu_Setup(void *pdev, USB_SETUP_REQ *req)
usbd_dfu_Setup Handles the DFU request parsing.
uint16_t MAL_Erase(uint32_t SectorAddress)
MAL_Erase Erase a sector of memory.
Definition: usbd_dfu_mal.c:141
static uint8_t usbd_dfu_Init(void *pdev, uint8_t cfgidx)
usbd_dfu_Init Initializes the DFU interface.
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION
Definition: usbd_def.h:95
static uint8_t EP0_RxReady(void *pdev)
EP0_RxReady Handles the DFU control endpoint data OUT stage.
void DCD_DevDisconnect(USB_OTG_CORE_HANDLE *pdev)
Disconnect device (disable internal pull-up)
Definition: usb_dcd.c:413
static void DFU_Req_CLRSTATUS(void *pdev)
DFU_Req_CLRSTATUS Handles the DFU CLRSTATUS request.
#define USB_REQ_TYPE_MASK
Definition: usbd_def.h:70
uint8_t DeviceStatus[6]
uint16_t wValue
Definition: usb_core.h:184
__ALIGN_BEGIN uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END
uint8_t * MAL_Read(uint32_t SectorAddress, uint32_t DataLength)
MAL_Read Read sectors of memory.
Definition: usbd_dfu_mal.c:211
header file for the usbd_desc.c file


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:20