From 0ff987061297d497de156680502bf3b91f17ca2e Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Sat, 18 May 2019 21:26:18 -0400 Subject: [PATCH 01/11] add interface descriptor --- targets/stm32l432/lib/usbd/usbd_composite.c | 79 ++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/targets/stm32l432/lib/usbd/usbd_composite.c b/targets/stm32l432/lib/usbd/usbd_composite.c index a1a868c..ed41812 100644 --- a/targets/stm32l432/lib/usbd/usbd_composite.c +++ b/targets/stm32l432/lib/usbd/usbd_composite.c @@ -26,8 +26,10 @@ static uint8_t *USBD_Composite_GetOtherSpeedCfgDesc (uint16_t *length); static uint8_t *USBD_Composite_GetDeviceQualifierDescriptor (uint16_t *length); -#define NUM_INTERFACES 2 +#define NUM_INTERFACES 3 +#if NUM_INTERFACES>2 +#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90) #if NUM_INTERFACES>1 #define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90) #else @@ -168,6 +170,81 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_ 0x00, /* bInterval: ignore for Bulk transfer */ #endif +#if NUM_INTERFACES>2 + +/* CCID Interface Descriptor */ +9, /* bLength: Interface Descriptor size */ +USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ +0, /* 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 */ +0x81, /* 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 */ +0x01, /* 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 */ +0x82, /* bEndpointAddress: (IN2) */ +0x03, /* bmAttributes: Interrupt */ +0x04, 0x00, /* wMaxPacketSize: 4 */ +0xFF, /* bInterval (255ms) */ + +#endif + }; From 4fad28ea470aff8656a5665c41138e67890e7a26 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Sat, 18 May 2019 21:47:51 -0400 Subject: [PATCH 02/11] compile new class --- targets/stm32l432/lib/usbd/usbd_ccid.h | 8 ++++++++ targets/stm32l432/lib/usbd/usbd_composite.c | 11 ++++++----- targets/stm32l432/lib/usbd/usbd_conf.c | 16 +++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 targets/stm32l432/lib/usbd/usbd_ccid.h diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.h b/targets/stm32l432/lib/usbd/usbd_ccid.h new file mode 100644 index 0000000..ce38be1 --- /dev/null +++ b/targets/stm32l432/lib/usbd/usbd_ccid.h @@ -0,0 +1,8 @@ +#ifndef _USBD_H_ +#define _USBD_H_ + +#define CCID_IN_EP 0x84U /* EP1 for data IN */ +#define CCID_OUT_EP 0x04U /* EP1 for data OUT */ +#define CCID_CMD_EP 0x85U /* EP2 for CDC commands */ + +#endif diff --git a/targets/stm32l432/lib/usbd/usbd_composite.c b/targets/stm32l432/lib/usbd/usbd_composite.c index ed41812..cf820d2 100644 --- a/targets/stm32l432/lib/usbd/usbd_composite.c +++ b/targets/stm32l432/lib/usbd/usbd_composite.c @@ -2,6 +2,7 @@ #include "usbd_desc.h" #include "usbd_hid.h" #include "usbd_cdc.h" +#include "usbd_ccid.h" #include "usbd_ctlreq.h" static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx); @@ -29,8 +30,8 @@ static uint8_t *USBD_Composite_GetDeviceQualifierDescriptor (uint16_t *length); #define NUM_INTERFACES 3 #if NUM_INTERFACES>2 -#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90) -#if NUM_INTERFACES>1 +#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 84) +#elif NUM_INTERFACES>1 #define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90) #else #define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (41) @@ -224,21 +225,21 @@ USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ /*Endpoint IN1 Descriptor*/ 7, /* bLength: Endpoint Descriptor size */ USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ -0x81, /* bEndpointAddress: (IN1) */ +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 */ -0x01, /* bEndpointAddress: (OUT1) */ +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 */ -0x82, /* bEndpointAddress: (IN2) */ +CCID_CMD_EP, /* bEndpointAddress: (IN2) */ 0x03, /* bmAttributes: Interrupt */ 0x04, 0x00, /* wMaxPacketSize: 4 */ 0xFF, /* bInterval (255ms) */ diff --git a/targets/stm32l432/lib/usbd/usbd_conf.c b/targets/stm32l432/lib/usbd/usbd_conf.c index 1d46743..793a0a2 100644 --- a/targets/stm32l432/lib/usbd/usbd_conf.c +++ b/targets/stm32l432/lib/usbd/usbd_conf.c @@ -50,6 +50,8 @@ #include "stm32l4xx_hal.h" #include "usbd_core.h" #include "usbd_hid.h" +#include "usbd_cdc.h" +#include "usbd_ccid.h" void SystemClock_Config(void); @@ -252,14 +254,18 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); // HID - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x98); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xd8); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , HID_EPOUT_ADDR , PCD_SNG_BUF, 0x98); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , HID_EPIN_ADDR , PCD_SNG_BUF, 0xd8); // CDC / uart - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x02 , PCD_SNG_BUF, 0xd8 + 64); // data OUT - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0xd8 + 64*2); // data IN - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x83 , PCD_SNG_BUF, 0xd8 + 64*3); // commands + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_OUT_EP , PCD_SNG_BUF, 0xd8 + 64); // data OUT + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_IN_EP , PCD_SNG_BUF, 0xd8 + 64*2); // data IN + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_CMD_EP , PCD_SNG_BUF, 0xd8 + 64*3); // commands + // CCID + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_OUT_EP , PCD_SNG_BUF, 0xd8 + 64*4); // data OUT + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_IN_EP , PCD_SNG_BUF, 0xd8 + 64*5); // data IN + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_CMD_EP , PCD_SNG_BUF, 0xd8 + 64*6); // commands return USBD_OK; } From 3a5cd786dc0b4dbb8505e2cbc0e81863014af51e Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Tue, 21 May 2019 20:17:37 -0400 Subject: [PATCH 03/11] enumerates correctly --- targets/stm32l432/build/common.mk | 3 +- targets/stm32l432/lib/usbd/usbd_ccid.c | 334 ++++++++++++++++++++ targets/stm32l432/lib/usbd/usbd_ccid.h | 33 ++ targets/stm32l432/lib/usbd/usbd_composite.c | 23 +- targets/stm32l432/lib/usbd/usbd_composite.h | 2 +- targets/stm32l432/src/init.c | 6 +- 6 files changed, 392 insertions(+), 9 deletions(-) create mode 100644 targets/stm32l432/lib/usbd/usbd_ccid.c diff --git a/targets/stm32l432/build/common.mk b/targets/stm32l432/build/common.mk index 7c0ae32..f018bce 100644 --- a/targets/stm32l432/build/common.mk +++ b/targets/stm32l432/build/common.mk @@ -10,7 +10,8 @@ DRIVER_LIBS := lib/stm32l4xx_hal_pcd.c lib/stm32l4xx_hal_pcd_ex.c lib/stm32l4xx_ USB_LIB := lib/usbd/usbd_cdc.c lib/usbd/usbd_cdc_if.c lib/usbd/usbd_composite.c \ lib/usbd/usbd_conf.c lib/usbd/usbd_core.c lib/usbd/usbd_ioreq.c \ - lib/usbd/usbd_ctlreq.c lib/usbd/usbd_desc.c lib/usbd/usbd_hid.c + lib/usbd/usbd_ctlreq.c lib/usbd/usbd_desc.c lib/usbd/usbd_hid.c \ + lib/usbd/usbd_ccid.c VERSION:=$(shell git describe --abbrev=0 ) VERSION_FULL:=$(shell git describe) diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.c b/targets/stm32l432/lib/usbd/usbd_ccid.c new file mode 100644 index 0000000..e202ffe --- /dev/null +++ b/targets/stm32l432/lib/usbd/usbd_ccid.c @@ -0,0 +1,334 @@ +#include +#include "usbd_ccid.h" +#include "usbd_ctlreq.h" +#include "usbd_conf.h" +#include "usbd_core.h" + +#include "log.h" + +static uint8_t USBD_CCID_Init (USBD_HandleTypeDef *pdev, + uint8_t cfgidx); + +static uint8_t USBD_CCID_DeInit (USBD_HandleTypeDef *pdev, + uint8_t cfgidx); + +static uint8_t USBD_CCID_Setup (USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req); + +static uint8_t USBD_CCID_DataIn (USBD_HandleTypeDef *pdev, + uint8_t epnum); + +static uint8_t USBD_CCID_DataOut (USBD_HandleTypeDef *pdev, + uint8_t epnum); + +static uint8_t USBD_CCID_EP0_RxReady (USBD_HandleTypeDef *pdev); + + +USBD_ClassTypeDef USBD_CCID = +{ + USBD_CCID_Init, + USBD_CCID_DeInit, + USBD_CCID_Setup, + NULL, /* EP0_TxSent, */ + USBD_CCID_EP0_RxReady, + USBD_CCID_DataIn, + USBD_CCID_DataOut, + NULL, + NULL, + NULL, + + NULL, + NULL, + NULL, + NULL, +}; + +static uint8_t ccidmsg_buf[CCID_DATA_PACKET_SIZE]; + +static uint8_t USBD_CCID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) +{ + uint8_t ret = 0U; + USBD_CCID_HandleTypeDef *hcdc; + + //Y + 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_out[CCID_OUT_EP & 0xFU].is_used = 1U; + + + USBD_LL_OpenEP(pdev, CCID_CMD_EP, USBD_EP_TYPE_INTR, CCID_DATA_PACKET_SIZE); + pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 1U; + + static USBD_CCID_HandleTypeDef mem; + pdev->pClassData = &mem; + + hcdc = (USBD_CCID_HandleTypeDef*) pdev->pClassData; + + // init transfer states + hcdc->TxState = 0U; + hcdc->RxState = 0U; + + USBD_LL_PrepareReceive(&Solo_USBD_Device, CCID_OUT_EP, ccidmsg_buf, + CCID_DATA_PACKET_SIZE); + + return ret; +} + +static uint8_t USBD_CCID_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) +{ + uint8_t ret = 0U; + //N + + USBD_LL_CloseEP(pdev, CCID_IN_EP); + pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 0U; + + USBD_LL_CloseEP(pdev, CCID_OUT_EP); + pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 0U; + + USBD_LL_CloseEP(pdev, CCID_CMD_EP); + pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 0U; + + /* DeInit physical Interface components */ + if(pdev->pClassData != NULL) + { + pdev->pClassData = NULL; + } + + return ret; +} + +/** + * @brief USBD_CDC_Setup + * Handle the CDC specific requests + * @param pdev: instance + * @param req: usb requests + * @retval status + */ +static uint8_t USBD_CCID_Setup (USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req) +{ + USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*) pdev->pClassData; + uint8_t ifalt = 0U; + uint16_t status_info = 0U; + uint8_t ret = USBD_OK; + //N + + switch (req->bmRequest & USB_REQ_TYPE_MASK) + { + case USB_REQ_TYPE_CLASS : + if (req->wLength) + { + if (req->bmRequest & 0x80U) + { + USBD_CtlSendData (pdev, (uint8_t *)(void *)hcdc->data, req->wLength); + } + else + { + hcdc->CmdOpCode = req->bRequest; + hcdc->CmdLength = (uint8_t)req->wLength; + + USBD_CtlPrepareRx (pdev, (uint8_t *)(void *)hcdc->data, req->wLength); + } + } + else + { + + } + break; + + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) + { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U); + } + else + { + USBD_CtlError (pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + USBD_CtlSendData (pdev, &ifalt, 1U); + } + else + { + USBD_CtlError (pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state != USBD_STATE_CONFIGURED) + { + USBD_CtlError (pdev, req); + ret = USBD_FAIL; + } + break; + case USB_REQ_GET_DESCRIPTOR: + break; + default: + USBD_CtlError (pdev, req); + ret = USBD_FAIL; + break; + } + break; + + default: + USBD_CtlError (pdev, req); + ret = USBD_FAIL; + break; + } + + return ret; +} + + +/** + * @brief USBD_CDC_DataIn + * Data sent on non-control IN endpoint + * @param pdev: device instance + * @param epnum: endpoint number + * @retval status + */ +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; + + /* Send ZLP */ + USBD_LL_Transmit (pdev, epnum, NULL, 0U); + } + else + { + hcdc->TxState = 0U; + } + return USBD_OK; + } + else + { + return USBD_FAIL; + } +} + +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; + + /* Transmit next packet */ + USBD_LL_Transmit(&Solo_USBD_Device, CCID_IN_EP, msg, + len); + + return USBD_OK; +} + +#define CCID_HEADER_SIZE 10 +typedef struct +{ + uint8_t type; + uint32_t len; + uint8_t slot; + uint8_t seq; + uint8_t rsvd; + uint16_t param; +} __attribute__((packed)) CCID_HEADER; + +void ccid_send_status(CCID_HEADER * c) +{ + uint8_t msg[CCID_HEADER_SIZE]; + memset(msg,0,sizeof(msg)); + + msg[0] = CCID_SLOT_STATUS_RES; + msg[6] = c->seq; + + USBD_CCID_TransmitPacket(msg, sizeof(msg)); + +} + + + + +void handle_ccid(uint8_t * msg, int len) +{ + CCID_HEADER * h = (CCID_HEADER *) msg; + switch(h->type) + { + case CCID_SLOT_STATUS: + ccid_send_status(h); + break; + default: + break; + } +} + +/** + * @brief USBD_CDC_DataOut + * Data received on non-control Out endpoint + * @param pdev: device instance + * @param epnum: endpoint number + * @retval status + */ +static uint8_t USBD_CCID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) +{ + while(1) + { + led_rgb(0xff3520); + } + USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*) pdev->pClassData; + + /* Get the received data length */ + hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); + + /* USB data will be immediately processed, this allow next USB traffic being + NAKed till the end of the application Xfer */ + if(pdev->pClassData != NULL) + { + // printf1(TAG_GREEN,"ccid>> "); + // dump_hex1(TAG_GREEN, hcdc->RxBuffer, hcdc->RxLength); + + handle_ccid(hcdc->RxBuffer, hcdc->RxLength); + + return USBD_OK; + } + else + { + return USBD_FAIL; + } +} + +/** + * @brief USBD_CDC_EP0_RxReady + * Handle EP0 Rx Ready event + * @param pdev: device instance + * @retval status + */ +static uint8_t USBD_CCID_EP0_RxReady (USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*) pdev->pClassData; + + if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU)) + { + hcdc->CmdOpCode = 0xFFU; + } + return USBD_OK; +} diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.h b/targets/stm32l432/lib/usbd/usbd_ccid.h index ce38be1..cecf170 100644 --- a/targets/stm32l432/lib/usbd/usbd_ccid.h +++ b/targets/stm32l432/lib/usbd/usbd_ccid.h @@ -1,8 +1,41 @@ #ifndef _USBD_H_ #define _USBD_H_ +#include "usbd_ioreq.h" + #define CCID_IN_EP 0x84U /* EP1 for data IN */ #define CCID_OUT_EP 0x04U /* EP1 for data OUT */ #define CCID_CMD_EP 0x85U /* EP2 for CDC commands */ +#define CCID_DATA_PACKET_SIZE 64 + +#define CCID_SET_PARAMS 0x61 +#define CCID_POWER_ON 0x62 +#define CCID_POWER_OFF 0x63 +#define CCID_SLOT_STATUS 0x65 +#define CCID_SECURE 0x69 +#define CCID_GET_PARAMS 0x6C +#define CCID_RESET_PARAMS 0x6D +#define CCID_XFR_BLOCK 0x6F +#define CCID_DATA_BLOCK_RES 0x80 +#define CCID_SLOT_STATUS_RES 0x81 +#define CCID_PARAMS_RES 0x82 + +extern USBD_ClassTypeDef USBD_CCID; + +typedef struct +{ + uint32_t data[CCID_DATA_PACKET_SIZE / 4U]; + uint8_t CmdOpCode; + uint8_t CmdLength; + uint8_t *RxBuffer; + uint8_t *TxBuffer; + uint32_t RxLength; + uint32_t TxLength; + + __IO uint32_t TxState; + __IO uint32_t RxState; +} +USBD_CCID_HandleTypeDef; + #endif diff --git a/targets/stm32l432/lib/usbd/usbd_composite.c b/targets/stm32l432/lib/usbd/usbd_composite.c index cf820d2..a70db6a 100644 --- a/targets/stm32l432/lib/usbd/usbd_composite.c +++ b/targets/stm32l432/lib/usbd/usbd_composite.c @@ -39,6 +39,7 @@ static uint8_t *USBD_Composite_GetDeviceQualifierDescriptor (uint16_t *length); #define HID_INTF_NUM 0 #define CDC_INTF_NUM 1 +#define CCID_INTF_NUM 2 __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_SIZE] __ALIGN_END = { /*Configuration Descriptor*/ @@ -176,7 +177,7 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_ /* CCID Interface Descriptor */ 9, /* bLength: Interface Descriptor size */ USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ -0, /* bInterfaceNumber: CCID Interface */ +CCID_INTF_NUM, /* bInterfaceNumber: CCID Interface */ 0, /* Alternate setting for this interface */ 3, /* bNumEndpoints: Bulk-IN, Bulk-OUT, Intr-IN */ 0x0B, /* CCID class */ @@ -273,19 +274,26 @@ int in_endpoint_to_class[MAX_ENDPOINTS]; int out_endpoint_to_class[MAX_ENDPOINTS]; -void USBD_Composite_Set_Classes(USBD_ClassTypeDef *class0, USBD_ClassTypeDef *class1) { +void USBD_Composite_Set_Classes(USBD_ClassTypeDef *class0, USBD_ClassTypeDef *class1, USBD_ClassTypeDef *class2) +{ + //Y USBD_Classes[0] = class0; USBD_Classes[1] = class1; + USBD_Classes[2] = class2; + //Y } static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { int i; + + //N + for(i = 0; i < NUM_INTERFACES; i++) { if (USBD_Classes[i]->Init(pdev, cfgidx) != USBD_OK) { return USBD_FAIL; } } - + //N return USBD_OK; } @@ -302,6 +310,7 @@ static uint8_t USBD_Composite_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) static uint8_t USBD_Composite_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { int i; + //N switch (req->bmRequest & USB_REQ_TYPE_MASK) { case USB_REQ_TYPE_CLASS : if (req->wIndex < NUM_INTERFACES) @@ -363,16 +372,19 @@ static uint8_t USBD_Composite_EP0_RxReady (USBD_HandleTypeDef *pdev) { } static uint8_t *USBD_Composite_GetFSCfgDesc (uint16_t *length) { + //Y *length = COMPOSITE_CDC_HID_DESCRIPTOR_SIZE; return COMPOSITE_CDC_HID_DESCRIPTOR; } static uint8_t *USBD_Composite_GetHSCfgDesc (uint16_t *length) { + //N *length = COMPOSITE_CDC_HID_DESCRIPTOR_SIZE; return COMPOSITE_CDC_HID_DESCRIPTOR; } static uint8_t *USBD_Composite_GetOtherSpeedCfgDesc (uint16_t *length) { + *length = COMPOSITE_CDC_HID_DESCRIPTOR_SIZE; return COMPOSITE_CDC_HID_DESCRIPTOR; } @@ -393,6 +405,7 @@ __ALIGN_BEGIN static uint8_t USBD_Composite_DeviceQualifierDesc[USB_LEN_DEV_QUAL }; uint8_t *USBD_Composite_GetDeviceQualifierDescriptor (uint16_t *length) { - *length = sizeof (USBD_Composite_DeviceQualifierDesc); - return USBD_Composite_DeviceQualifierDesc; + //N + *length = sizeof (USBD_Composite_DeviceQualifierDesc); + return USBD_Composite_DeviceQualifierDesc; } diff --git a/targets/stm32l432/lib/usbd/usbd_composite.h b/targets/stm32l432/lib/usbd/usbd_composite.h index 7599b39..0fdc513 100644 --- a/targets/stm32l432/lib/usbd/usbd_composite.h +++ b/targets/stm32l432/lib/usbd/usbd_composite.h @@ -17,7 +17,7 @@ extern int in_endpoint_to_class[MAX_ENDPOINTS]; extern int out_endpoint_to_class[MAX_ENDPOINTS]; -void USBD_Composite_Set_Classes(USBD_ClassTypeDef *class0, USBD_ClassTypeDef *class1); +void USBD_Composite_Set_Classes(USBD_ClassTypeDef *class0, USBD_ClassTypeDef *class1, USBD_ClassTypeDef *class2); #ifdef __cplusplus } diff --git a/targets/stm32l432/src/init.c b/targets/stm32l432/src/init.c index e7fa953..93ca071 100644 --- a/targets/stm32l432/src/init.c +++ b/targets/stm32l432/src/init.c @@ -27,6 +27,7 @@ #include "usbd_desc.h" #include "usbd_hid.h" #include "usbd_cdc.h" +#include "usbd_ccid.h" #include "usbd_composite.h" #include "usbd_cdc_if.h" #include "device.h" @@ -706,7 +707,7 @@ void init_usb() SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN); #if DEBUG_LEVEL > 0 - USBD_Composite_Set_Classes(&USBD_HID, &USBD_CDC); + USBD_Composite_Set_Classes(&USBD_HID, &USBD_CDC, &USBD_CCID); in_endpoint_to_class[HID_EPIN_ADDR & 0x7F] = 0; out_endpoint_to_class[HID_EPOUT_ADDR & 0x7F] = 0; @@ -723,8 +724,9 @@ void init_usb() USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0); USBD_RegisterClass(&Solo_USBD_Device, &USBD_HID); #endif - + //Y USBD_Start(&Solo_USBD_Device); + //Y } void init_pwm(void) From ba581db49c27d0a16c24e358c1bed88d6ee2f170 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Tue, 21 May 2019 20:17:44 -0400 Subject: [PATCH 04/11] delete excess --- targets/stm32l432/lib/usbd/usbd_cdc.c | 345 +------------------------- 1 file changed, 1 insertion(+), 344 deletions(-) diff --git a/targets/stm32l432/lib/usbd/usbd_cdc.c b/targets/stm32l432/lib/usbd/usbd_cdc.c index 58d1301..0d8eb36 100644 --- a/targets/stm32l432/lib/usbd/usbd_cdc.c +++ b/targets/stm32l432/lib/usbd/usbd_cdc.c @@ -195,302 +195,9 @@ USBD_ClassTypeDef USBD_CDC = NULL, NULL, NULL, - // USBD_CDC_GetHSCfgDesc, - // USBD_CDC_GetFSCfgDesc, - // USBD_CDC_GetOtherSpeedCfgDesc, - // USBD_CDC_GetDeviceQualifierDescriptor, }; -/* USB CDC device Configuration Descriptor */ -__ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ - /*Configuration Descriptor*/ - 0x09, /* bLength: Configuration Descriptor size */ - USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */ - 0x00, - 0x02, /* bNumInterfaces: 2 interface */ - 0x01, /* bConfigurationValue: Configuration value */ - 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ - /*---------------------------------------------------------------------------*/ - - /*Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - 0x00, /* bInterfaceNumber: Number of Interface */ - 0x00, /* bAlternateSetting: Alternate setting */ - 0x01, /* bNumEndpoints: One endpoints used */ - 0x02, /* bInterfaceClass: Communication Interface Class */ - 0x02, /* bInterfaceSubClass: Abstract Control Model */ - 0x01, /* bInterfaceProtocol: Common AT commands */ - 0x00, /* iInterface: */ - - /*Header Functional Descriptor*/ - 0x05, /* bLength: Endpoint Descriptor size */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x00, /* bDescriptorSubtype: Header Func Desc */ - 0x10, /* bcdCDC: spec release number */ - 0x01, - - /*Call Management Functional Descriptor*/ - 0x05, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x01, /* bDescriptorSubtype: Call Management Func Desc */ - 0x00, /* bmCapabilities: D0+D1 */ - 0x01, /* bDataInterface: 1 */ - - /*ACM Functional Descriptor*/ - 0x04, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ - 0x02, /* bmCapabilities */ - - /*Union Functional Descriptor*/ - 0x05, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x06, /* bDescriptorSubtype: Union func desc */ - 0x00, /* bMasterInterface: Communication class interface */ - 0x01, /* bSlaveInterface0: Data Class Interface */ - - /*Endpoint 2 Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /*Data class interface descriptor*/ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - 0x01, /* bInterfaceNumber: Number of Interface */ - 0x00, /* bAlternateSetting: Alternate setting */ - 0x02, /* bNumEndpoints: Two endpoints used */ - 0x0A, /* bInterfaceClass: CDC */ - 0x00, /* bInterfaceSubClass: */ - 0x00, /* bInterfaceProtocol: */ - 0x00, /* iInterface: */ - - /*Endpoint OUT Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /*Endpoint IN Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00 /* bInterval: ignore for Bulk transfer */ -} ; - - -/* USB CDC device Configuration Descriptor */ -__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ - /*Configuration Descriptor*/ - 0x09, /* bLength: Configuration Descriptor size */ - USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */ - 0x00, - 0x02, /* bNumInterfaces: 2 interface */ - 0x01, /* bConfigurationValue: Configuration value */ - 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ - 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ - - /*---------------------------------------------------------------------------*/ - - /*Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - 0x00, /* bInterfaceNumber: Number of Interface */ - 0x00, /* bAlternateSetting: Alternate setting */ - 0x01, /* bNumEndpoints: One endpoints used */ - 0x02, /* bInterfaceClass: Communication Interface Class */ - 0x02, /* bInterfaceSubClass: Abstract Control Model */ - 0x01, /* bInterfaceProtocol: Common AT commands */ - 0x00, /* iInterface: */ - - /*Header Functional Descriptor*/ - 0x05, /* bLength: Endpoint Descriptor size */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x00, /* bDescriptorSubtype: Header Func Desc */ - 0x10, /* bcdCDC: spec release number */ - 0x01, - - /*Call Management Functional Descriptor*/ - 0x05, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x01, /* bDescriptorSubtype: Call Management Func Desc */ - 0x00, /* bmCapabilities: D0+D1 */ - 0x01, /* bDataInterface: 1 */ - - /*ACM Functional Descriptor*/ - 0x04, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ - 0x02, /* bmCapabilities */ - - /*Union Functional Descriptor*/ - 0x05, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x06, /* bDescriptorSubtype: Union func desc */ - 0x00, /* bMasterInterface: Communication class interface */ - 0x01, /* bSlaveInterface0: Data Class Interface */ - - /*Endpoint 2 Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /*Data class interface descriptor*/ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - 0x01, /* bInterfaceNumber: Number of Interface */ - 0x00, /* bAlternateSetting: Alternate setting */ - 0x02, /* bNumEndpoints: Two endpoints used */ - 0x0A, /* bInterfaceClass: CDC */ - 0x00, /* bInterfaceSubClass: */ - 0x00, /* bInterfaceProtocol: */ - 0x00, /* iInterface: */ - - /*Endpoint OUT Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /*Endpoint IN Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00 /* bInterval: ignore for Bulk transfer */ -} ; - -__ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ - 0x09, /* bLength: Configuation Descriptor size */ - USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, - USB_CDC_CONFIG_DESC_SIZ, - 0x00, - 0x02, /* bNumInterfaces: 2 interfaces */ - 0x01, /* bConfigurationValue: */ - 0x04, /* iConfiguration: */ - 0xC0, /* bmAttributes: */ - 0x32, /* MaxPower 100 mA */ - - /*Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - 0x00, /* bInterfaceNumber: Number of Interface */ - 0x00, /* bAlternateSetting: Alternate setting */ - 0x01, /* bNumEndpoints: One endpoints used */ - 0x02, /* bInterfaceClass: Communication Interface Class */ - 0x02, /* bInterfaceSubClass: Abstract Control Model */ - 0x01, /* bInterfaceProtocol: Common AT commands */ - 0x00, /* iInterface: */ - - /*Header Functional Descriptor*/ - 0x05, /* bLength: Endpoint Descriptor size */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x00, /* bDescriptorSubtype: Header Func Desc */ - 0x10, /* bcdCDC: spec release number */ - 0x01, - - /*Call Management Functional Descriptor*/ - 0x05, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x01, /* bDescriptorSubtype: Call Management Func Desc */ - 0x00, /* bmCapabilities: D0+D1 */ - 0x01, /* bDataInterface: 1 */ - - /*ACM Functional Descriptor*/ - 0x04, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ - 0x02, /* bmCapabilities */ - - /*Union Functional Descriptor*/ - 0x05, /* bFunctionLength */ - 0x24, /* bDescriptorType: CS_INTERFACE */ - 0x06, /* bDescriptorSubtype: Union func desc */ - 0x00, /* bMasterInterface: Communication class interface */ - 0x01, /* bSlaveInterface0: Data Class Interface */ - - /*Endpoint 2 Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */ - CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - - /*---------------------------------------------------------------------------*/ - - /*Data class interface descriptor*/ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - 0x01, /* bInterfaceNumber: Number of Interface */ - 0x00, /* bAlternateSetting: Alternate setting */ - 0x02, /* bNumEndpoints: Two endpoints used */ - 0x0A, /* bInterfaceClass: CDC */ - 0x00, /* bInterfaceSubClass: */ - 0x00, /* bInterfaceProtocol: */ - 0x00, /* iInterface: */ - - /*Endpoint OUT Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - 0x40, /* wMaxPacketSize: */ - 0x00, - 0x00, /* bInterval: ignore for Bulk transfer */ - - /*Endpoint IN Descriptor*/ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - 0x40, /* wMaxPacketSize: */ - 0x00, - 0x00 /* bInterval */ -}; - -/** - * @} - */ - -/** @defgroup USBD_CDC_Private_Functions - * @{ - */ /** * @brief USBD_CDC_Init @@ -782,45 +489,7 @@ static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) return USBD_OK; } -/** - * @brief USBD_CDC_GetFSCfgDesc - * Return configuration descriptor - * @param speed : current device speed - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -/*static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length) -{ - *length = sizeof (USBD_CDC_CfgFSDesc); - return USBD_CDC_CfgFSDesc; -} -*/ -/** - * @brief USBD_CDC_GetHSCfgDesc - * Return configuration descriptor - * @param speed : current device speed - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -/*static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length) -{ - *length = sizeof (USBD_CDC_CfgHSDesc); - return USBD_CDC_CfgHSDesc; -} -*/ -/** - * @brief USBD_CDC_GetCfgDesc - * Return configuration descriptor - * @param speed : current device speed - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -/*static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) -{ - *length = sizeof (USBD_CDC_OtherSpeedCfgDesc); - return USBD_CDC_OtherSpeedCfgDesc; -} -*/ + /** * @brief DeviceQualifierDescriptor * return Device Qualifier descriptor @@ -939,22 +608,10 @@ uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) /* Suspend or Resume USB Out process */ if(pdev->pClassData != NULL) { - if(pdev->dev_speed == USBD_SPEED_HIGH ) - { - /* Prepare Out endpoint to receive next packet */ - USBD_LL_PrepareReceive(pdev, - CDC_OUT_EP, - hcdc->RxBuffer, - CDC_DATA_HS_OUT_PACKET_SIZE); - } - else - { - /* Prepare Out endpoint to receive next packet */ USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, CDC_DATA_FS_OUT_PACKET_SIZE); - } return USBD_OK; } else From a51417bf61da53c19c61333ded2f565b40a0118c Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Fri, 31 May 2019 15:58:13 -0400 Subject: [PATCH 05/11] fix epout connection --- targets/stm32l432/lib/usbd/usbd_ccid.c | 33 +++++++++++++++++--------- targets/stm32l432/lib/usbd/usbd_ccid.h | 2 ++ targets/stm32l432/lib/usbd/usbd_conf.c | 5 +++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.c b/targets/stm32l432/lib/usbd/usbd_ccid.c index e202ffe..c452aa3 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, - USBD_CCID_DataOut, + usb_ccid_recieve_callback, NULL, NULL, NULL, @@ -259,7 +259,7 @@ void ccid_send_status(CCID_HEADER * c) memset(msg,0,sizeof(msg)); msg[0] = CCID_SLOT_STATUS_RES; - msg[6] = c->seq; + msg[6] = 1; USBD_CCID_TransmitPacket(msg, sizeof(msg)); @@ -277,6 +277,12 @@ void handle_ccid(uint8_t * msg, int len) ccid_send_status(h); break; default: + // while(1) + // { + // led_rgb(0xff3520); + // } + //Y + ccid_send_status(h); break; } } @@ -288,12 +294,9 @@ void handle_ccid(uint8_t * msg, int len) * @param epnum: endpoint number * @retval status */ -static uint8_t USBD_CCID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) +uint8_t usb_ccid_recieve_callback(USBD_HandleTypeDef *pdev, uint8_t epnum) { - while(1) - { - led_rgb(0xff3520); - } + USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*) pdev->pClassData; /* Get the received data length */ @@ -312,10 +315,18 @@ static uint8_t USBD_CCID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) } else { + + + while(1) + { + led_rgb(0xff3520); + } + return USBD_FAIL; } } + /** * @brief USBD_CDC_EP0_RxReady * Handle EP0 Rx Ready event @@ -326,9 +337,9 @@ static uint8_t USBD_CCID_EP0_RxReady (USBD_HandleTypeDef *pdev) { USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*) pdev->pClassData; - if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU)) - { - hcdc->CmdOpCode = 0xFFU; - } + // if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU)) + // { + // hcdc->CmdOpCode = 0xFFU; + // } return USBD_OK; } diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.h b/targets/stm32l432/lib/usbd/usbd_ccid.h index cecf170..6535987 100644 --- a/targets/stm32l432/lib/usbd/usbd_ccid.h +++ b/targets/stm32l432/lib/usbd/usbd_ccid.h @@ -38,4 +38,6 @@ typedef struct } USBD_CCID_HandleTypeDef; +uint8_t usb_ccid_recieve_callback(USBD_HandleTypeDef *pdev, uint8_t epnum); + #endif diff --git a/targets/stm32l432/lib/usbd/usbd_conf.c b/targets/stm32l432/lib/usbd/usbd_conf.c index 793a0a2..61bcecd 100644 --- a/targets/stm32l432/lib/usbd/usbd_conf.c +++ b/targets/stm32l432/lib/usbd/usbd_conf.c @@ -119,9 +119,12 @@ void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); switch(epnum) { - case HID_ENDPOINT: + case HID_EPOUT_ADDR: usb_hid_recieve_callback(epnum); break; + case CCID_OUT_EP: + usb_ccid_recieve_callback((USBD_HandleTypeDef*)hpcd->pData, epnum); + break; } } From 32f920e372b6d6c924f48512a714a9628ef5fea3 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Thu, 22 Aug 2019 19:52:21 +0800 Subject: [PATCH 06/11] 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); From bde4c09c21ad943bf20634455b90f6a29ab5e527 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Sat, 24 Aug 2019 15:06:16 +0800 Subject: [PATCH 07/11] CCID basics working --- targets/stm32l432/lib/usbd/usbd_ccid.c | 104 ++++++++----------------- targets/stm32l432/lib/usbd/usbd_ccid.h | 17 +++- targets/stm32l432/lib/usbd/usbd_conf.c | 21 ++--- 3 files changed, 62 insertions(+), 80 deletions(-) diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.c b/targets/stm32l432/lib/usbd/usbd_ccid.c index 2a81ef7..76b8b8e 100644 --- a/targets/stm32l432/lib/usbd/usbd_ccid.c +++ b/targets/stm32l432/lib/usbd/usbd_ccid.c @@ -64,6 +64,8 @@ static uint8_t USBD_CCID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) USBD_LL_OpenEP(pdev, CCID_CMD_EP, USBD_EP_TYPE_INTR, CCID_DATA_PACKET_SIZE); pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 1U; + // dump_pma_header("ccid.c"); + static USBD_CCID_HandleTypeDef mem; pdev->pClassData = &mem; @@ -207,30 +209,8 @@ static uint8_t USBD_CCID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) } 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; - - // /* 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; } @@ -246,41 +226,39 @@ uint8_t USBD_CCID_TransmitPacket(uint8_t * msg, int len) 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); - + printf1(TAG_GREEN,"ccid<< "); + dump_hex1(TAG_GREEN, msg, len); return USBD_OK; } -#define CCID_HEADER_SIZE 10 -typedef struct -{ - uint8_t type; - uint32_t len; - uint8_t slot; - uint8_t seq; - uint8_t rsvd; - uint16_t param; -} __attribute__((packed)) CCID_HEADER; -void ccid_send_status(CCID_HEADER * c) + +void ccid_send_status(CCID_HEADER * c, uint8_t status) { uint8_t msg[CCID_HEADER_SIZE]; memset(msg,0,sizeof(msg)); msg[0] = CCID_SLOT_STATUS_RES; - msg[6] = 1; + msg[6] = c->seq; + msg[7] = status; USBD_CCID_TransmitPacket(msg, sizeof(msg)); } +void ccid_send_data_block(CCID_HEADER * c, uint8_t status) +{ + uint8_t msg[CCID_HEADER_SIZE]; + memset(msg,0,sizeof(msg)); + + msg[0] = CCID_DATA_BLOCK_RES; + msg[6] = c->seq; + msg[7] = status; + + USBD_CCID_TransmitPacket(msg, sizeof(msg)); + +} void handle_ccid(uint8_t * msg, int len) { @@ -288,15 +266,16 @@ void handle_ccid(uint8_t * msg, int len) switch(h->type) { case CCID_SLOT_STATUS: - ccid_send_status(h); + ccid_send_status(h, CCID_STATUS_ON); + break; + case CCID_POWER_ON: + ccid_send_data_block(h, CCID_STATUS_ON); + break; + case CCID_POWER_OFF: + ccid_send_status(h, CCID_STATUS_OFF); break; default: - // while(1) - // { - // led_rgb(0xff3520); - // } - //Y - ccid_send_status(h); + ccid_send_status(h, CCID_STATUS_ON); break; } } @@ -316,24 +295,15 @@ uint8_t usb_ccid_recieve_callback(USBD_HandleTypeDef *pdev, uint8_t epnum) /* Get the received data length */ hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); - /* USB data will be immediately processed, this allow next USB traffic being - NAKed till the end of the application Xfer */ - if(pdev->pClassData != NULL) - { - // printf1(TAG_GREEN,"ccid>> "); - // dump_hex1(TAG_GREEN, hcdc->RxBuffer, hcdc->RxLength); + printf1(TAG_GREEN, "ccid>> "); + dump_hex1(TAG_GREEN, ccidmsg_buf, hcdc->RxLength); - handle_ccid(hcdc->RxBuffer, hcdc->RxLength); + handle_ccid(ccidmsg_buf, hcdc->RxLength); - return USBD_OK; - } - else - { + USBD_LL_PrepareReceive(&Solo_USBD_Device, CCID_OUT_EP, ccidmsg_buf, + CCID_DATA_PACKET_SIZE); - while(1){ led_rgb(0xff3520); } - - return USBD_FAIL; - } + return USBD_OK; } @@ -345,11 +315,5 @@ uint8_t usb_ccid_recieve_callback(USBD_HandleTypeDef *pdev, uint8_t epnum) */ static uint8_t USBD_CCID_EP0_RxReady (USBD_HandleTypeDef *pdev) { - USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*) pdev->pClassData; - - // if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU)) - // { - // hcdc->CmdOpCode = 0xFFU; - // } return USBD_OK; } diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.h b/targets/stm32l432/lib/usbd/usbd_ccid.h index 6535987..513c796 100644 --- a/targets/stm32l432/lib/usbd/usbd_ccid.h +++ b/targets/stm32l432/lib/usbd/usbd_ccid.h @@ -3,7 +3,18 @@ #include "usbd_ioreq.h" -#define CCID_IN_EP 0x84U /* EP1 for data IN */ +#define CCID_HEADER_SIZE 10 +typedef struct +{ + uint8_t type; + uint32_t len; + uint8_t slot; + uint8_t seq; + uint8_t rsvd; + uint16_t param; +} __attribute__((packed)) CCID_HEADER; + +#define CCID_IN_EP 0x86U /* EP1 for data IN */ #define CCID_OUT_EP 0x04U /* EP1 for data OUT */ #define CCID_CMD_EP 0x85U /* EP2 for CDC commands */ @@ -17,6 +28,10 @@ #define CCID_GET_PARAMS 0x6C #define CCID_RESET_PARAMS 0x6D #define CCID_XFR_BLOCK 0x6F + +#define CCID_STATUS_ON 0x00 +#define CCID_STATUS_OFF 0x02 + #define CCID_DATA_BLOCK_RES 0x80 #define CCID_SLOT_STATUS_RES 0x81 #define CCID_PARAMS_RES 0x82 diff --git a/targets/stm32l432/lib/usbd/usbd_conf.c b/targets/stm32l432/lib/usbd/usbd_conf.c index 61bcecd..ad5b211 100644 --- a/targets/stm32l432/lib/usbd/usbd_conf.c +++ b/targets/stm32l432/lib/usbd/usbd_conf.c @@ -52,6 +52,7 @@ #include "usbd_hid.h" #include "usbd_cdc.h" #include "usbd_ccid.h" +#include "log.h" void SystemClock_Config(void); @@ -223,7 +224,6 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) { USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); } - /** * @brief Initializes the low level portion of the device driver. * @param pdev: Device handle @@ -260,15 +260,17 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , HID_EPOUT_ADDR , PCD_SNG_BUF, 0x98); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , HID_EPIN_ADDR , PCD_SNG_BUF, 0xd8); - // CDC / uart - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_OUT_EP , PCD_SNG_BUF, 0xd8 + 64); // data OUT - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_IN_EP , PCD_SNG_BUF, 0xd8 + 64*2); // data IN - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_CMD_EP , PCD_SNG_BUF, 0xd8 + 64*3); // commands - // CCID - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_OUT_EP , PCD_SNG_BUF, 0xd8 + 64*4); // data OUT - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_IN_EP , PCD_SNG_BUF, 0xd8 + 64*5); // data IN - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_CMD_EP , PCD_SNG_BUF, 0xd8 + 64*6); // commands + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_OUT_EP , PCD_SNG_BUF, 0xd8 + 64); // data OUT + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_IN_EP , PCD_SNG_BUF, 0xd8 + 64*2); // data IN + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CCID_CMD_EP , PCD_SNG_BUF, 0xd8 + 64*3); // commands + + // CDC / uart + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_CMD_EP , PCD_SNG_BUF, 0xd8 + 64*4); // commands + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_OUT_EP , PCD_SNG_BUF, 0xd8 + 64*5); // data OUT + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_IN_EP , PCD_SNG_BUF, 0xd8 + 64*6); // data IN + + // dump_pma_header("usbd_conf"); return USBD_OK; } @@ -319,6 +321,7 @@ USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_type, uint16_t ep_mps) { + // printf1(TAG_RED,"LL_Open. ep: %x, %x\r\n", ep_addr, ep_type); HAL_PCD_EP_Open((PCD_HandleTypeDef*) pdev->pData, ep_addr, ep_mps, From ccd9a04146c5ebdc241e9ee3077597d62e07092b Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Sat, 24 Aug 2019 15:08:14 +0800 Subject: [PATCH 08/11] add ccid log tag --- fido2/log.c | 1 + fido2/log.h | 1 + fido2/main.c | 1 + targets/stm32l432/lib/usbd/usbd_ccid.c | 8 ++++---- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fido2/log.c b/fido2/log.c index c4d874e..af2cd55 100644 --- a/fido2/log.c +++ b/fido2/log.c @@ -50,6 +50,7 @@ struct logtag tagtable[] = { {TAG_EXT,"EXT"}, {TAG_NFC,"NFC"}, {TAG_NFC_APDU, "NAPDU"}, + {TAG_CCID, "CCID"}, }; diff --git a/fido2/log.h b/fido2/log.h index d7190cf..17a2d6b 100644 --- a/fido2/log.h +++ b/fido2/log.h @@ -44,6 +44,7 @@ typedef enum TAG_EXT = (1 << 18), TAG_NFC = (1 << 19), TAG_NFC_APDU = (1 << 20), + TAG_CCID = (1 << 21), TAG_NO_TAG = (1UL << 30), TAG_FILENO = (1UL << 31) diff --git a/fido2/main.c b/fido2/main.c index f794375..a22d48c 100644 --- a/fido2/main.c +++ b/fido2/main.c @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) TAG_GREEN| TAG_RED| TAG_EXT| + TAG_CCID| TAG_ERR ); diff --git a/targets/stm32l432/lib/usbd/usbd_ccid.c b/targets/stm32l432/lib/usbd/usbd_ccid.c index 76b8b8e..0a0a797 100644 --- a/targets/stm32l432/lib/usbd/usbd_ccid.c +++ b/targets/stm32l432/lib/usbd/usbd_ccid.c @@ -226,8 +226,8 @@ uint8_t USBD_CCID_TransmitPacket(uint8_t * msg, int len) USBD_LL_Transmit(&Solo_USBD_Device, CCID_IN_EP, msg, len); - printf1(TAG_GREEN,"ccid<< "); - dump_hex1(TAG_GREEN, msg, len); + printf1(TAG_CCID,"<< "); + dump_hex1(TAG_CCID, msg, len); return USBD_OK; } @@ -295,8 +295,8 @@ uint8_t usb_ccid_recieve_callback(USBD_HandleTypeDef *pdev, uint8_t epnum) /* Get the received data length */ hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); - printf1(TAG_GREEN, "ccid>> "); - dump_hex1(TAG_GREEN, ccidmsg_buf, hcdc->RxLength); + printf1(TAG_CCID, ">> "); + dump_hex1(TAG_CCID, ccidmsg_buf, hcdc->RxLength); handle_ccid(ccidmsg_buf, hcdc->RxLength); From 3b4c154fd17607fc14ddb5ce7eb29773055a0379 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Sat, 24 Aug 2019 15:49:02 +0800 Subject: [PATCH 09/11] add enable macro for CCID interface --- targets/stm32l432/lib/usbd/usbd_composite.c | 60 ++++++++++++++------- targets/stm32l432/src/app.h | 4 ++ targets/stm32l432/src/init.c | 10 +--- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/targets/stm32l432/lib/usbd/usbd_composite.c b/targets/stm32l432/lib/usbd/usbd_composite.c index 7d5fdb4..b1de7d2 100644 --- a/targets/stm32l432/lib/usbd/usbd_composite.c +++ b/targets/stm32l432/lib/usbd/usbd_composite.c @@ -4,6 +4,7 @@ #include "usbd_cdc.h" #include "usbd_ccid.h" #include "usbd_ctlreq.h" +#include "app.h" static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx); @@ -27,20 +28,29 @@ static uint8_t *USBD_Composite_GetOtherSpeedCfgDesc (uint16_t *length); static uint8_t *USBD_Composite_GetDeviceQualifierDescriptor (uint16_t *length); +#ifdef ENABLE_CCID +#define CCID_SIZE 84 +#define CCID_NUM_INTERFACE 1 +#else +#define CCID_NUM_INTERFACE 0 +#define CCID_SIZE 0 +#endif + +#if DEBUG_LEVEL > 0 +#define CDC_SIZE (49 + 8 + 9 + 4) +#define CDC_NUM_INTERFACE 2 +#else +#define CDC_SIZE 0 +#define CDC_NUM_INTERFACE 0 +#endif + +#define HID_SIZE 41 + +#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (HID_SIZE + CDC_SIZE + CCID_SIZE) +#define NUM_INTERFACES (1 + CDC_NUM_INTERFACE + CCID_NUM_INTERFACE) #define NUM_CLASSES 3 -#if NUM_CLASSES>2 -#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 + 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 CDC_MASTER_INTF_NUM 1 #define CDC_SLAVE_INTF_NUM 2 @@ -101,7 +111,7 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_ 0x00, HID_BINTERVAL, /*bInterval: Polling Interval */ -#if NUM_INTERFACES > 2 +#if DEBUG_LEVEL > 0 /* */ /* CDC */ @@ -199,7 +209,7 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_ 0x04, #endif -#if NUM_INTERFACES>3 +#ifdef ENABLE_CCID /* CCID Interface Descriptor */ 9, /* bLength: Interface Descriptor size */ @@ -295,16 +305,21 @@ USBD_ClassTypeDef USBD_Composite = USBD_Composite_GetDeviceQualifierDescriptor, }; -static USBD_ClassTypeDef *USBD_Classes[MAX_CLASSES]; +static USBD_ClassTypeDef * USBD_Classes[MAX_CLASSES]; 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) { + memset(USBD_Classes, 0 , sizeof(USBD_Classes)); USBD_Classes[0] = hid_class; +#ifdef ENABLE_CCID USBD_Classes[1] = ccid_class; +#endif +#if DEBUG_LEVEL > 0 USBD_Classes[2] = cdc_class; +#endif } static USBD_ClassTypeDef * getClass(uint8_t index) @@ -313,12 +328,15 @@ static USBD_ClassTypeDef * getClass(uint8_t index) { case HID_INTF_NUM: return USBD_Classes[0]; +#ifdef ENABLE_CCID case CCID_INTF_NUM: return USBD_Classes[1]; +#endif +#if DEBUG_LEVEL > 0 case CDC_MASTER_INTF_NUM: case CDC_SLAVE_INTF_NUM: return USBD_Classes[2]; - +#endif } return NULL; } @@ -326,7 +344,7 @@ static USBD_ClassTypeDef * getClass(uint8_t index) static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { int i; for(i = 0; i < NUM_CLASSES; i++) { - if (USBD_Classes[i]->Init(pdev, cfgidx) != USBD_OK) { + if (USBD_Classes[i] != NULL && USBD_Classes[i]->Init(pdev, cfgidx) != USBD_OK) { return USBD_FAIL; } } @@ -337,7 +355,7 @@ static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { static uint8_t USBD_Composite_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { int i; for(i = 0; i < NUM_CLASSES; i++) { - if (USBD_Classes[i]->DeInit(pdev, cfgidx) != USBD_OK) { + if (USBD_Classes[i] != NULL && USBD_Classes[i]->DeInit(pdev, cfgidx) != USBD_OK) { return USBD_FAIL; } } @@ -363,7 +381,7 @@ static uint8_t USBD_Composite_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqType case USB_REQ_GET_DESCRIPTOR : for(i = 0; i < NUM_CLASSES; i++) { - if (USBD_Classes[i]->Setup(pdev, req) != USBD_OK) { + if (USBD_Classes[i] != NULL && USBD_Classes[i]->Setup(pdev, req) != USBD_OK) { return USBD_FAIL; } } @@ -386,6 +404,8 @@ static uint8_t USBD_Composite_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) { i = in_endpoint_to_class[epnum]; + if (USBD_Classes[i] == NULL) return USBD_FAIL; + return USBD_Classes[i]->DataIn(pdev, epnum); } @@ -394,6 +414,8 @@ static uint8_t USBD_Composite_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) i = out_endpoint_to_class[epnum]; + if (USBD_Classes[i] == NULL) return USBD_FAIL; + return USBD_Classes[i]->DataOut(pdev, epnum); } @@ -401,7 +423,7 @@ static uint8_t USBD_Composite_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) static uint8_t USBD_Composite_EP0_RxReady (USBD_HandleTypeDef *pdev) { int i; for(i = 0; i < NUM_CLASSES; i++) { - if (USBD_Classes[i]->EP0_RxReady != NULL) { + if (USBD_Classes[i] != NULL && USBD_Classes[i]->EP0_RxReady != NULL) { if (USBD_Classes[i]->EP0_RxReady(pdev) != USBD_OK) { return USBD_FAIL; } diff --git a/targets/stm32l432/src/app.h b/targets/stm32l432/src/app.h index 308e5f6..fcd5629 100644 --- a/targets/stm32l432/src/app.h +++ b/targets/stm32l432/src/app.h @@ -12,9 +12,13 @@ #define DEBUG_UART USART1 #ifndef DEBUG_LEVEL +// Enable the CDC ACM USB interface & debug logs (DEBUG_LEVEL > 0) #define DEBUG_LEVEL 0 #endif +// Enable the CCID USB interface +// #define ENABLE_CCID + #define NON_BLOCK_PRINTING 0 diff --git a/targets/stm32l432/src/init.c b/targets/stm32l432/src/init.c index c57392c..a51e8b8 100644 --- a/targets/stm32l432/src/init.c +++ b/targets/stm32l432/src/init.c @@ -707,7 +707,6 @@ void init_usb() // Enable USB Clock SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN); -#if DEBUG_LEVEL > 0 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; @@ -720,17 +719,10 @@ void init_usb() USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0); USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite); - // USBD_RegisterClass(&Solo_USBD_Device, &USBD_HID); - // - // USBD_RegisterClass(&Solo_USBD_Device, &USBD_CDC); +#if DEBUG_LEVEL > 0 USBD_CDC_RegisterInterface(&Solo_USBD_Device, &USBD_Interface_fops_FS); -#else - USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0); - USBD_RegisterClass(&Solo_USBD_Device, &USBD_HID); #endif - //Y USBD_Start(&Solo_USBD_Device); - //Y } void init_pwm(void) From 3ba9b671fc1eec23547d5a4314513c7dc6886cd9 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Sat, 24 Aug 2019 16:01:44 +0800 Subject: [PATCH 10/11] dont use composit for bootloader --- targets/stm32l432/src/init.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/targets/stm32l432/src/init.c b/targets/stm32l432/src/init.c index a51e8b8..bdf42fa 100644 --- a/targets/stm32l432/src/init.c +++ b/targets/stm32l432/src/init.c @@ -706,7 +706,7 @@ void init_usb() // Enable USB Clock SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN); - +#ifndef IS_BOOTLOADER 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; @@ -721,6 +721,10 @@ void init_usb() USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite); #if DEBUG_LEVEL > 0 USBD_CDC_RegisterInterface(&Solo_USBD_Device, &USBD_Interface_fops_FS); +#endif +#else + USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0); + USBD_RegisterClass(&Solo_USBD_Device, &USBD_HID); #endif USBD_Start(&Solo_USBD_Device); } From 8bf1921263fedb173e333b8d41fee5fc484cf7bc Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Sat, 24 Aug 2019 16:20:52 +0800 Subject: [PATCH 11/11] dont reference not-enabled ccid --- targets/stm32l432/lib/usbd/usbd_conf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/targets/stm32l432/lib/usbd/usbd_conf.c b/targets/stm32l432/lib/usbd/usbd_conf.c index ad5b211..bd3c442 100644 --- a/targets/stm32l432/lib/usbd/usbd_conf.c +++ b/targets/stm32l432/lib/usbd/usbd_conf.c @@ -123,9 +123,11 @@ void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) case HID_EPOUT_ADDR: usb_hid_recieve_callback(epnum); break; +#ifdef ENABLE_CCID case CCID_OUT_EP: usb_ccid_recieve_callback((USBD_HandleTypeDef*)hpcd->pData, epnum); break; +#endif } }