compile/crash fixes

This commit is contained in:
Conor Patrick 2019-08-22 19:52:21 +08:00
parent a5aff478dd
commit 32f920e372
3 changed files with 128 additions and 115 deletions

View File

@ -32,7 +32,7 @@ USBD_ClassTypeDef USBD_CCID =
NULL, /* EP0_TxSent, */ NULL, /* EP0_TxSent, */
USBD_CCID_EP0_RxReady, USBD_CCID_EP0_RxReady,
USBD_CCID_DataIn, USBD_CCID_DataIn,
usb_ccid_recieve_callback, USBD_CCID_DataOut,
NULL, NULL,
NULL, 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, USBD_LL_OpenEP(pdev, CCID_IN_EP, USBD_EP_TYPE_BULK,
CCID_DATA_PACKET_SIZE); 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, USBD_LL_OpenEP(pdev, CCID_OUT_EP, USBD_EP_TYPE_BULK,
CCID_DATA_PACKET_SIZE); CCID_DATA_PACKET_SIZE);
pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 1U;
pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 1U; pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 1U;
@ -202,43 +201,60 @@ static uint8_t USBD_CCID_Setup (USBD_HandleTypeDef *pdev,
* @param epnum: endpoint number * @param epnum: endpoint number
* @retval status * @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) static uint8_t USBD_CCID_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
{ {
//N //N
USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*)pdev->pClassData; USBD_CCID_HandleTypeDef *hcdc = (USBD_CCID_HandleTypeDef*)pdev->pClassData;
PCD_HandleTypeDef *hpcd = pdev->pData; PCD_HandleTypeDef *hpcd = pdev->pData;
if(pdev->pClassData != NULL) // if(pdev->pClassData != NULL)
{ // {
if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) // 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 */ // /* Update the packet total length */
pdev->ep_in[epnum].total_length = 0U; // pdev->ep_in[epnum].total_length = 0U;
/* Send ZLP */ // /* Send ZLP */
USBD_LL_Transmit (pdev, epnum, NULL, 0U); // USBD_LL_Transmit (pdev, epnum, NULL, 0U);
} // }
else // else
{ // {
// hcdc->TxState = 0U;
// }
// return USBD_OK;
// }
// else
// {
// return USBD_FAIL;
// }
hcdc->TxState = 0U; hcdc->TxState = 0U;
}
return USBD_OK; return USBD_OK;
} }
else
{
return USBD_FAIL;
}
}
uint8_t USBD_CCID_TransmitPacket(uint8_t * msg, int len) uint8_t USBD_CCID_TransmitPacket(uint8_t * msg, int len)
{ {
/* Update the packet total length */ /* Update the packet total length */
Solo_USBD_Device.ep_in[CCID_IN_EP & 0xFU].total_length = len; 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 */ /* Transmit next packet */
USBD_LL_Transmit(&Solo_USBD_Device, CCID_IN_EP, msg, USBD_LL_Transmit(&Solo_USBD_Device, CCID_IN_EP, msg,
len); 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; return USBD_OK;
} }
@ -266,8 +282,6 @@ void ccid_send_status(CCID_HEADER * c)
} }
void handle_ccid(uint8_t * msg, int len) void handle_ccid(uint8_t * msg, int len)
{ {
CCID_HEADER * h = (CCID_HEADER *) msg; CCID_HEADER * h = (CCID_HEADER *) msg;
@ -316,11 +330,7 @@ uint8_t usb_ccid_recieve_callback(USBD_HandleTypeDef *pdev, uint8_t epnum)
else else
{ {
while(1){ led_rgb(0xff3520); }
while(1)
{
led_rgb(0xff3520);
}
return USBD_FAIL; return USBD_FAIL;
} }

View File

@ -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 COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 8+9 + 4 + 84)
#define NUM_INTERFACES 4 #define NUM_INTERFACES 4
#elif NUM_CLASSES>1 #elif NUM_CLASSES>1
#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 84) #define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 8+9 + 4)
#define NUM_INTERFACES 2 #define NUM_INTERFACES 3
#else #else
#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (41) #define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (41)
#define NUM_INTERFACES 1 #define NUM_INTERFACES 1
#endif #endif
#define HID_INTF_NUM 0 #define HID_INTF_NUM 0
#define CCID_INTF_NUM 1 #define CDC_MASTER_INTF_NUM 1
#define CDC_MASTER_INTF_NUM 2 #define CDC_SLAVE_INTF_NUM 2
#define CDC_SLAVE_INTF_NUM 3 #define CCID_INTF_NUM 3
__ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_SIZE] __ALIGN_END = __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_SIZE] __ALIGN_END =
{ {
/*Configuration Descriptor*/ /*Configuration Descriptor*/
@ -101,81 +101,6 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_
0x00, 0x00,
HID_BINTERVAL, /*bInterval: Polling Interval */ 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 #if NUM_INTERFACES > 2
/* */ /* */
@ -274,6 +199,81 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_
0x04, 0x04,
#endif #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]; 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[0] = hid_class;
USBD_Classes[1] = ccid_class; USBD_Classes[1] = ccid_class;
USBD_Classes[2] = cdc_class; USBD_Classes[2] = cdc_class;
@ -314,10 +314,10 @@ static USBD_ClassTypeDef * getClass(uint8_t index)
case HID_INTF_NUM: case HID_INTF_NUM:
return USBD_Classes[0]; return USBD_Classes[0];
case CCID_INTF_NUM: case CCID_INTF_NUM:
return USBD_Classes[2]; return USBD_Classes[1];
case CDC_MASTER_INTF_NUM: case CDC_MASTER_INTF_NUM:
case CDC_SLAVE_INTF_NUM: case CDC_SLAVE_INTF_NUM:
return USBD_Classes[3]; return USBD_Classes[2];
} }
return NULL; return NULL;

View File

@ -708,12 +708,15 @@ void init_usb()
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN); SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN);
#if DEBUG_LEVEL > 0 #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; in_endpoint_to_class[HID_EPIN_ADDR & 0x7F] = 0;
out_endpoint_to_class[HID_EPOUT_ADDR & 0x7F] = 0; out_endpoint_to_class[HID_EPOUT_ADDR & 0x7F] = 0;
in_endpoint_to_class[CDC_IN_EP & 0x7F] = 1; in_endpoint_to_class[CCID_IN_EP & 0x7F] = 1;
out_endpoint_to_class[CDC_OUT_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_Init(&Solo_USBD_Device, &Solo_Desc, 0);
USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite); USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite);