usb_dfu.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @file
  3. * @brief USB DFU Class public header
  4. *
  5. */
  6. #ifndef _USB_DFU_H_
  7. #define _USB_DFU_H_
  8. /**\addtogroup USB_MODULE_DFU USB DFU class
  9. * \brief This module contains USB Device Firmware Upgrade class definitions.
  10. * \details This module based on
  11. * + [USB Device Firmware Upgrade Specification, Revision 1.1]
  12. * (https://www.usb.org/sites/default/files/DFU_1.1.pdf)
  13. * @{ */
  14. /** DFU Specification release */
  15. #define DFU_VERSION 0x0110
  16. /** DFU Class Subclass */
  17. #define DFU_SUBCLASS_DFU 0x01
  18. /** DFU Class runtime Protocol */
  19. #define DFU_PROTOCOL_RUNTIME 0x01
  20. /** DFU Class DFU mode Protocol */
  21. #define DFU_PROTOCOL_MODE 0x02
  22. /**
  23. * @brief DFU Class Specific Requests
  24. */
  25. #define DFU_REQUEST_DETACH 0x00
  26. #define DFU_REQUEST_DNLOAD 0x01
  27. #define DFU_REQUEST_UPLOAD 0x02
  28. #define DFU_REQUEST_GETSTATUS 0x03
  29. #define DFU_REQUEST_CLRSTATUS 0x04
  30. #define DFU_REQUEST_GETSTATE 0x05
  31. #define DFU_REQUEST_ABORT 0x06
  32. /** DFU FUNCTIONAL descriptor type */
  33. #define DFU_FUNC_DESC 0x21
  34. /** DFU attributes DFU Functional Descriptor */
  35. #define DFU_ATTR_WILL_DETACH 0x08
  36. #define DFU_ATTR_MANIFESTATION_TOLERANT 0x04
  37. #define DFU_ATTR_CAN_UPLOAD 0x02
  38. #define DFU_ATTR_CAN_DNLOAD 0x01
  39. /** bStatus values for the DFU_GETSTATUS response */
  40. #define DFU_STATUS_OK 0x00U
  41. #define DFU_STATUS_ERR_TARGET 0x01U
  42. #define DFU_STATUS_ERR_FILE 0x02U
  43. #define DFU_STATUS_ERR_WRITE 0x03U
  44. #define DFU_STATUS_ERR_ERASE 0x04U
  45. #define DFU_STATUS_ERR_CHECK_ERASED 0x05U
  46. #define DFU_STATUS_ERR_PROG 0x06U
  47. #define DFU_STATUS_ERR_VERIFY 0x07U
  48. #define DFU_STATUS_ERR_ADDRESS 0x08U
  49. #define DFU_STATUS_ERR_NOTDONE 0x09U
  50. #define DFU_STATUS_ERR_FIRMWARE 0x0AU
  51. #define DFU_STATUS_ERR_VENDOR 0x0BU
  52. #define DFU_STATUS_ERR_USB 0x0CU
  53. #define DFU_STATUS_ERR_POR 0x0DU
  54. #define DFU_STATUS_ERR_UNKNOWN 0x0EU
  55. #define DFU_STATUS_ERR_STALLEDPKT 0x0FU
  56. /** bState values for the DFU_GETSTATUS response */
  57. #define DFU_STATE_APP_IDLE 0U
  58. #define DFU_STATE_APP_DETACH 1U
  59. #define DFU_STATE_DFU_IDLE 2U
  60. #define DFU_STATE_DFU_DNLOAD_SYNC 3U
  61. #define DFU_STATE_DFU_DNLOAD_BUSY 4U
  62. #define DFU_STATE_DFU_DNLOAD_IDLE 5U
  63. #define DFU_STATE_DFU_MANIFEST_SYNC 6U
  64. #define DFU_STATE_DFU_MANIFEST 7U
  65. #define DFU_STATE_DFU_MANIFEST_WAIT_RESET 8U
  66. #define DFU_STATE_DFU_UPLOAD_IDLE 9U
  67. #define DFU_STATE_DFU_ERROR 10U
  68. /** Run-Time Functional Descriptor */
  69. struct dfu_runtime_descriptor {
  70. uint8_t bLength; /**<\brief Descriptor length in bytes.*/
  71. uint8_t bDescriptorType; /**<\brief DFU functional descriptor type.*/
  72. uint8_t bmAttributes; /**<\brief USB DFU capabilities \ref USB_DFU_CAPAB*/
  73. uint16_t wDetachTimeout; /**<\brief USB DFU detach timeout in ms.*/
  74. uint16_t wTransferSize; /**<\brief USB DFU maximum transfer block size in bytes.*/
  75. uint16_t bcdDFUVersion; /**<\brief USB DFU version \ref VERSION_BCD utility macro.*/
  76. } __PACKED;
  77. /**\brief Payload packet to response in DFU_GETSTATUS request */
  78. struct dfu_info {
  79. uint8_t bStatus; /**<\brief An indication of the status resulting from the
  80. * execution of the most recent request.*/
  81. uint8_t bPollTimeout; /**<\brief Minimum time (LSB) in ms, that the host should wait
  82. * before sending a subsequent DFU_GETSTATUS request.*/
  83. uint16_t wPollTimeout; /**<\brief Minimum time (MSB) in ms, that the host should wait
  84. * before sending a subsequent DFU_GETSTATUS request.*/
  85. uint8_t bState; /**<\brief An indication of the state that the device is going
  86. * to enter immediately following transmission of this response.*/
  87. uint8_t iString; /**<\brief Index of the status string descriptor.*/
  88. };
  89. #endif /* _USB_DFU_H_ */