STM32F1 custom USB
Posted: Mon Jun 29, 2015 9:02 am
Hi,
I try run USB as Vendor specific with libUSB driver.
At this moment, device it's correct detected in system, but I can't receive from host any data.
My code it's look that:
usbDataReceived look's that:
So, when I try send some information, then LED should be turn on, but this isn't happening.
I must activation EndPoint or something that?
I want transfer simple information like some short strings.
I try run USB as Vendor specific with libUSB driver.
At this moment, device it's correct detected in system, but I can't receive from host any data.
My code it's look that:
Code: Select all
#define USBD1_DATA_REQUEST_EP1 0x01
#define USBD1_DATA_REQUEST_EP2 0x02
/*
* USB Device Descriptor.
*/
static const uint8_t device_descriptor_data[18] = {
USB_DESC_DEVICE(
0x0110, /* bcdUSB (1.1). */
0xFF, /* bDeviceClass (custom). */
0x00, /* bDeviceSubClass. */
0x00, /* bDeviceProtocol. */
0x40, /* bMaxPacketSize. */
0x0483, /* idVendor (ST). */
0x5750, /* idProduct. */
0x0100, /* bcdDevice. */
1, /* iManufacturer. */
2, /* iProduct. */
3, /* iSerialNumber. */
1) /* bNumConfigurations. */
};
/*
* Device Descriptor wrapper.
*/
static const USBDescriptor device_descriptor = {
sizeof device_descriptor_data,
device_descriptor_data
};
/* Configuration Descriptor tree*/
static const uint8_t configuration_descriptor_data[32] = {
/* Configuration Descriptor.*/
USB_DESC_CONFIGURATION( // 8
32, /* wTotalLength. */
0x01, /* bNumInterfaces. */
0x01, /* bConfigurationValue. */
0, /* iConfiguration. */
0xC0, /* bmAttributes (self powered). */
200), /* bMaxPower (400mA). */
/* Interface Descriptor.*/
USB_DESC_INTERFACE( // 9
0x00, /* bInterfaceNumber. */
0x00, /* bAlternateSetting. */
0x02, /* bNumEndpoints. */
0xFF, /* bInterfaceClass (Vendor Specific). */
0x00, /* bInterfaceSubClass */
0x00, /* bInterfaceProtocol */
0), /* iInterface. */
/* Endpoint 3 Descriptor.*/
USB_DESC_ENDPOINT( // 7
USBD1_DATA_REQUEST_EP1, /* bEndpointAddress.*/
0x02, /* bmAttributes (Bulk). */
0x0040, /* wMaxPacketSize. */
0x00), /* bInterval. */
/* Endpoint 1 Descriptor.*/
USB_DESC_ENDPOINT( // 7
USBD1_DATA_REQUEST_EP2, /* bEndpointAddress.*/
0x02, /* bmAttributes (Bulk). */
0x0040, /* wMaxPacketSize. */
0x00) /* bInterval. */
};
/*
* Configuration Descriptor wrapper.
*/
static const USBDescriptor configuration_descriptor = {
sizeof configuration_descriptor_data,
configuration_descriptor_data
};
/*
* U.S. English language identifier.
*/
static const uint8_t usb_string0[] = {
USB_DESC_BYTE(4), /* bLength. */
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
USB_DESC_WORD(0x0409) /* wLANGID (U.S. English). */
};
/*
* Vendor string.
*/
static const uint8_t usb_string1[] = {
USB_DESC_BYTE(12), /* bLength. */
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
'S', 0, 'T', 0, 'O', 0, 'R', 0, 'K', 0,
};
/*
* Device Description string.
*/
static const uint8_t usb_string2[] = {
USB_DESC_BYTE(14), /* bLength. */
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
'D', 0, 'E', 0, 'V', 0, 'I', 0, 'C', 0, 'E', 0,
};
/*
* Serial Number string.
*/
static const uint8_t usb_string3[] = {
USB_DESC_BYTE(8), /* bLength. */
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
'0' + CH_KERNEL_MAJOR, 0,
'0' + CH_KERNEL_MINOR, 0,
'0' + CH_KERNEL_PATCH, 0,
};
/*
* Strings wrappers array.
*/
static const USBDescriptor usb_strings[] = {
{sizeof usb_string0, usb_string0},
{sizeof usb_string1, usb_string1},
{sizeof usb_string2, usb_string2},
{sizeof usb_string3, usb_string3}
};
/*
* Handles the GET_DESCRIPTOR callback. All required descriptors must be
* handled here.
*/
static const USBDescriptor *get_descriptor(USBDriver *usbp,
uint8_t dtype,
uint8_t dindex,
uint16_t lang) {
(void)usbp;
(void)lang;
switch (dtype)
{
case USB_DESCRIPTOR_DEVICE:
return &device_descriptor;
case USB_DESCRIPTOR_CONFIGURATION:
return &configuration_descriptor;
case USB_DESCRIPTOR_STRING:
if (dindex < 4)
return &usb_strings[dindex];
}
return NULL;
}
/**
* @brief IN EP1 state.
*/
static USBInEndpointState ep1instate;
/**
* @brief OUT EP1 state.
*/
static USBOutEndpointState ep1outstate;
/**
* @brief EP1 initialization structure (both IN and OUT).
*/
static const USBEndpointConfig ep1config = {
USB_EP_MODE_TYPE_BULK,
NULL,
sduDataTransmitted,
usbDataReceived,
0x0040,
0x0040,
&ep1instate,
&ep1outstate,
2,
NULL
};
/**
* @brief OUT EP2 state.
*/
static USBOutEndpointState ep2outstate;
/**
* @brief EP2 initialization structure (IN only).
*/
static const USBEndpointConfig ep2config = {
USB_EP_MODE_TYPE_BULK,
NULL,
NULL,
usbDataReceived,
0x0000,
0x0040,
NULL,
&ep2outstate,
2,
NULL
};
/*
* Handles the USB driver global events.
*/
static void usb_event(USBDriver *usbp, usbevent_t event)
{
switch (event)
{
case USB_EVENT_RESET:
return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
chSysLockFromIsr();
usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP1, &ep1config);
usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP2, &ep2config);
chSysUnlockFromIsr();
return;
case USB_EVENT_SUSPEND:
return;
case USB_EVENT_WAKEUP:
return;
case USB_EVENT_STALLED:
return;
}
return;
}
/*
* USB driver configuration.
*/
static const USBConfig usbcfg = {
usb_event,
get_descriptor,
NULL,
NULL
};usbDataReceived look's that:
Code: Select all
void usbDataReceived(USBDriver *usbp, usbep_t ep)
{
LED_red_ON;
}So, when I try send some information, then LED should be turn on, but this isn't happening.
I must activation EndPoint or something that?
I want transfer simple information like some short strings.