From 32f920e372b6d6c924f48512a714a9628ef5fea3 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Thu, 22 Aug 2019 19:52:21 +0800 Subject: [PATCH] compile/crash fixes --- targets/stm32l432/lib/usbd/usbd_ccid.c | 68 ++++---- targets/stm32l432/lib/usbd/usbd_composite.c | 166 ++++++++++---------- targets/stm32l432/src/init.c | 9 +- 3 files changed, 128 insertions(+), 115 deletions(-) diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.c b/targets/stm32l432/lib/usbd/usbd_ccid.c index c452aa3..2a81ef7 100644 --- a/targets/stm32l432/lib/usbd/usbd_ccid.c +++ b/targets/stm32l432/lib/usbd/usbd_ccid.c @@ -32,7 +32,7 @@ USBD_ClassTypeDef USBD_CCID = NULL, /* EP0_TxSent, */ USBD_CCID_EP0_RxReady, USBD_CCID_DataIn, - usb_ccid_recieve_callback, + USBD_CCID_DataOut, NULL, NULL, NULL, @@ -54,11 +54,10 @@ static uint8_t USBD_CCID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) USBD_LL_OpenEP(pdev, CCID_IN_EP, USBD_EP_TYPE_BULK, CCID_DATA_PACKET_SIZE); - pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 1U; - USBD_LL_OpenEP(pdev, CCID_OUT_EP, USBD_EP_TYPE_BULK, CCID_DATA_PACKET_SIZE); + pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 1U; pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 1U; @@ -202,32 +201,38 @@ static uint8_t USBD_CCID_Setup (USBD_HandleTypeDef *pdev, * @param epnum: endpoint number * @retval status */ +static uint8_t USBD_CCID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) +{ + return USBD_OK; +} static uint8_t USBD_CCID_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) { //N USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*)pdev->pClassData; PCD_HandleTypeDef *hpcd = pdev->pData; - if(pdev->pClassData != NULL) - { - if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) - { - /* Update the packet total length */ - pdev->ep_in[epnum].total_length = 0U; + // if(pdev->pClassData != NULL) + // { + // if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) + // { + // /* Update the packet total length */ + // pdev->ep_in[epnum].total_length = 0U; - /* Send ZLP */ - USBD_LL_Transmit (pdev, epnum, NULL, 0U); - } - else - { - hcdc->TxState = 0U; - } - return USBD_OK; - } - else - { - return USBD_FAIL; - } + // /* Send ZLP */ + // USBD_LL_Transmit (pdev, epnum, NULL, 0U); + // } + // else + // { + // hcdc->TxState = 0U; + // } + // return USBD_OK; + // } + // else + // { + // return USBD_FAIL; + // } + hcdc->TxState = 0U; + return USBD_OK; } uint8_t USBD_CCID_TransmitPacket(uint8_t * msg, int len) @@ -235,10 +240,21 @@ uint8_t USBD_CCID_TransmitPacket(uint8_t * msg, int len) /* Update the packet total length */ Solo_USBD_Device.ep_in[CCID_IN_EP & 0xFU].total_length = len; + while (PCD_GET_EP_TX_STATUS(USB, CCID_IN_EP & 0x0f) == USB_EP_TX_VALID) + ; /* Transmit next packet */ USBD_LL_Transmit(&Solo_USBD_Device, CCID_IN_EP, msg, len); + + // /* Update the packet total length */ + // Solo_USBD_Device.ep_in[CCID_CMD_EP & 0xFU].total_length = len; + + // /* Transmit next packet */ + // USBD_LL_Transmit(&Solo_USBD_Device, CCID_CMD_EP, msg, + // len); + + return USBD_OK; } @@ -266,8 +282,6 @@ void ccid_send_status(CCID_HEADER * c) } - - void handle_ccid(uint8_t * msg, int len) { CCID_HEADER * h = (CCID_HEADER *) msg; @@ -316,11 +330,7 @@ uint8_t usb_ccid_recieve_callback(USBD_HandleTypeDef *pdev, uint8_t epnum) else { - - while(1) - { - led_rgb(0xff3520); - } + while(1){ led_rgb(0xff3520); } return USBD_FAIL; } diff --git a/targets/stm32l432/lib/usbd/usbd_composite.c b/targets/stm32l432/lib/usbd/usbd_composite.c index 1aa641d..7d5fdb4 100644 --- a/targets/stm32l432/lib/usbd/usbd_composite.c +++ b/targets/stm32l432/lib/usbd/usbd_composite.c @@ -34,17 +34,17 @@ static uint8_t *USBD_Composite_GetDeviceQualifierDescriptor (uint16_t *length); #define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 8+9 + 4 + 84) #define NUM_INTERFACES 4 #elif NUM_CLASSES>1 -#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 84) -#define NUM_INTERFACES 2 +#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 8+9 + 4) +#define NUM_INTERFACES 3 #else #define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (41) #define NUM_INTERFACES 1 #endif #define HID_INTF_NUM 0 -#define CCID_INTF_NUM 1 -#define CDC_MASTER_INTF_NUM 2 -#define CDC_SLAVE_INTF_NUM 3 +#define CDC_MASTER_INTF_NUM 1 +#define CDC_SLAVE_INTF_NUM 2 +#define CCID_INTF_NUM 3 __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_SIZE] __ALIGN_END = { /*Configuration Descriptor*/ @@ -101,81 +101,6 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_ 0x00, HID_BINTERVAL, /*bInterval: Polling Interval */ -#if NUM_INTERFACES>1 - - /* CCID Interface Descriptor */ - 9, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - CCID_INTF_NUM, /* bInterfaceNumber: CCID Interface */ - 0, /* Alternate setting for this interface */ - 3, /* bNumEndpoints: Bulk-IN, Bulk-OUT, Intr-IN */ - 0x0B, /* CCID class */ - 0x00, /* CCID subclass */ - 0x00, /* CCID protocol */ - 0, /* string index for interface */ - - /* ICC Descriptor */ - 54, /* bLength: */ - 0x21, /* bDescriptorType: USBDESCR_ICC */ - 0x10, 0x01, /* bcdCCID: revision 1.1 (of CCID) */ - 0, /* bMaxSlotIndex: */ - 1, /* bVoltageSupport: 5V-only */ - 0x02, 0, 0, 0, /* dwProtocols: T=1 */ - 0xa0, 0x0f, 0, 0, /* dwDefaultClock: 4000 */ - 0xa0, 0x0f, 0, 0, /* dwMaximumClock: 4000 */ - 0, /* bNumClockSupported: 0x00 */ - 0x80, 0x25, 0, 0, /* dwDataRate: 9600 */ - 0x80, 0x25, 0, 0, /* dwMaxDataRate: 9600 */ - 0, /* bNumDataRateSupported: 0x00 */ - 0xfe, 0, 0, 0, /* dwMaxIFSD: 254 */ - 0, 0, 0, 0, /* dwSynchProtocols: 0 */ - 0, 0, 0, 0, /* dwMechanical: 0 */ - 0x7a, 0x04, 0x02, 0x00, /* dwFeatures: - * Short and extended APDU level: 0x40000 ---- - * Short APDU level : 0x20000 * - * (ICCD?) : 0x00800 ---- - * Automatic IFSD : 0x00400 * - * NAD value other than 0x00 : 0x00200 - * Can set ICC in clock stop : 0x00100 - * Automatic PPS CUR : 0x00080 - * Automatic PPS PROP : 0x00040 * - * Auto baud rate change : 0x00020 * - * Auto clock change : 0x00010 * - * Auto voltage selection : 0x00008 * - * Auto activaction of ICC : 0x00004 - * Automatic conf. based on ATR : 0x00002 * - */ - 0x0f, 0x01, 0, 0, /* dwMaxCCIDMessageLength: 271 */ - 0xff, /* bClassGetResponse: 0xff */ - 0x00, /* bClassEnvelope: 0 */ - 0, 0, /* wLCDLayout: 0 */ - 0, /* bPinSupport: No PIN pad */ - - 1, /* bMaxCCIDBusySlots: 1 */ - /*Endpoint IN1 Descriptor*/ - 7, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CCID_IN_EP, /* bEndpointAddress: (IN1) */ - 0x02, /* bmAttributes: Bulk */ - HID_FIDO_REPORT_DESC_SIZE, 0x00, /* wMaxPacketSize: */ - 0x00, /* bInterval */ - /*Endpoint OUT1 Descriptor*/ - 7, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CCID_OUT_EP, /* bEndpointAddress: (OUT1) */ - 0x02, /* bmAttributes: Bulk */ - HID_FIDO_REPORT_DESC_SIZE, 0x00, /* wMaxPacketSize: */ - 0x00, /* bInterval */ - /*Endpoint IN2 Descriptor*/ - 7, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CCID_CMD_EP, /* bEndpointAddress: (IN2) */ - 0x03, /* bmAttributes: Interrupt */ - 0x04, 0x00, /* wMaxPacketSize: 4 */ - 0xFF, /* bInterval (255ms) */ - -#endif - #if NUM_INTERFACES > 2 /* */ @@ -274,6 +199,81 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_ 0x04, #endif +#if NUM_INTERFACES>3 + + /* CCID Interface Descriptor */ + 9, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + CCID_INTF_NUM, /* bInterfaceNumber: CCID Interface */ + 0, /* Alternate setting for this interface */ + 3, /* bNumEndpoints: Bulk-IN, Bulk-OUT, Intr-IN */ + 0x0B, /* CCID class */ + 0x00, /* CCID subclass */ + 0x00, /* CCID protocol */ + 0, /* string index for interface */ + + /* ICC Descriptor */ + 54, /* bLength: */ + 0x21, /* bDescriptorType: USBDESCR_ICC */ + 0x10, 0x01, /* bcdCCID: revision 1.1 (of CCID) */ + 0, /* bMaxSlotIndex: */ + 1, /* bVoltageSupport: 5V-only */ + 0x02, 0, 0, 0, /* dwProtocols: T=1 */ + 0xa0, 0x0f, 0, 0, /* dwDefaultClock: 4000 */ + 0xa0, 0x0f, 0, 0, /* dwMaximumClock: 4000 */ + 0, /* bNumClockSupported: 0x00 */ + 0x80, 0x25, 0, 0, /* dwDataRate: 9600 */ + 0x80, 0x25, 0, 0, /* dwMaxDataRate: 9600 */ + 0, /* bNumDataRateSupported: 0x00 */ + 0xfe, 0, 0, 0, /* dwMaxIFSD: 254 */ + 0, 0, 0, 0, /* dwSynchProtocols: 0 */ + 0, 0, 0, 0, /* dwMechanical: 0 */ + 0x7a, 0x04, 0x02, 0x00, /* dwFeatures: + * Short and extended APDU level: 0x40000 ---- + * Short APDU level : 0x20000 * + * (ICCD?) : 0x00800 ---- + * Automatic IFSD : 0x00400 * + * NAD value other than 0x00 : 0x00200 + * Can set ICC in clock stop : 0x00100 + * Automatic PPS CUR : 0x00080 + * Automatic PPS PROP : 0x00040 * + * Auto baud rate change : 0x00020 * + * Auto clock change : 0x00010 * + * Auto voltage selection : 0x00008 * + * Auto activaction of ICC : 0x00004 + * Automatic conf. based on ATR : 0x00002 * + */ + 0x0f, 0x01, 0, 0, /* dwMaxCCIDMessageLength: 271 */ + 0xff, /* bClassGetResponse: 0xff */ + 0x00, /* bClassEnvelope: 0 */ + 0, 0, /* wLCDLayout: 0 */ + 0, /* bPinSupport: No PIN pad */ + + 1, /* bMaxCCIDBusySlots: 1 */ + /*Endpoint IN1 Descriptor*/ + 7, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + CCID_IN_EP, /* bEndpointAddress: (IN1) */ + 0x02, /* bmAttributes: Bulk */ + CCID_DATA_PACKET_SIZE, 0x00, /* wMaxPacketSize: */ + 0x00, /* bInterval */ + /*Endpoint OUT1 Descriptor*/ + 7, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + CCID_OUT_EP, /* bEndpointAddress: (OUT1) */ + 0x02, /* bmAttributes: Bulk */ + CCID_DATA_PACKET_SIZE, 0x00, /* wMaxPacketSize: */ + 0x00, /* bInterval */ + /*Endpoint IN2 Descriptor*/ + 7, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + CCID_CMD_EP, /* bEndpointAddress: (IN2) */ + 0x03, /* bmAttributes: Interrupt */ + CCID_DATA_PACKET_SIZE, 0x00, /* wMaxPacketSize: 4 */ + 0xFF, /* bInterval (255ms) */ + +#endif + }; @@ -301,7 +301,7 @@ int in_endpoint_to_class[MAX_ENDPOINTS]; int out_endpoint_to_class[MAX_ENDPOINTS]; -void USBD_Composite_Set_Classes(USBD_ClassTypeDef *hid_class, USBD_ClassTypeDef *ccid_class, USBD_ClassTypeDef *cdc_class)) { +void USBD_Composite_Set_Classes(USBD_ClassTypeDef *hid_class, USBD_ClassTypeDef *ccid_class, USBD_ClassTypeDef *cdc_class) { USBD_Classes[0] = hid_class; USBD_Classes[1] = ccid_class; USBD_Classes[2] = cdc_class; @@ -314,10 +314,10 @@ static USBD_ClassTypeDef * getClass(uint8_t index) case HID_INTF_NUM: return USBD_Classes[0]; case CCID_INTF_NUM: - return USBD_Classes[2]; + return USBD_Classes[1]; case CDC_MASTER_INTF_NUM: case CDC_SLAVE_INTF_NUM: - return USBD_Classes[3]; + return USBD_Classes[2]; } return NULL; diff --git a/targets/stm32l432/src/init.c b/targets/stm32l432/src/init.c index 2475bdf..c57392c 100644 --- a/targets/stm32l432/src/init.c +++ b/targets/stm32l432/src/init.c @@ -708,12 +708,15 @@ void init_usb() SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN); #if DEBUG_LEVEL > 0 - USBD_Composite_Set_Classes(&USBD_HID, &USBD_CDC, &USBD_CCID); + USBD_Composite_Set_Classes(&USBD_HID, &USBD_CCID, &USBD_CDC); in_endpoint_to_class[HID_EPIN_ADDR & 0x7F] = 0; out_endpoint_to_class[HID_EPOUT_ADDR & 0x7F] = 0; - in_endpoint_to_class[CDC_IN_EP & 0x7F] = 1; - out_endpoint_to_class[CDC_OUT_EP & 0x7F] = 1; + in_endpoint_to_class[CCID_IN_EP & 0x7F] = 1; + out_endpoint_to_class[CCID_OUT_EP & 0x7F] = 1; + + in_endpoint_to_class[CDC_IN_EP & 0x7F] = 2; + out_endpoint_to_class[CDC_OUT_EP & 0x7F] = 2; USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0); USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite);