aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2018-12-13 13:42:27 +0100
committerKévin Redon <kredon@sysmocom.de>2019-01-16 18:39:41 +0100
commitefd55db9cc4d1480eda1734088d99f6fdf7a1c45 (patch)
treeeb8e636ab28df41cd4b03183493926a0c06ebe99
parentdf28f25276abf7fa04e5b3dfa06579f7dd2f34d2 (diff)
add USB DFU description
uses the USB CDC ACM example code as template to create a USB DFU description according to USB DFU specification version 1.1 USB DFU stack is under LGPLv2.1 or later license Change-Id: I7bd6cb46b734ffe8a51f2de7083b4f9e76d385e6
-rw-r--r--config/usbd_config.h358
-rw-r--r--gcc/Makefile22
-rw-r--r--usb/class/dfu/device/dfudf.c186
-rw-r--r--usb/class/dfu/device/dfudf.h59
-rw-r--r--usb/class/dfu/device/dfudf_desc.h112
-rw-r--r--usb/class/dfu/usb_protocol_dfu.h150
-rw-r--r--usb_dfu_main.c (renamed from usb_cdc_echo_main.c)3
-rw-r--r--usb_start.c85
-rw-r--r--usb_start.h26
9 files changed, 712 insertions, 289 deletions
diff --git a/config/usbd_config.h b/config/usbd_config.h
index e8334ec..e33f4ba 100644
--- a/config/usbd_config.h
+++ b/config/usbd_config.h
@@ -14,33 +14,54 @@
#define CONF_USBD_HS_SP 0
#endif
-// ---- USB Device Stack CDC ACM Options ----
+// ---- USB Device Stack DFU Options ----
// <e> Enable String Descriptors
-// <id> usb_cdcd_acm_str_en
-#ifndef CONF_USB_CDCD_ACM_STR_EN
-#define CONF_USB_CDCD_ACM_STR_EN 0
+// <ID> USB_DFUD_STR_EN
+#ifndef CONF_USB_DFUD_STR_EN
+#define CONF_USB_DFUD_STR_EN 0
#endif
// <s> Language IDs
// <i> Language IDs in c format, split by comma (E.g., 0x0409 ...)
-// <id> usb_cdcd_acm_langid
-#ifndef CONF_USB_CDCD_ACM_LANGID
-#define CONF_USB_CDCD_ACM_LANGID "0x0409"
+// <id> usb_dufd_langid
+#ifndef CONF_USB_DFUD_LANGID
+#define CONF_USB_DFUD_LANGID "0x0409"
#endif
-#ifndef CONF_USB_CDCD_ACM_LANGID_DESC
-#define CONF_USB_CDCD_ACM_LANGID_DESC
+#ifndef CONF_USB_DFUD_LANGID_DESC
+#define CONF_USB_DFUD_LANGID_DESC 4, 0x03, 0x09, 0x04,
#endif
// </e>
-// <h> CDC ACM Device Descriptor
+// <h> DFU Device Descriptor
// <o> bcdUSB
// <0x0200=> USB 2.0 version
// <0x0210=> USB 2.1 version
-// <id> usb_cdcd_acm_bcdusb
-#ifndef CONF_USB_CDCD_ACM_BCDUSB
-#define CONF_USB_CDCD_ACM_BCDUSB 0x200
+// <id> usb_dfud_bcdusb
+#ifndef CONF_USB_DFUD_BCDUSB
+#define CONF_USB_DFUD_BCDUSB 0x200
+#endif
+
+// <o> bDeviceClass
+// <0=> unused
+// <id> usb_dfud_bdeviceclass
+#ifndef CONF_USB_DFUD_BDEVICECLASS
+#define CONF_USB_DFUD_BDEVICECLASS 0
+#endif
+
+// <o> bDeviceSubClass
+// <0=> unused
+// <id> usb_dfud_bdevicesubclass
+#ifndef CONF_USB_DFUD_BDEVICESUBCLASS
+#define CONF_USB_DFUD_BDEVICESUBCLASS 0
+#endif
+
+// <o> bDeviceProtocol
+// <0=> unused
+// <id> usb_dfud_bdeviceprotocol
+#ifndef CONF_USB_DFUD_BDEVICEPROTOCOL
+#define CONF_USB_DFUD_BDEVICEPROTOCOL 0
#endif
// <o> bMaxPackeSize0
@@ -48,133 +69,149 @@
// <0x0010=> 16 bytes
// <0x0020=> 32 bytes
// <0x0040=> 64 bytes
-// <id> usb_cdcd_acm_bmaxpksz0
-#ifndef CONF_USB_CDCD_ACM_BMAXPKSZ0
-#define CONF_USB_CDCD_ACM_BMAXPKSZ0 0x40
+// <id> usb_dufd_bmaxpksz0
+#ifndef CONF_USB_DFUD_BMAXPKSZ0
+#define CONF_USB_DFUD_BMAXPKSZ0 0x40
#endif
-// <o> idVender <0x0000-0xFFFF>
-// <id> usb_cdcd_acm_idvender
-#ifndef CONF_USB_CDCD_ACM_IDVENDER
-#define CONF_USB_CDCD_ACM_IDVENDER 0x3eb
+// <o> idVendor <0x0000-0xFFFF>
+// <0x1d50=> OpenMoko
+// <id> usb_octsim_idvendor
+#ifndef CONF_USB_OCTSIM_IDVENDOR
+#define CONF_USB_OCTSIM_IDVENDOR 0x1d50
#endif
// <o> idProduct <0x0000-0xFFFF>
-// <id> usb_cdcd_acm_idproduct
-#ifndef CONF_USB_CDCD_ACM_IDPRODUCT
-#define CONF_USB_CDCD_ACM_IDPRODUCT 0x2404
+// <0x6140=> sysmoOCTSIM
+// <id> usb_dufd_idproduct
+#ifndef CONF_USB_OCTSIM_IDPRODUCT
+#define CONF_USB_OCTSIM_IDPRODUCT 0x6140
#endif
// <o> bcdDevice <0x0000-0xFFFF>
-// <id> usb_cdcd_acm_bcddevice
-#ifndef CONF_USB_CDCD_ACM_BCDDEVICE
-#define CONF_USB_CDCD_ACM_BCDDEVICE 0x100
+// <id> usb_dufd_bcddevice
+#ifndef CONF_USB_DFUD_BCDDEVICE
+#define CONF_USB_DFUD_BCDDEVICE 0x000
#endif
// <e> Enable string descriptor of iManufact
-// <id> usb_cdcd_acm_imanufact_en
-#ifndef CONF_USB_CDCD_ACM_IMANUFACT_EN
-#define CONF_USB_CDCD_ACM_IMANUFACT_EN 0
+// <id> usb_dufd_imanufact_en
+#ifndef CONF_USB_DFUD_IMANUFACT_EN
+#define CONF_USB_DFUD_IMANUFACT_EN 1
#endif
-#ifndef CONF_USB_CDCD_ACM_IMANUFACT
-#define CONF_USB_CDCD_ACM_IMANUFACT (CONF_USB_CDCD_ACM_IMANUFACT_EN * (CONF_USB_CDCD_ACM_IMANUFACT_EN))
+#ifndef CONF_USB_DFUD_IMANUFACT
+#define CONF_USB_DFUD_IMANUFACT (CONF_USB_DFUD_IMANUFACT_EN * (CONF_USB_DFUD_IMANUFACT_EN))
#endif
// <s> Unicode string of iManufact
-// <id> usb_cdcd_acm_imanufact_str
-#ifndef CONF_USB_CDCD_ACM_IMANUFACT_STR
-#define CONF_USB_CDCD_ACM_IMANUFACT_STR "Atmel"
+// <id> usb_dufd_imanufact_str
+#ifndef CONF_USB_DFUD_IMANUFACT_STR
+#define CONF_USB_DFUD_IMANUFACT_STR "sysmocom"
#endif
-#ifndef CONF_USB_CDCD_ACM_IMANUFACT_STR_DESC
-#define CONF_USB_CDCD_ACM_IMANUFACT_STR_DESC
+#ifndef CONF_USB_DFUD_IMANUFACT_STR_DESC
+#define CONF_USB_DFUD_IMANUFACT_STR_DESC 18, 0x03, 's', 0x00, 'y', 0x00, 's', 0x00, 'm', 0x00, 'o', 0x00, 'c', 0x00, 'o', 0x00, 'm', 0x00,
#endif
// </e>
// <e> Enable string descriptor of iProduct
-// <id> usb_cdcd_acm_iproduct_en
-#ifndef CONF_USB_CDCD_ACM_IPRODUCT_EN
-#define CONF_USB_CDCD_ACM_IPRODUCT_EN 0
+// <id> usb_dufd_iproduct_en
+#ifndef CONF_USB_DFUD_IPRODUCT_EN
+#define CONF_USB_DFUD_IPRODUCT_EN 1
#endif
-#ifndef CONF_USB_CDCD_ACM_IPRODUCT
-#define CONF_USB_CDCD_ACM_IPRODUCT \
- (CONF_USB_CDCD_ACM_IPRODUCT_EN * (CONF_USB_CDCD_ACM_IMANUFACT_EN + CONF_USB_CDCD_ACM_IPRODUCT_EN))
+#ifndef CONF_USB_DFUD_IPRODUCT
+#define CONF_USB_DFUD_IPRODUCT \
+ (CONF_USB_DFUD_IPRODUCT_EN * (CONF_USB_DFUD_IMANUFACT_EN + CONF_USB_DFUD_IPRODUCT_EN))
#endif
// <s> Unicode string of iProduct
-// <id> usb_cdcd_acm_iproduct_str
-#ifndef CONF_USB_CDCD_ACM_IPRODUCT_STR
-#define CONF_USB_CDCD_ACM_IPRODUCT_STR "CDC ACM Serial Bridge Demo"
+// <id> usb_dufd_iproduct_str
+#ifndef CONF_USB_DFUD_IPRODUCT_STR
+#define CONF_USB_DFUD_IPRODUCT_STR "sysmoOCTSIM"
#endif
-#ifndef CONF_USB_CDCD_ACM_IPRODUCT_STR_DESC
-#define CONF_USB_CDCD_ACM_IPRODUCT_STR_DESC
+#ifndef CONF_USB_DFUD_IPRODUCT_STR_DESC
+#define CONF_USB_DFUD_IPRODUCT_STR_DESC 24, 0x03, 's', 0x00, 'y', 0x00, 's', 0x00, 'm', 0x00, 'o', 0x00, 'O', 0x00, 'C', 0x00, 'T', 0x00, 'S', 0x00, 'I', 0x00, 'M', 0x00,
#endif
// </e>
// <e> Enable string descriptor of iSerialNum
-// <id> usb_cdcd_acm_iserialnum_en
-#ifndef CONF_USB_CDCD_ACM_ISERIALNUM_EN
-#define CONF_USB_CDCD_ACM_ISERIALNUM_EN 0
+// <id> usb_dufd_iserialnum_en
+#ifndef CONF_USB_DFUD_ISERIALNUM_EN
+#define CONF_USB_DFUD_ISERIALNUM_EN 0
#endif
-#ifndef CONF_USB_CDCD_ACM_ISERIALNUM
-#define CONF_USB_CDCD_ACM_ISERIALNUM \
- (CONF_USB_CDCD_ACM_ISERIALNUM_EN \
- * (CONF_USB_CDCD_ACM_IMANUFACT_EN + CONF_USB_CDCD_ACM_IPRODUCT_EN + CONF_USB_CDCD_ACM_ISERIALNUM_EN))
+#ifndef CONF_USB_DFUD_ISERIALNUM
+#define CONF_USB_DFUD_ISERIALNUM \
+ (CONF_USB_DFUD_ISERIALNUM_EN \
+ * (CONF_USB_DFUD_IMANUFACT_EN + CONF_USB_DFUD_IPRODUCT_EN + CONF_USB_DFUD_ISERIALNUM_EN))
#endif
// <s> Unicode string of iSerialNum
-// <id> usb_cdcd_acm_iserialnum_str
-#ifndef CONF_USB_CDCD_ACM_ISERIALNUM_STR
-#define CONF_USB_CDCD_ACM_ISERIALNUM_STR "123456789ABCDEF"
+// <id> usb_dufd_iserialnum_str
+#ifndef CONF_USB_DFUD_ISERIALNUM_STR
+#define CONF_USB_DFUD_ISERIALNUM_STR "123456789ABCDEF"
#endif
-#ifndef CONF_USB_CDCD_ACM_ISERIALNUM_STR_DESC
-#define CONF_USB_CDCD_ACM_ISERIALNUM_STR_DESC
+#ifndef CONF_USB_DFUD_ISERIALNUM_STR_DESC
+#define CONF_USB_DFUD_ISERIALNUM_STR_DESC
#endif
// </e>
// <o> bNumConfigurations <0x01-0xFF>
-// <id> usb_cdcd_acm_bnumconfig
-#ifndef CONF_USB_CDCD_ACM_BNUMCONFIG
-#define CONF_USB_CDCD_ACM_BNUMCONFIG 0x1
+// <id> usb_dufd_bnumconfig
+#ifndef CONF_USB_DFUD_BNUMCONFIG
+#define CONF_USB_DFUD_BNUMCONFIG 0x1
#endif
// </h>
-// <h> CDC ACM Configuration Descriptor
+// <h> DFU Configuration Descriptor
+
+// <o> wTotalLength <0x01-0xFF>
+// <id> usb_dufd_wtotallength
+#ifndef CONF_USB_DFUD_WTOTALLENGTH
+#define CONF_USB_DFUD_WTOTALLENGTH 27
+#endif
+
+// <o> bNumInterfaces <0x01-0xFF>
+// <id> usb_dufd_bnuminterfaces
+#ifndef CONF_USB_DFUD_BNUMINTERFACES
+#define CONF_USB_DFUD_BNUMINTERFACES 1
+#endif
+
// <o> bConfigurationValue <0x01-0xFF>
-// <id> usb_cdcd_acm_bconfigval
-#ifndef CONF_USB_CDCD_ACM_BCONFIGVAL
-#define CONF_USB_CDCD_ACM_BCONFIGVAL 0x1
+// <id> usb_dufd_bconfigval
+#ifndef CONF_USB_DFUD_BCONFIGVAL
+#define CONF_USB_DFUD_BCONFIGVAL 0x1
#endif
+
// <e> Enable string descriptor of iConfig
-// <id> usb_cdcd_acm_iconfig_en
-#ifndef CONF_USB_CDCD_ACM_ICONFIG_EN
-#define CONF_USB_CDCD_ACM_ICONFIG_EN 0
+// <id> usb_dufd_iconfig_en
+#ifndef CONF_USB_DFUD_ICONFIG_EN
+#define CONF_USB_DFUD_ICONFIG_EN 0
#endif
-#ifndef CONF_USB_CDCD_ACM_ICONFIG
-#define CONF_USB_CDCD_ACM_ICONFIG \
- (CONF_USB_CDCD_ACM_ICONFIG_EN \
- * (CONF_USB_CDCD_ACM_IMANUFACT_EN + CONF_USB_CDCD_ACM_IPRODUCT_EN + CONF_USB_CDCD_ACM_ISERIALNUM_EN \
- + CONF_USB_CDCD_ACM_ICONFIG_EN))
+#ifndef CONF_USB_DFUD_ICONFIG
+#define CONF_USB_DFUD_ICONFIG \
+ (CONF_USB_DFUD_ICONFIG_EN \
+ * (CONF_USB_DFUD_IMANUFACT_EN + CONF_USB_DFUD_IPRODUCT_EN + CONF_USB_DFUD_ISERIALNUM_EN \
+ + CONF_USB_DFUD_ICONFIG_EN))
#endif
// <s> Unicode string of iConfig
-// <id> usb_cdcd_acm_iconfig_str
-#ifndef CONF_USB_CDCD_ACM_ICONFIG_STR
-#define CONF_USB_CDCD_ACM_ICONFIG_STR ""
+// <id> usb_dufd_iconfig_str
+#ifndef CONF_USB_DFUD_ICONFIG_STR
+#define CONF_USB_DFUD_ICONFIG_STR ""
#endif
-#ifndef CONF_USB_CDCD_ACM_ICONFIG_STR_DESC
-#define CONF_USB_CDCD_ACM_ICONFIG_STR_DESC
+#ifndef CONF_USB_DFUD_ICONFIG_STR_DESC
+#define CONF_USB_DFUD_ICONFIG_STR_DESC
#endif
// </e>
@@ -184,157 +221,62 @@
// <0xA0=> Bus power supply, support for remote wakeup
// <0xC0=> Self powered, not support for remote wakeup
// <0xE0=> Self powered, support for remote wakeup
-// <id> usb_cdcd_acm_bmattri
-#ifndef CONF_USB_CDCD_ACM_BMATTRI
-#define CONF_USB_CDCD_ACM_BMATTRI 0x80
+// <id> usb_dufd_bmattri
+#ifndef CONF_USB_DFUD_BMATTRI
+#define CONF_USB_DFUD_BMATTRI 0x80
#endif
// <o> bMaxPower <0x00-0xFF>
-// <id> usb_cdcd_acm_bmaxpower
-#ifndef CONF_USB_CDCD_ACM_BMAXPOWER
-#define CONF_USB_CDCD_ACM_BMAXPOWER 0x32
+// <id> usb_dufd_bmaxpower
+#ifndef CONF_USB_DFUD_BMAXPOWER
+#define CONF_USB_DFUD_BMAXPOWER 0x32
#endif
// </h>
-// <h> CDC ACM Communication Interface Descriptor
+// <h> DFU Interface Descriptor
// <o> bInterfaceNumber <0x00-0xFF>
-// <id> usb_cdcd_acm_comm_bifcnum
-#ifndef CONF_USB_CDCD_ACM_COMM_BIFCNUM
-#define CONF_USB_CDCD_ACM_COMM_BIFCNUM 0x0
-#endif
-// <o> bAlternateSetting <0x00-0xFF>
-// <id> usb_cdcd_acm_comm_baltset
-#ifndef CONF_USB_CDCD_ACM_COMM_BALTSET
-#define CONF_USB_CDCD_ACM_COMM_BALTSET 0x0
-#endif
-
-// <o> iInterface <0x00-0xFF>
-// <id> usb_cdcd_acm_comm_iifc
-#ifndef CONF_USB_CDCD_ACM_COMM_IIFC
-#define CONF_USB_CDCD_ACM_COMM_IIFC 0x0
-#endif
-
-// <o> Interrupt IN Endpoint Address
-// <0x81=> EndpointAddress = 0x81
-// <0x82=> EndpointAddress = 0x82
-// <0x83=> EndpointAddress = 0x83
-// <0x84=> EndpointAddress = 0x84
-// <0x85=> EndpointAddress = 0x85
-// <0x86=> EndpointAddress = 0x86
-// <0x87=> EndpointAddress = 0x87
-// <id> usb_cdcd_acm_epaddr
-#ifndef CONF_USB_CDCD_ACM_COMM_INT_EPADDR
-#define CONF_USB_CDCD_ACM_COMM_INT_EPADDR 0x82
-#endif
-
-// <o> Interrupt IN Endpoint wMaxPacketSize
-// <0x0008=> 8 bytes
-// <0x0010=> 16 bytes
-// <0x0020=> 32 bytes
-// <0x0040=> 64 bytes
-// <id> usb_cdcd_acm_comm_int_maxpksz
-#ifndef CONF_USB_CDCD_ACM_COMM_INT_MAXPKSZ
-#define CONF_USB_CDCD_ACM_COMM_INT_MAXPKSZ 0x40
+// <id> usb_dufd_bifcnum
+#ifndef CONF_USB_DFUD_BIFCNUM
+#define CONF_USB_DFUD_BIFCNUM 0x0
#endif
-// <o> Interrupt IN Endpoint Interval <0x00-0xFF>
-// <id> usb_cdcd_acm_comm_int_interval
-#ifndef CONF_USB_CDCD_ACM_COMM_INT_INTERVAL
-#define CONF_USB_CDCD_ACM_COMM_INT_INTERVAL 0xa
-#endif
-// </h>
-
-// <h> CDC ACM Data Interface Descriptor
-
-// <o> bInterfaceNumber <0x00-0xFF>
-// <id> usb_cdcd_acm_data_bifcnum
-#ifndef CONF_USB_CDCD_ACM_DATA_BIFCNUM
-#define CONF_USB_CDCD_ACM_DATA_BIFCNUM 0x1
-#endif
// <o> bAlternateSetting <0x00-0xFF>
-// <id> usb_cdcd_acm_data_baltset
-#ifndef CONF_USB_CDCD_ACM_DATA_BALTSET
-#define CONF_USB_CDCD_ACM_DATA_BALTSET 0x0
+// <id> usb_dufd_baltset
+#ifndef CONF_USB_DFUD_BALTSET
+#define CONF_USB_DFUD_BALTSET 0x0
#endif
-// <o> iInterface <0x00-0xFF>
-// <id> usb_cdcd_acm_data_iifc
-#ifndef CONF_USB_CDCD_ACM_DATA_IIFC
-#define CONF_USB_CDCD_ACM_DATA_IIFC 0x0
+// <o> bNumEndpoints <0x00-0xFF>
+// <id> usb_dufd_bnumep
+#ifndef CONF_USB_DFUD_BNUMEP
+#define CONF_USB_DFUD_BNUMEP 0x0
#endif
-// <o> BULK IN Endpoint Address
-// <0x81=> EndpointAddress = 0x81
-// <0x82=> EndpointAddress = 0x82
-// <0x83=> EndpointAddress = 0x83
-// <0x84=> EndpointAddress = 0x84
-// <0x85=> EndpointAddress = 0x85
-// <0x86=> EndpointAddress = 0x86
-// <0x87=> EndpointAddress = 0x87
-// <id> usb_cdcd_acm_data_bulkin_epaddr
-#ifndef CONF_USB_CDCD_ACM_DATA_BULKIN_EPADDR
-#define CONF_USB_CDCD_ACM_DATA_BULKIN_EPADDR 0x81
+// <e> Enable string descriptor of iInterface
+// <id> usb_dufd_iinterface_en
+#ifndef CONF_USB_DFUD_IINTERFACE_EN
+#define CONF_USB_DFUD_IINTERFACE_EN 1
#endif
-// <o> BULK IN Endpoint wMaxPacketSize
-// <0x0008=> 8 bytes
-// <0x0010=> 16 bytes
-// <0x0020=> 32 bytes
-// <0x0040=> 64 bytes
-// <id> usb_cdcd_acm_data_builin_maxpksz
-#ifndef CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ
-#define CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ 0x40
+#ifndef CONF_USB_DFUD_IINTERFACE
+#define CONF_USB_DFUD_IINTERFACE \
+ (CONF_USB_DFUD_IINTERFACE_EN \
+ * (CONF_USB_DFUD_IMANUFACT_EN + CONF_USB_DFUD_IPRODUCT_EN + CONF_USB_DFUD_ISERIALNUM_EN \
+ + CONF_USB_DFUD_ICONFIG_EN + CONF_USB_DFUD_IINTERFACE_EN))
#endif
-// <o> BULK IN Endpoint wMaxPacketSize for High Speed
-// <0x0008=> 8 bytes
-// <0x0010=> 16 bytes
-// <0x0020=> 32 bytes
-// <0x0040=> 64 bytes
-// <0x0080=> 128 bytes
-// <0x0100=> 256 bytes
-// <0x0200=> 512 bytes
-// <id> usb_cdcd_acm_data_builin_maxpksz_hs
-#ifndef CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ_HS
-#define CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ_HS 0x200
-#endif
-
-// <o> BULK OUT Endpoint Address
-// <0x01=> EndpointAddress = 0x01
-// <0x02=> EndpointAddress = 0x02
-// <0x03=> EndpointAddress = 0x03
-// <0x04=> EndpointAddress = 0x04
-// <0x05=> EndpointAddress = 0x05
-// <0x06=> EndpointAddress = 0x06
-// <0x07=> EndpointAddress = 0x07
-// <id> usb_cdcd_acm_data_bulkout_epaddr
-#ifndef CONF_USB_CDCD_ACM_DATA_BULKOUT_EPADDR
-#define CONF_USB_CDCD_ACM_DATA_BULKOUT_EPADDR 0x1
-#endif
-
-// <o> BULK OUT Endpoint wMaxPacketSize
-// <0x0008=> 8 bytes
-// <0x0010=> 16 bytes
-// <0x0020=> 32 bytes
-// <0x0040=> 64 bytes
-// <id> usb_cdcd_acm_data_buckout_maxpksz
-#ifndef CONF_USB_CDCD_ACM_DATA_BULKOUT_MAXPKSZ
-#define CONF_USB_CDCD_ACM_DATA_BULKOUT_MAXPKSZ 0x40
+// <s> Unicode string of iInterface
+// <id> usb_dufd_iinterface_str
+#ifndef CONF_USB_DFUD_IINTERFAGE_STR
+#define CONF_USB_DFUD_IINTERFACE_STR "SAM D5x/E5x DFU bootloader (DFU mode)"
#endif
-// <o> BULK OUT Endpoint wMaxPacketSize for High Speed
-// <0x0008=> 8 bytes
-// <0x0010=> 16 bytes
-// <0x0020=> 32 bytes
-// <0x0040=> 64 bytes
-// <0x0080=> 128 bytes
-// <0x0100=> 256 bytes
-// <0x0200=> 512 bytes
-// <id> usb_cdcd_acm_data_buckout_maxpksz_hs
-#ifndef CONF_USB_CDCD_ACM_DATA_BULKOUT_MAXPKSZ_HS
-#define CONF_USB_CDCD_ACM_DATA_BULKOUT_MAXPKSZ_HS 0x200
+#ifndef CONF_USB_DFUD_IINTERFACE_STR_DESC
+#define CONF_USB_DFUD_IINTERFACE_STR_DESC 76, 0x03, 'S', 0x00, 'A', 0x00, 'M', 0x00, ' ', 0x00, 'D', 0x00, '5', 0x00, 'x', 0x00, '/', 0x00, 'E', 0x00, '5', 0x00, 'x', 0x00, ' ', 0x00, 'D', 0x00, 'F', 0x00, 'U', 0x00, ' ', 0x00, 'b', 0x00, 'o', 0x00, 'o', 0x00, 't', 0x00, 'l', 0x00, 'o', 0x00, 'a', 0x00, 'd', 0x00, 'e', 0x00, 'r', 0x00, ' ', 0x00, '(', 0x00, 'D', 0x00, 'F', 0x00, 'U', 0x00, ' ', 0x00, 'm', 0x00, 'o', 0x00, 'd', 0x00, 'e', 0x00, ')', 0x00,
#endif
+
+// </e>
// </h>
// <<< end of configuration section >>>
diff --git a/gcc/Makefile b/gcc/Makefile
index 6542661..231ed39 100644
--- a/gcc/Makefile
+++ b/gcc/Makefile
@@ -31,7 +31,7 @@ gcc \
hpl/osc32kctrl \
hpl/ramecc \
hpl/dmac \
-usb/class/cdc/device \
+usb/class/dfu/device \
hal/src \
hpl/mclk \
usb \
@@ -49,7 +49,7 @@ hpl/cmcc
OBJS += \
hal/src/hal_io.o \
hpl/core/hpl_core_m4.o \
-usb/class/cdc/device/cdcdf_acm.o \
+usb/class/dfu/device/dfudf.o \
hal/utils/src/utils_syscalls.o \
hpl/dmac/hpl_dmac.o \
gcc/system_same54.o \
@@ -77,14 +77,14 @@ hal/src/hal_sleep.o \
hal/src/hal_cache.o \
hpl/cmcc/hpl_cmcc.o \
atmel_start.o \
-usb_cdc_echo_main.o \
+usb_dfu_main.o \
usb/device/usbdc.o \
hal/src/hal_atomic.o
OBJS_AS_ARGS += \
"hal/src/hal_io.o" \
"hpl/core/hpl_core_m4.o" \
-"usb/class/cdc/device/cdcdf_acm.o" \
+"usb/class/dfu/device/dfudf.o" \
"hal/utils/src/utils_syscalls.o" \
"hpl/dmac/hpl_dmac.o" \
"gcc/system_same54.o" \
@@ -112,7 +112,7 @@ OBJS_AS_ARGS += \
"hal/src/hal_cache.o" \
"hpl/cmcc/hpl_cmcc.o" \
"atmel_start.o" \
-"usb_cdc_echo_main.o" \
+"usb_dfu_main.o" \
"usb/device/usbdc.o" \
"hal/src/hal_atomic.o"
@@ -125,7 +125,7 @@ DEPS_AS_ARGS += \
"hpl/ramecc/hpl_ramecc.d" \
"hpl/core/hpl_core_m4.d" \
"hal/utils/src/utils_syscalls.d" \
-"usb/class/cdc/device/cdcdf_acm.d" \
+"usb/class/dfu/device/dfudf.d" \
"gcc/gcc/startup_same54.d" \
"hpl/usb/hpl_usb.d" \
"hal/utils/src/utils_list.d" \
@@ -140,7 +140,7 @@ DEPS_AS_ARGS += \
"hal/src/hal_usb_device.d" \
"hpl/dmac/hpl_dmac.d" \
"hal/src/hal_init.d" \
-"usb_cdc_echo_main.d" \
+"usb_dfu_main.d" \
"hpl/mclk/hpl_mclk.d" \
"driver_init.d" \
"hpl/osc32kctrl/hpl_osc32kctrl.d" \
@@ -199,7 +199,7 @@ $(OUTPUT_FILE_PATH): $(OBJS)
@echo ARM/GNU C Compiler
$(QUOTE)arm-none-eabi-gcc$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
-D__SAME54P20A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
--I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include" \
+-I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include" \
-MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<
@@ -208,7 +208,7 @@ $(OUTPUT_FILE_PATH): $(OBJS)
@echo ARM/GNU Assembler
$(QUOTE)arm-none-eabi-as$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
-D__SAME54P20A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
--I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include" \
+-I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include" \
-MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<
@@ -217,7 +217,7 @@ $(OUTPUT_FILE_PATH): $(OBJS)
@echo ARM/GNU Preprocessing Assembler
$(QUOTE)arm-none-eabi-gcc$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
-D__SAME54P20A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
--I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include" \
+-I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include" \
-MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<
@@ -237,4 +237,4 @@ clean:
rm -f $(DEPS_AS_ARGS)
rm -f $(OUTPUT_FILE_NAME).a $(OUTPUT_FILE_NAME).hex $(OUTPUT_FILE_NAME).bin \
$(OUTPUT_FILE_NAME).lss $(OUTPUT_FILE_NAME).eep $(OUTPUT_FILE_NAME).map \
- $(OUTPUT_FILE_NAME).srec \ No newline at end of file
+ $(OUTPUT_FILE_NAME).srec
diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c
new file mode 100644
index 0000000..7747a23
--- /dev/null
+++ b/usb/class/dfu/device/dfudf.c
@@ -0,0 +1,186 @@
+/**
+ * \file
+ *
+ * \brief USB Device Stack DFU Function Implementation.
+ *
+ * Copyright (c) 2018 sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dfudf.h"
+#include "usb_protocol_dfu.h"
+
+/** USB Device DFU Fucntion Specific Data */
+struct dfudf_func_data {
+ /** DFU Interface information */
+ uint8_t func_iface;
+ /** DFU Enable Flag */
+ bool enabled;
+};
+
+static struct usbdf_driver _dfudf;
+static struct dfudf_func_data _dfudf_funcd;
+
+/**
+ * \brief Enable DFU Function
+ * \param[in] drv Pointer to USB device function driver
+ * \param[in] desc Pointer to USB interface descriptor
+ * \return Operation status.
+ */
+static int32_t dfudf_enable(struct usbdf_driver *drv, struct usbd_descriptors *desc)
+{
+ struct dfudf_func_data *func_data = (struct dfudf_func_data *)(drv->func_data);
+
+ usb_iface_desc_t ifc_desc;
+ uint8_t * ifc;
+ uint8_t i;
+
+ ifc = desc->sod;
+ for (i = 0; i < 2; i++) {
+ if (NULL == ifc) {
+ return ERR_NOT_FOUND;
+ }
+
+ ifc_desc.bInterfaceNumber = ifc[2];
+ ifc_desc.bInterfaceClass = ifc[5];
+
+ if (USB_DFU_CLASS == ifc_desc.bInterfaceClass) {
+ if (func_data->func_iface == ifc_desc.bInterfaceNumber) { // Initialized
+ return ERR_ALREADY_INITIALIZED;
+ } else if (func_data->func_iface != 0xFF) { // Occupied
+ return ERR_NO_RESOURCE;
+ } else {
+ func_data->func_iface = ifc_desc.bInterfaceNumber;
+ }
+ } else { // Not supported by this function driver
+ return ERR_NOT_FOUND;
+ }
+
+ // there are no endpoint to install since DFU uses only the control endpoint
+
+ ifc = usb_find_desc(usb_desc_next(desc->sod), desc->eod, USB_DT_INTERFACE);
+ }
+ // Installed
+ _dfudf_funcd.enabled = true;
+ return ERR_NONE;
+}
+
+/**
+ * \brief Disable DFU Function
+ * \param[in] drv Pointer to USB device function driver
+ * \param[in] desc Pointer to USB device descriptor
+ * \return Operation status.
+ */
+static int32_t dfudf_disable(struct usbdf_driver *drv, struct usbd_descriptors *desc)
+{
+ struct dfudf_func_data *func_data = (struct dfudf_func_data *)(drv->func_data);
+
+ usb_iface_desc_t ifc_desc;
+
+ if (desc) {
+ ifc_desc.bInterfaceClass = desc->sod[5];
+ // Check interface
+ if (ifc_desc.bInterfaceClass != USB_DFU_CLASS) {
+ return ERR_NOT_FOUND;
+ }
+ }
+
+ func_data->func_iface = 0xFF;
+
+ _dfudf_funcd.enabled = false;
+ return ERR_NONE;
+}
+
+/**
+ * \brief DFU Control Function
+ * \param[in] drv Pointer to USB device function driver
+ * \param[in] ctrl USB device general function control type
+ * \param[in] param Parameter pointer
+ * \return Operation status.
+ */
+static int32_t dfudf_ctrl(struct usbdf_driver *drv, enum usbdf_control ctrl, void *param)
+{
+ switch (ctrl) {
+ case USBDF_ENABLE:
+ return dfudf_enable(drv, (struct usbd_descriptors *)param);
+
+ case USBDF_DISABLE:
+ return dfudf_disable(drv, (struct usbd_descriptors *)param);
+
+ case USBDF_GET_IFACE:
+ return ERR_UNSUPPORTED_OP;
+
+ default:
+ return ERR_INVALID_ARG;
+ }
+}
+
+/**
+ * \brief Process the CDC class request
+ * \param[in] ep Endpoint address.
+ * \param[in] req Pointer to the request.
+ * \return Operation status.
+ */
+static int32_t dfudf_req(uint8_t ep, struct usb_req *req, enum usb_ctrl_stage stage)
+{
+ if (0x01 != ((req->bmRequestType >> 5) & 0x03)) { // class request
+ return ERR_NOT_FOUND;
+ }
+ if ((req->wIndex == _dfudf_funcd.func_iface)) {
+ // we don't verify the bmRequestType
+ switch (req->bRequest) {
+ default:
+ return ERR_UNSUPPORTED_OP;
+ }
+ } else {
+ return ERR_NOT_FOUND;
+ }
+}
+
+/** USB Device DFU Handler Struct */
+static struct usbdc_handler dfudf_req_h = {NULL, (FUNC_PTR)dfudf_req};
+
+/**
+ * \brief Initialize the USB DFU Function Driver
+ */
+int32_t dfudf_init(void)
+{
+ if (usbdc_get_state() > USBD_S_POWER) {
+ return ERR_DENIED;
+ }
+
+ _dfudf.ctrl = dfudf_ctrl;
+ _dfudf.func_data = &_dfudf_funcd;
+
+ usbdc_register_function(&_dfudf);
+ usbdc_register_handler(USBDC_HDL_REQ, &dfudf_req_h);
+ return ERR_NONE;
+}
+
+/**
+ * \brief Deinitialize the USB DFU Function Driver
+ */
+void dfudf_deinit(void)
+{
+}
+
+/**
+ * \brief Check whether DFU Function is enabled
+ */
+bool dfudf_is_enabled(void)
+{
+ return _dfudf_funcd.enabled;
+}
diff --git a/usb/class/dfu/device/dfudf.h b/usb/class/dfu/device/dfudf.h
new file mode 100644
index 0000000..ba5cdd5
--- /dev/null
+++ b/usb/class/dfu/device/dfudf.h
@@ -0,0 +1,59 @@
+/**
+ * \file
+ *
+ * \brief USB Device Stack DFU Function Definition.
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ * Copyright (c) 2018 sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ */
+
+#ifndef USBDF_DFU_H_
+#define USBDF_DFU_H_
+
+#include "usbdc.h"
+
+/**
+ * \brief Initialize the USB DFU Function Driver
+ * \return Operation status.
+ */
+int32_t dfudf_init(void);
+
+/**
+ * \brief Deinitialize the USB DFU Function Driver
+ * \return Operation status.
+ */
+void dfudf_deinit(void);
+
+/**
+ * \brief Check whether DFU Function is enabled
+ * \return Operation status.
+ * \return true DFU Function is enabled
+ * \return false DFU Function is disabled
+ */
+bool dfudf_is_enabled(void);
+
+#endif /* USBDF_DFU_H_ */
diff --git a/usb/class/dfu/device/dfudf_desc.h b/usb/class/dfu/device/dfudf_desc.h
new file mode 100644
index 0000000..f9eca38
--- /dev/null
+++ b/usb/class/dfu/device/dfudf_desc.h
@@ -0,0 +1,112 @@
+/**
+ * \file
+ *
+ * \brief USB Device Stack DFU Function Descriptor Setting.
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ * Copyright (c) 2018 sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ */
+
+#ifndef USBDF_DFU_DESC_H_
+#define USBDF_DFU_DESC_H_
+
+#include "usb_protocol.h"
+#include "usbd_config.h"
+#include "usb_protocol_dfu.h"
+
+#define DFUD_DEV_DESC \
+ USB_DEV_DESC_BYTES(CONF_USB_DFUD_BCDUSB, \
+ CONF_USB_DFUD_BDEVICECLASS, \
+ CONF_USB_DFUD_BDEVICESUBCLASS, \
+ CONF_USB_DFUD_BDEVICEPROTOCOL, \
+ CONF_USB_DFUD_BMAXPKSZ0, \
+ CONF_USB_OCTSIM_IDVENDOR, \
+ CONF_USB_OCTSIM_IDPRODUCT, \
+ CONF_USB_DFUD_BCDDEVICE, \
+ CONF_USB_DFUD_IMANUFACT, \
+ CONF_USB_DFUD_IPRODUCT, \
+ CONF_USB_DFUD_ISERIALNUM, \
+ CONF_USB_DFUD_BNUMCONFIG)
+
+#define DFUD_DEV_QUAL_DESC \
+ USB_DEV_QUAL_DESC_BYTES(CONF_USB_DFUD_BCDUSB, \
+ CONF_USB_DFUD_BDEVICECLASS, \
+ CONF_USB_DFUD_BDEVICESUBCLASS, \
+ CONF_USB_DFUD_BMAXPKSZ0, \
+ CONF_USB_DFUD_BNUMCONFIG)
+
+#define DFUD_CFG_DESC \
+ USB_CONFIG_DESC_BYTES(CONF_USB_DFUD_WTOTALLENGTH, \
+ CONF_USB_DFUD_BNUMINTERFACES, \
+ CONF_USB_DFUD_BCONFIGVAL, \
+ CONF_USB_DFUD_ICONFIG, \
+ CONF_USB_DFUD_BMATTRI, \
+ CONF_USB_DFUD_BMAXPOWER)
+
+#define DFUD_OTH_SPD_CFG_DESC \
+ USB_OTH_SPD_CFG_DESC_BYTES(CONF_USB_DFUD_WTOTALLENGTH, \
+ CONF_USB_DFUD_BNUMINTERFACES, \
+ CONF_USB_DFUD_BCONFIGVAL, \
+ CONF_USB_DFUD_ICONFIG, \
+ CONF_USB_DFUD_BMATTRI, \
+ CONF_USB_DFUD_BMAXPOWER)
+
+#define DFUD_IFACE_DESCES \
+ USB_IFACE_DESC_BYTES(CONF_USB_DFUD_BIFCNUM, \
+ CONF_USB_DFUD_BALTSET, \
+ CONF_USB_DFUD_BNUMEP, \
+ USB_DFU_CLASS, \
+ USB_DFU_SUBCLASS, \
+ USB_DFU_PROTOCOL_DFU, \
+ CONF_USB_DFUD_IINTERFACE), \
+ USB_DFU_FUNC_DESC_BYTES(USB_DFU_ATTRIBUTES_CAN_DOWNLOAD | USB_DFU_ATTRIBUTES_WILL_DETACH, \
+ 200, /* maximum time in milliseconds to detach (and reboot) */ \
+ 1024, /* maximum transfer size */ \
+ 0x0110 /*< DFU specification version 1.1 used */ )
+
+#define DFUD_STR_DESCES \
+ CONF_USB_DFUD_LANGID_DESC \
+ CONF_USB_DFUD_IMANUFACT_STR_DESC \
+ CONF_USB_DFUD_IPRODUCT_STR_DESC \
+ CONF_USB_DFUD_ISERIALNUM_STR_DESC \
+ CONF_USB_DFUD_ICONFIG_STR_DESC \
+ CONF_USB_DFUD_IINTERFACE_STR_DESC
+
+/** USB Device descriptors and configuration descriptors */
+#define DFUD_DESCES_LS_FS \
+ DFUD_DEV_DESC, DFUD_CFG_DESC, DFUD_IFACE_DESCES, DFUD_STR_DESCES
+
+#define DFUD_HS_DESCES_LS_FS \
+ DFUD_DEV_DESC, DFUD_DEV_QUAL_DESC, DFUD_CFG_DESC, DFUD_M_IFACE_DESCES, \
+ DFUD_IFACE_DESCES, DFUD_OTH_SPD_CFG_DESC, \
+ DFUD_IFACE_DESCES_HS, DFUD_STR_DESCES
+
+#define DFUD_HS_DESCES_HS \
+ DFUD_CFG_DESC, DFUD_IFACE_DESCES, DFUD_IFACE_DESCES_HS, DFUD_OTH_SPD_CFG_DESC, \
+ DFUD_IFACE_DESCES
+
+#endif /* USBDF_DFU_DESC_H_ */
diff --git a/usb/class/dfu/usb_protocol_dfu.h b/usb/class/dfu/usb_protocol_dfu.h
new file mode 100644
index 0000000..2e7323f
--- /dev/null
+++ b/usb/class/dfu/usb_protocol_dfu.h
@@ -0,0 +1,150 @@
+/**
+ * \file
+ *
+ * \brief USB Device Firmware Upgrade (DFU) protocol definitions
+ *
+ * Copyright (c) 2018 sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef _USB_PROTOCOL_DFU_H_
+#define _USB_PROTOCOL_DFU_H_
+
+#include "usb_includes.h"
+
+/*
+ * \ingroup usb_protocol_group
+ * \defgroup dfu_protocol_group Device Firmware Upgrade Definitions
+ * \implements USB Device Firmware Upgrade Specification, Revision 1.1
+ * @{
+ */
+
+/**
+ * \name USB DFU Subclass IDs
+ */
+//@{
+#define USB_DFU_CLASS 0xFE //!< Application Specific Class Code
+//@}
+
+//! \name USB DFU Subclass IDs
+//@{
+#define USB_DFU_SUBCLASS 0x01 //!< Device Firmware Upgrade Code
+//@}
+
+//! \name USB DFU Protocol IDs
+//@{
+#define USB_DFU_PROTOCOL_RUNTIME 0x01 //!< Runtime protocol
+#define USB_DFU_PROTOCOL_DFU 0x02 //!< DFU mode protocol
+//@}
+
+//! \name USB DFU Attributes bits mask
+//@{
+#define USB_DFU_ATTRIBUTES_CAN_DOWNLOAD 0x01
+#define USB_DFU_ATTRIBUTES_CAN_UPLOAD 0x02
+#define USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT 0x04
+#define USB_DFU_ATTRIBUTES_WILL_DETACH 0x08
+//@}
+
+//! \name USB DFU Request IDs
+//@{
+#define USB_REQ_DFU_DETACH 0x00
+#define USB_REQ_DFU_DNLOAD 0x01
+#define USB_REQ_DFU_UPLOAD 0x02
+#define USB_REQ_DFU_GETSTATUS 0x03
+#define USB_REQ_DFU_CLRSTATUS 0x04
+#define USB_REQ_DFU_GETSTATE 0x05
+#define USB_REQ_DFU_ABORT 0x06
+//@}
+
+/*
+ * Need to pack structures tightly, or the compiler might insert padding
+ * and violate the spec-mandated layout.
+ */
+COMPILER_PACK_SET(1)
+
+//! \name USB DFU Descriptors
+//@{
+
+//! DFU Functional Descriptor
+typedef struct usb_dfu_func_desc {
+ uint8_t bFunctionLength;
+ uint8_t bDescriptorType;
+ uint8_t bmAttributes;
+ le16_t wDetachTimeOut;
+ le16_t wTransferSize;
+ le16_t bcdDFUVersion;
+} usb_dfu_func_desc_t;
+
+#define USB_DFU_FUNC_DESC_LEN 0x09
+#define USB_DFU_FUNC_DESC_TYPE 0x21
+#define USB_DFU_FUNC_DESC_BYTES(bmAttributes, wDetachTimeOut, wTransferSize, bcdDFUVersion) \
+ USB_DFU_FUNC_DESC_LEN, /* bFunctionLength */ \
+ USB_DFU_FUNC_DESC_TYPE, /* bDescriptorType */ \
+ bmAttributes, \
+ LE_BYTE0(wDetachTimeOut), LE_BYTE1(wDetachTimeOut), \
+ LE_BYTE0(wTransferSize), LE_BYTE1(wTransferSize), \
+ LE_BYTE0(bcdDFUVersion), LE_BYTE1(bcdDFUVersion)
+
+COMPILER_PACK_RESET()
+
+//! @}
+
+//! USB DFU Request IDs
+enum usb_dfu_req {
+ USB_DFU_DETACH,
+ USB_DFU_DNLOAD,
+ USB_DFU_UPLOAD,
+ USB_DFU_GETSTATUS,
+ USB_DFU_CLRSTATUS,
+ USB_DFU_GETSTATE,
+ USB_DFU_ABORT,
+};
+
+//! USB DFU Device Status IDs
+enum usb_dfu_status {
+ USB_DFU_STATUS_OK,
+ USB_DFU_STATUS_ERR_TARGET,
+ USB_DFU_STATUS_ERR_FILE,
+ USB_DFU_STATUS_ERR_WRITE,
+ USB_DFU_STATUS_ERR_ERASE,
+ USB_DFU_STATUS_ERR_CHECK_ERASED,
+ USB_DFU_STATUS_ERR_PROG,
+ USB_DFU_STATUS_ERR_VERIFY,
+ USB_DFU_STATUS_ERR_ADDRESS,
+ USB_DFU_STATUS_ERR_NOTDONE,
+ USB_DFU_STATUS_ERR_FIRMWARE,
+ USB_DFU_STATUS_ERR_VENDOR,
+ USB_DFU_STATUS_ERR_USBR,
+ USB_DFU_STATUS_ERR_POR,
+ USB_DFU_STATUS_ERR_UNKNOWN,
+ USB_DFU_STATUS_ERR_STALLEDPKT,
+};
+
+//! USB DFU Device State IDs
+enum usb_dfu_state {
+ USB_DFU_STATE_APP_IDLE,
+ USB_DFU_STATE_APP_DETACH,
+ USB_DFU_STATE_DFU_IDLE,
+ USB_DFU_STATE_DFU_DNLOAD_SYNC,
+ USB_DFU_STATE_DFU_DNBUSY,
+ USB_DFU_STATE_DFU_DNLOAD_IDLE,
+ USB_DFU_STATE_DFU_MANIFEST_SYNC,
+ USB_DFU_STATE_DFU_MANIFEST,
+ USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET,
+ USB_DFU_STATE_DFU_UPLOAD_IDLE,
+ USB_DFU_STATE_DFU_ERROR,
+};
+
+#endif // _USB_PROTOCOL_DFU_H_
diff --git a/usb_cdc_echo_main.c b/usb_dfu_main.c
index fe02810..2535475 100644
--- a/usb_cdc_echo_main.c
+++ b/usb_dfu_main.c
@@ -4,6 +4,7 @@
* \brief Application implement
*
* Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ * Copyright (c) 2018 sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
*
* \asf_license_start
*
@@ -40,5 +41,5 @@
int main(void)
{
atmel_start_init();
- cdcd_acm_example();
+ usb_dfu();
}
diff --git a/usb_start.c b/usb_start.c
index de86172..4f9f875 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -1,9 +1,19 @@
/*
- * Code generated from Atmel Start.
+ * (C) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
*
- * This file will be overwritten when reconfiguring your Atmel Start project.
- * Please copy examples or other code you want to keep to a separate file or main.c
- * to avoid loosing it when reconfiguring.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "atmel_start.h"
#include "usb_start.h"
@@ -11,16 +21,14 @@
#if CONF_USBD_HS_SP
static uint8_t single_desc_bytes[] = {
/* Device descriptors and Configuration descriptors list. */
- CDCD_ACM_HS_DESCES_LS_FS};
+ DFUD_HS_DESCES_LS_FS};
static uint8_t single_desc_bytes_hs[] = {
/* Device descriptors and Configuration descriptors list. */
- CDCD_ACM_HS_DESCES_HS};
-#define CDCD_ECHO_BUF_SIZ CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ_HS
+ DFUD_HS_DESCES_HS};
#else
static uint8_t single_desc_bytes[] = {
/* Device descriptors and Configuration descriptors list. */
- CDCD_ACM_DESCES_LS_FS};
-#define CDCD_ECHO_BUF_SIZ CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ
+ DFUD_DESCES_LS_FS};
#endif
static struct usbd_descriptors single_desc[]
@@ -31,62 +39,19 @@ static struct usbd_descriptors single_desc[]
#endif
};
-/** Buffers to receive and echo the communication bytes. */
-static uint32_t usbd_cdc_buffer[CDCD_ECHO_BUF_SIZ / 4];
-
/** Ctrl endpoint buffer */
static uint8_t ctrl_buffer[64];
/**
- * \brief Callback invoked when bulk OUT data received
- */
-static bool usb_device_cb_bulk_out(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count)
-{
- cdcdf_acm_write((uint8_t *)usbd_cdc_buffer, count);
-
- /* No error. */
- return false;
-}
-
-/**
- * \brief Callback invoked when bulk IN data received
+ * \brief USB DFU Init
*/
-static bool usb_device_cb_bulk_in(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count)
-{
- /* Echo data. */
- cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer));
-
- /* No error. */
- return false;
-}
-
-/**
- * \brief Callback invoked when Line State Change
- */
-static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
-{
- if (state.rs232.DTR) {
- /* Callbacks must be registered after endpoint allocation */
- cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)usb_device_cb_bulk_out);
- cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)usb_device_cb_bulk_in);
- /* Start Rx */
- cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer));
- }
-
- /* No error. */
- return false;
-}
-
-/**
- * \brief CDC ACM Init
- */
-void cdc_device_acm_init(void)
+void usb_dfu_init(void)
{
/* usb stack init */
usbdc_init(ctrl_buffer);
/* usbdc_register_funcion inside */
- cdcdf_acm_init();
+ dfudf_init();
usbdc_start(single_desc);
usbdc_attach();
@@ -102,14 +67,12 @@ void cdc_device_acm_init(void)
* - Open a HyperTerminal or other COM tools in PC side.
* - Send out a character or string and it will echo the content received.
*/
-void cdcd_acm_example(void)
+void usb_dfu(void)
{
- while (!cdcdf_acm_is_enabled()) {
- // wait cdc acm to be installed
+ while (!dfudf_is_enabled()) {
+ // wait DFU to be installed
};
- cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c);
-
while (1) {
}
}
@@ -117,5 +80,5 @@ void cdcd_acm_example(void)
void usb_init(void)
{
- cdc_device_acm_init();
+ usb_dfu_init();
}
diff --git a/usb_start.h b/usb_start.h
index 48b2735..37502b4 100644
--- a/usb_start.h
+++ b/usb_start.h
@@ -1,9 +1,19 @@
/*
- * Code generated from Atmel Start.
+ * (C) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
*
- * This file will be overwritten when reconfiguring your Atmel Start project.
- * Please copy examples or other code you want to keep to a separate file or main.c
- * to avoid loosing it when reconfiguring.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef USB_DEVICE_MAIN_H
#define USB_DEVICE_MAIN_H
@@ -12,11 +22,11 @@
extern "C" {
#endif // __cplusplus
-#include "cdcdf_acm.h"
-#include "cdcdf_acm_desc.h"
+#include "dfudf.h"
+#include "dfudf_desc.h"
-void cdcd_acm_example(void);
-void cdc_device_acm_init(void);
+void usb_dfu(void);
+void usb_dfu_init(void);
/**
* \berif Initialize USB