diff --git a/docs/hic/sam3u2c.md b/docs/hic/sam3u2c.md index 3ae591ca4..ad98a8afe 100644 --- a/docs/hic/sam3u2c.md +++ b/docs/hic/sam3u2c.md @@ -4,7 +4,7 @@ Based on ATSAM3U2C chip ([Datasheet](https://ww1.microchip.com/downloads/en/Devi - Cortex-M3 96 Mhz - 128 KB Flash - 36 KB RAM -- High-speed USB 2.0 device controller: up to 7 bi-directional endpoints including EP0 (*) +- High-speed USB 2.0 device controller: up to 7 endpoints including EP0 (*) - LQFP100 packaging (*) "up to 7 bidirectional Endpoints" (source: Datasheet](https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-6430-32-bit-Cortex-M3-Microcontroller-SAM3U4-SAM3U2-SAM3U1_Datasheet.pdf)) diff --git a/projects.yaml b/projects.yaml index 710aa6ff4..67cc34252 100644 --- a/projects.yaml +++ b/projects.yaml @@ -215,6 +215,8 @@ projects: sam3u2c_if: - *module_if - *module_hic_sam3u2c + - records/usb/usb-bulk.yaml + - records/board/sam3u2c_if.yaml - records/family/all_family.yaml stm32f072x8_if: - *module_if diff --git a/records/board/sam3u2c_if.yaml b/records/board/sam3u2c_if.yaml new file mode 100644 index 000000000..5d3201adb --- /dev/null +++ b/records/board/sam3u2c_if.yaml @@ -0,0 +1,5 @@ +common: + macros: + - HID_ENDPOINT_DISABLE + - MSC_ENDPOINT_DISABLE + - DRAG_N_DROP_DISABLE diff --git a/source/hic_hal/atmel/sam3u2c/DAP_config.h b/source/hic_hal/atmel/sam3u2c/DAP_config.h index 22b5c0478..4cf8fc1a5 100644 --- a/source/hic_hal/atmel/sam3u2c/DAP_config.h +++ b/source/hic_hal/atmel/sam3u2c/DAP_config.h @@ -83,10 +83,10 @@ This information includes: /// This configuration settings is used to optimize the communication performance with the /// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB, /// 1024 for High-speed USB HID and 512 for High-speed USB WinUSB. -#ifndef HID_ENDPOINT //HID end points currently set limits to 64 -#define DAP_PACKET_SIZE 512 ///< Specifies Packet Size in bytes. -#else +#if defined(HID_ENDPOINT) && !defined(HID_ENDPOINT_DISABLE) // HID end points currently set limits to 64 #define DAP_PACKET_SIZE 64 ///< Specifies Packet Size in bytes. +#else +#define DAP_PACKET_SIZE 512 ///< Specifies Packet Size in bytes. #endif /// Maximum Package Buffers for Command and Response data. diff --git a/source/hic_hal/atmel/sam3u2c/usb_config.c b/source/hic_hal/atmel/sam3u2c/usb_config.c index 2dc7e1d36..5e6b3e19f 100644 --- a/source/hic_hal/atmel/sam3u2c/usb_config.c +++ b/source/hic_hal/atmel/sam3u2c/usb_config.c @@ -87,6 +87,46 @@ #endif #endif +#if (BULK_ENDPOINT) +/* SAM3UC only has 7 endpoints, and as a consequence BULK_ENDPOINT cannot + * be enabled at the same time as CDC_ENDPOINT and MSC_ENDPOINT. + */ +#if (CDC_ENDPOINT && MSC_ENDPOINT) +#error "SAM3U2C does not have enough endpoints to support this configuration" +#endif +#if (CDC_ENDPOINT) +#define USBD_HID_EP_INTOUT 0 +#define USBD_BULK_EP_BULKIN 1 +#define USBD_BULK_EP_BULKOUT 2 +#define USBD_HID_EP_INTIN 3 +#define USBD_CDC_ACM_EP_INTIN 4 +#define USBD_CDC_ACM_EP_BULKOUT 5 +#define USBD_CDC_ACM_EP_BULKIN 6 +#define USBD_MSC_EP_BULKIN 7 /* Unused */ +#define USBD_MSC_EP_BULKOUT 7 /* Unused */ +#else // !(CDC_ENDPOINT) +#define USBD_MSC_EP_BULKIN 1 +#define USBD_MSC_EP_BULKOUT 2 +#define USBD_HID_EP_INTIN 3 +#define USBD_HID_EP_INTOUT 4 +#define USBD_BULK_EP_BULKOUT 5 +#define USBD_BULK_EP_BULKIN 6 +#define USBD_CDC_ACM_EP_INTIN 7 /* Unused */ +#define USBD_CDC_ACM_EP_BULKIN 7 /* Unused */ +#define USBD_CDC_ACM_EP_BULKOUT 7 /* Unused */ +#endif +#else // !(BULK_ENDPOINT) +#define USBD_HID_EP_INTOUT 0 +#define USBD_MSC_EP_BULKIN 1 +#define USBD_MSC_EP_BULKOUT 2 +#define USBD_HID_EP_INTIN 3 +#define USBD_CDC_ACM_EP_INTIN 4 +#define USBD_CDC_ACM_EP_BULKOUT 5 +#define USBD_CDC_ACM_EP_BULKIN 6 +#define USBD_BULK_EP_BULKIN 7 /* Unused */ +#define USBD_BULK_EP_BULKOUT 7 /* Unused */ +#endif + // USB Device // Enable the USB Device functionality #define USBD_ENABLE 1 @@ -209,9 +249,7 @@ // #define USBD_HID_ENABLE HID_ENDPOINT -#define USBD_HID_EP_INTIN 3 #define USBD_HID_EP_INTIN_STACK 0 -#define USBD_HID_EP_INTOUT 0 #define USBD_HID_EP_INTOUT_STACK 0 #define USBD_HID_WMAXPACKETSIZE 64 #define USBD_HID_BINTERVAL 1 @@ -258,9 +296,7 @@ // #define USBD_MSC_ENABLE MSC_ENDPOINT -#define USBD_MSC_EP_BULKIN 1 #define USBD_MSC_EP_BULKIN_STACK 0 -#define USBD_MSC_EP_BULKOUT 2 #define USBD_MSC_EP_BULKOUT_STACK 0 #define USBD_MSC_WMAXPACKETSIZE 64 #define USBD_MSC_HS_ENABLE 1 @@ -374,16 +410,13 @@ // #define USBD_CDC_ACM_ENABLE CDC_ENDPOINT -#define USBD_CDC_ACM_EP_INTIN 4 #define USBD_CDC_ACM_EP_INTIN_STACK 0 #define USBD_CDC_ACM_WMAXPACKETSIZE 16 #define USBD_CDC_ACM_BINTERVAL 32 #define USBD_CDC_ACM_HS_ENABLE 1 #define USBD_CDC_ACM_HS_WMAXPACKETSIZE 64 #define USBD_CDC_ACM_HS_BINTERVAL 2 -#define USBD_CDC_ACM_EP_BULKIN 6 #define USBD_CDC_ACM_EP_BULKIN_STACK 0 -#define USBD_CDC_ACM_EP_BULKOUT 5 #define USBD_CDC_ACM_EP_BULKOUT_STACK 0 #define USBD_CDC_ACM_WMAXPACKETSIZE1 64 #define USBD_CDC_ACM_HS_ENABLE1 1 @@ -431,20 +464,6 @@ // #define USBD_BULK_ENABLE BULK_ENDPOINT -// We don't have enough endpoints for BULK unless MSC or CDC are disabled. -// MSC is the best choice, since this is only useful in the fixed target IF config and we can still upload firmware via DAP. -// We'll still want MSC for the BL though, but in that case BULK isn't useful anyway. -#if USBD_MSC_ENABLE == 0 -#define USBD_BULK_EP_BULKIN 1 // Use the MSC endpoints for BULK -#define USBD_BULK_EP_BULKOUT 2 -#elif USBD_CDC_ACM_ENABLE == 0 -#define USBD_BULK_EP_BULKIN 5 // Use the CDC endpoints for BULK -#define USBD_BULK_EP_BULKOUT 6 -#else -#define USBD_BULK_EP_BULKIN 7 // Use non-existent endpoints to force an error -#define USBD_BULK_EP_BULKOUT 8 // if BULK is enabled but MSC + CDC are still enabled -#endif - #define USBD_BULK_WMAXPACKETSIZE 64 #define USBD_BULK_HS_ENABLE 1 #define USBD_BULK_HS_WMAXPACKETSIZE 512