cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 add endpoint to USB

thom_as
Associate II
Posted on June 10, 2016 at 11:52

I'm doing a project where I use a NUCLEO-F446ZE as a USB device.

I'm implementing the CCID class. I used the template class and some code from VCP. This way some endpoint are already configured like Bulk in and out. Now I want to add Interrupt IN because it's used to tell the host if there is any change (like card insertion/removal). I added this in my class file in the init function

#define CCID_INTR_IN_EP 82
#define CCID_INTR_EP_MAX_PACKET 4
USBD_LL_OpenEP(pdev,
CCID_INTR_IN_EP,
USBD_EP_TYPE_INTR,
CCID_INTR_EP_MAX_PACKET);

and this to usb_conf.c in the USBD_LL_Init() function

HAL_PCDEx_SetTxFiFo(&hpcd, 2, 0x40);

But it doesn't work, the host receive nothing and the USB register aren't configured #stm32f4-nucleo-hal #ccid #device #usb
2 REPLIES 2
tsuneo
Senior
Posted on June 12, 2016 at 13:41

Your above code looks like fine.

1) Does the CCID interface descriptor declare

three endpoints?

{

sizeof(USBInterfaceDescriptor),

USBGenericDescriptor_INTERFACE,

0, // Interface 0

0, // No alternate settings

3, // uses bulk-IN, bulk-OUT and interrupt IN

SMART_CARD_DEVICE_CLASS, // = 0x0B 

0, // Subclass code

0, // bulk transfers optional interrupt-IN

0 // No associated string descriptor

},

2) HAL_PCDEx_SetTxFiFo() has a couple of restrictions.

- First, the RX FIFO is set up by HAL_PCDEx_SetRxFiFo(). HAL_PCDEx_SetTxFiFo() should be called after HAL_PCDEx_SetRxFiFo().

- HAL_PCDEx_SetTxFiFo() for two or more IN endpoints should be called in the order of the endpoint number.

- The ''size'' parameters of HAL_PCDEx_SetRxFiFo() and HAL_PCDEx_SetTxFiFo() is represented in the terms of 4-byte ''word''. Minimum: 16 words, maximum: 256 words

- The total of FIFO sizes should be no more than the 1.25 Kbytes USB RAM

HAL_PCDEx_SetRxFiFo(&hpcd, 0x40); // 0x40 words = 256 bytes

HAL_PCDEx_SetTxFiFo(&hpcd, 0, 0x20); // 128 bytes

HAL_PCDEx_SetTxFiFo(&hpcd, 1, 0x40); // 256 bytes

HAL_PCDEx_SetTxFiFo(&hpcd, 2, 0x10); // 64 bytes

Tsuneo

thom_as
Associate II
Posted on June 13, 2016 at 09:37

Thank you for the reply.

1) Does the CCID interface descriptor declare three endpoints? I think it's good

Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x00 bInterfaceNumber
0x00 bAlternateSetting
0x03 bNumEndPoints
0x0B bInterfaceClass (Smart Card Device Class)
0x00 bInterfaceSubClass 
0x00 bInterfaceProtocol 
0x05 iInterface 
''SCR Interface''
//<- Is it important?
Endpoint Descriptor:
 ------------------------------
 0x07 bLength
 0x05 bDescriptorType
 0x81 bEndpointAddress (IN Endpoint)
 0x02 bmAttributes (Transfer: Bulk / Synch: None / Usage: Data)
 0x0040 wMaxPacketSize (64 Bytes) 
 0x00 bInterval
 
 Endpoint Descriptor:
 ------------------------------
 0x07 bLength
 0x05 bDescriptorType
 0x01 bEndpointAddress (OUT Endpoint)
 0x02 bmAttributes (Transfer: Bulk / Synch: None / Usage: Data)
 0x0040 wMaxPacketSize (64 Bytes) 
 0x00 bInterval
 
 Endpoint Descriptor:
 ------------------------------
 0x07 bLength
 0x05 bDescriptorType
 0x82 bEndpointAddress (IN Endpoint)
 0x03 bmAttributes (Transfer: Interrupt / Synch: None / Usage: Data)
 0x0008 wMaxPacketSize (8 Bytes) 
 0x18 bInterval

2) HAL_PCDEx_SetTxFiFo() has a couple of restrictions. - order are respected - minimum size is ok - but RAM size exceeded! I took your values but it still don't work By the way, on the computer I'm using Windows with the default CCID driver (WUDFUsbccidDriver.dll). I'm installing debian to check this with PCSC-lite and another CCID driver