cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 USB configuration problem

rafflex290
Associate II
Posted on September 26, 2014 at 11:18

Hi Guys,

Im currently try to implement a USB. The programm is

derived

from the CDC example. It is already working with 3 enpoint like in the CDC example. But I want only to work with 2 endpoint but when I configured it I get always a set configuration error when a want to communicate with the stm here a the configuration with 3 endpoints: usb_desc.c

const
uint8_t Virtual_Com_Port_DeviceDescriptor[] =
{
0x12, 
/* bLength */
USB_DEVICE_DESCRIPTOR_TYPE, 
/* bDescriptorType */
0x00,
0x02, 
/* bcdUSB = 2.00 */
0xff, 
/* Class: Vendor specific */
0x00, 
/* bDeviceSubClass */
0x00, 
/* bDeviceProtocol */
0x40, 
/* bMaxPacketSize0 */
0x83,
0x04, 
/* idVendor = 0x0483 */
0x01,
0xf0, 
/* idProduct = 0xf001 */
0x00,
0x01, 
/* bcdDevice = 2.00 */
1, 
/* Index of string descriptor describing manufacturer */
2, 
/* Index of string descriptor describing product */
3, 
/* Index of string descriptor describing the device's serial number */
0x01 
/* bNumConfigurations */
};
const
uint8_t Virtual_Com_Port_ConfigDescriptor[] =
{
/*Configuation Descriptor*/
0x09, 
/* bLength: Configuation Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, 
/* bDescriptorType: Configuration */
VIRTUAL_COM_PORT_SIZ_CONFIG_DESC, 
/* wTotalLength:no of returned bytes */
0x00,
0x01, 
/* bNumInterfaces: 1 interface */
0x01, 
/* bConfigurationValue: Configuration value */
0x00, 
/* iConfiguration: Index of string descriptor describing the configuration */
0x80, 
/* bmAttributes: Bus powered */
500/2, 
/* MaxPower 0 mA */
/*Data class interface descriptor*/
0x09, 
/* bLength: Endpoint Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE, 
/* bDescriptorType: */
0x00, 
/* bInterfaceNumber: Number of Interface */
0x00, 
/* bAlternateSetting: Alternate setting */
0x03, 
/* bNumEndpoints: 3 endpoints used */
0xff, 
/* bInterfaceClass: ??? */
0x00, 
/* bInterfaceSubClass: */
0x00, 
/* bInterfaceProtocol: */
0x00, 
/* iInterface: */
/*Endpoint 1 Descriptor*/
0x07, 
/* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, 
/* bDescriptorType: Endpoint */
0x81, 
/* bEndpointAddress: (IN1) */
0x02, 
/* bmAttributes: Bulk */
VIRTUAL_COM_PORT_DATA_SIZE, 
/* wMaxPacketSize: */
0x00,
0x00, 
/* bInterval */
/*Endpoint 2 Descriptor*/
0x07, 
/* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, 
/* bDescriptorType: Endpoint */
0x02, 
/* bEndpointAddress: (OUT2) */
0x02, 
/* bmAttributes: Bulk */
VIRTUAL_COM_PORT_DATA_SIZE, 
/* wMaxPacketSize: */
0x00,
0x00, 
/* bInterval: ignore for Bulk transfer */
/*Endpoint32 Descriptor*/
0x07, 
/* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, 
/* bDescriptorType: Endpoint */
0x03, 
/* bEndpointAddress: (OUT3) */
0x02, 
/* bmAttributes: Bulk */
VIRTUAL_COM_PORT_DATA_SIZE, 
/* wMaxPacketSize: */
0x00,
0x00 
/* bInterval: ignore for Bulk transfer */
};

usb_config.h

#define EP_NUM (4) //+EP0
 /*-------------------------------------------------------------*/
 /* -------------- Buffer Description Table -----------------*/
 /*-------------------------------------------------------------*/
 /* buffer table base address */
 /* buffer table base address */
 #define BTABLE_ADDRESS (0x00)
 /* EP0 */
 /* rx/tx buffer base address */
 #define ENDP0_RXADDR (0x40)
 #define ENDP0_TXADDR (0x80)
 /* EP1 */
 /* tx buffer base address */
 #define ENDP1_TXADDR (0xC0)
 #define ENDP2_RXADDR (0x100) 

usb_prop.c

void
Virtual_Com_Port_Reset(
void
)
{
/* Set Virtual_Com_Port DEVICE as not configured */
pInformation->Current_Configuration = 0;
/* Current Feature initialization */
pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];
/* Set Virtual_Com_Port DEVICE with the default Interface*/
pInformation->Current_Interface = 0;
SetBTABLE(BTABLE_ADDRESS);
/* Initialize Endpoint 0 */
SetEPType(ENDP0, EP_CONTROL);
SetEPTxStatus(ENDP0, EP_TX_STALL);
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
Clear_Status_Out(ENDP0);
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
SetEPRxValid(ENDP0);
/* Initialize Endpoint 1 */
SetEPType(ENDP1, EP_BULK);
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
SetEPTxStatus(ENDP1, EP_TX_NAK);
SetEPRxStatus(ENDP1, EP_RX_DIS);
/* pre-fill a packet. */
USB_SIL_Write(ENDP1,(uint8_t *)
''TEST''
, 4);
SetEPTxValid(ENDP1);
/* Initialize Endpoint 2 */
SetEPType(ENDP2, EP_BULK);
SetEPRxAddr(ENDP2, ENDP2_RXADDR);
SetEPTxStatus(ENDP2, EP_TX_DIS);
SetEPRxStatus(ENDP2, EP_RX_VALID);
SetEPRxCount(ENDP2, VIRTUAL_COM_PORT_DATA_SIZE);
/* Set this device to response on default address */
SetDeviceAddress(0);
bDeviceState = ATTACHED;
}

usb_endp.c

/*******************************************************************************
* Function Name : EP1_IN_Callback
* Description :
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void
EP1_IN_Callback (
void
)
{
SetEPTxValid(ENDP1);
}
/*******************************************************************************
* Function Name : EP2_OUT_Callback
* Description :
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void
EP2_OUT_Callback(
void
)
{
packet_receive = 1;
Receive_length = GetEPRxCount(ENDP2);
PMAToUserBufferCopy((unsigned 
char
*)Receive_Buffer, ENDP2_RXADDR, Receive_length);
SetEPRxValid(ENDP2);
}

and the 2 endpoint config I just modify usb_desc.c and usb_conf.h usb_desc.c

const
uint8_t Virtual_Com_Port_ConfigDescriptor[] =
{
/*Configuation Descriptor*/
0x09, 
/* bLength: Configuation Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, 
/* bDescriptorType: Configuration */
VIRTUAL_COM_PORT_SIZ_CONFIG_DESC, 
/* wTotalLength:no of returned bytes */
0x00,
0x01, 
/* bNumInterfaces: 1 interface */
0x01, 
/* bConfigurationValue: Configuration value */
0x00, 
/* iConfiguration: Index of string descriptor describing the configuration */
0x80, 
/* bmAttributes: Bus powered */
500/2, 
/* MaxPower 0 mA */
/*Data class interface descriptor*/
0x09, 
/* bLength: Endpoint Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE, 
/* bDescriptorType: */
0x00, 
/* bInterfaceNumber: Number of Interface */
0x00, 
/* bAlternateSetting: Alternate setting */
0x02, 
/* bNumEndpoints: 3 endpoints used */
0xff, 
/* bInterfaceClass: ??? */
0x00, 
/* bInterfaceSubClass: */
0x00, 
/* bInterfaceProtocol: */
0x00, 
/* iInterface: */
/*Endpoint 1 Descriptor*/
0x07, 
/* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, 
/* bDescriptorType: Endpoint */
0x81, 
/* bEndpointAddress: (IN1) */
0x02, 
/* bmAttributes: Bulk */
VIRTUAL_COM_PORT_DATA_SIZE, 
/* wMaxPacketSize: */
0x00,
0x00, 
/* bInterval */
/*Endpoint 2 Descriptor*/
0x07, 
/* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, 
/* bDescriptorType: Endpoint */
0x02, 
/* bEndpointAddress: (OUT2) */
0x02, 
/* bmAttributes: Bulk */
VIRTUAL_COM_PORT_DATA_SIZE, 
/* wMaxPacketSize: */
0x00,
0x00 
/* bInterval: ignore for Bulk transfer */
};

usb_conf.h

#define EP_NUM (3) //+EP0

Does anybody know how to solve the problem so I can just use 2 endpoint or anybody knows why this error happend? Thanks in advance
10 REPLIES 10
chen
Associate II
Posted on October 01, 2014 at 16:29

''But I

learned

alot from my ''stupid'' trials so I think thats good''

Well, if it works for you - OK then.

Bear in mind, most people who learn in an unstructured way and learn it is a hap hazard way - end up coding in the same way. They then wonder why it is really difficult to debug and get something going.

ST have provided examples of 4/5 USB device types. This is a good place to start : just understand what a USB device is and how to add/modify enough code to get it to work or do something different.

Once, you have tried 2 devices, you will start to understand what I mean by the 'layers' and how ST have partitioned the code into layers to make it easier to understand and work with