Hi,
I am trying to implement the usb on imxrt1050 to connect to the vendor server. My usb descriptor is set up as vendor specific class 0xFF, subclass 0x00, protocol 0x00. There is only 1 endpoint1 as Bulk out transfer 0x02 receiver. Currently, I tried to use usb msc example from sdk, I could get the usb connect to the server by correct device descriptor. However, I can not get the data that is sent from the server. Please guide me any example or what do I need to do to get it work. Thank you.
Hi Phuong Ly,
Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
I'd like to know the more background information, so I was wondering if you introduce what modification you did about the MSC demo which is from the SDK library, in addition, the testing process.
Then I can replicate the phenomenon on my site.
Looking forward to your reply.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hello Jeremy,
Thank you for responding my email. This is the first time I learn and work on USB. There is a lot of things that I have no clue ☹. Here is this my configuration descriptor that I need to config. I need to receive the big data is send from the vendor server to usb
USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
uint8_t g_UsbDeviceConfigurationDescriptor[] = {
9U, // bLength;
2U, // bDescriptorType;
USB_SHORT_GET_LOW(99799), // wTotalLength
USB_SHORT_GET_HIGH(99799),
2U, // bNumInterfaces
1U, // bConfigurationValue
0U, // iConfiguration
0x80U, // bmAttributes
50U, // bMaxPower
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9U, // bLength
4U, // bDescriptorType
0U, // bInterfaceNumber
0U, // bAlternateSetting
1U, // bNumEndpoints
0xffU, // bInterfaceClass (Vendor specific)
0x00U, // bInterfaceSubClass
0x00U, // bInterfaceProtocol
0U, // iInterface
// endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
7U, // bLength
5U, // bDescriptorType
1U, // bEndpointAddress
0x02U, // bmAttributes (0x02=bulk)
64U, 0U, // wMaxPacketSize
0U, // bInterval
// interface descriptor, DFU Mode (DFU spec Table 4.4)
9U, // bLength
4U, // bDescriptorType
1U, // bInterfaceNumber
0U, // bAlternateSetting
0U, // bNumEndpoints
0xFEU, // bInterfaceClass
0x01U, // bInterfaceSubClass
0x01U, // bInterfaceProtocol (Runtime)
4U, // iInterface
// DFU Functional Descriptor (DFU spec TAble 4.2)
9U, // bLength
0x21U, // bDescriptorType
0x0DU, // bmAttributes
USB_SHORT_GET_LOW(DFU_DETACH_TIMEOUT), // wDetachTimeOut
USB_SHORT_GET_HIGH(DFU_DETACH_TIMEOUT),
USB_SHORT_GET_LOW(DFU_TRANSFER_SIZE), // wTransferSize
USB_SHORT_GET_HIGH(DFU_TRANSFER_SIZE),
0x01,0x01, // bcdDFUVersion
};
I am using sdk of usb mcs lite example code. I removed some of Buld in and UFI configuration because I won’t need them. Right now I could connect my usb to the vendor server by correct device descriptor but that is it. When the server send data my usb response with broken pipe as picture (Data on the left is my working usb with broken pipe. Data on the right is support to be from vendor device).
In function USB_DeviceMscBulkOut(),my usb is always break in else case with
mscHandle->outEndpointStallFlag = 1;
mscHandle->inEndpointStallFlag = 1;
mscHandle->stallStatus = (uint8_t)USB_DEVICE_MSC_STALL_IN_CBW;
mscHandle->performResetRecover = 1;
So I tried to change these flags to 0 to make the usb is not in stall state. Please guide me how to set up this BullkOut function (which flags should I need to remove or keep)
I don’t understand how does the interrupt void USB_OTG1_IRQHandler(void) work?. For my code, it only trigger when those descriptors are setting up, but after that it is not at all.
Should I use the function USB_DeviceMscRecv() for receiving data ? what should I modify it?
Do I need to do any thing about pipe?
Thank you very much for trouble
Phuong
Hi Phuong Ly,
Thanks for your reply.
It makes me a bit confused, according to your statement, you just said you want to receive big data from the host.
However, you have not clarified what USB class device you want to implement, in further, I was wondering if you can introduce what modification you did about the MCS lite example code.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi Jeremy,
I actually did send you some modification on the last email.
I want to receive big data that is sent from the host. I want to implement usb vendor class 0xFF that has only one endpoint 1 as BULK_OUT. I only get the device control config on endpoint0 then I stuck. In the attachment file (captured by wireshark), the last BULK OUT response from usb is error when the host sends big data (1600 bytes). Then interrupt is stopped triggering after that. Here is my modified code and descriptors
USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
uint8_t g_UsbDeviceDescriptor[] = {
USB_DESCRIPTOR_LENGTH_DEVICE, /* Size of this descriptor in bytes */
USB_DESCRIPTOR_TYPE_DEVICE, /* DEVICE Descriptor Type */
USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION),
USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* USB Specification Release Number in
Binary-Coded Decimal (i.e., 2.10 is 210H). */
USB_DEVICE_CLASS, /* Class code 0x00 */
USB_DEVICE_SUBCLASS, /* Subclass code 0x00 */
USB_DEVICE_PROTOCOL, /* Protocol code 0x00 */
USB_CONTROL_MAX_PACKET_SIZE, /* Maximum packet size for endpoint zero is 64*/
USB_SHORT_GET_LOW(VENDOR_ID), USB_SHORT_GET_HIGH(VENDOR_ID), /* Vendor ID (assigned by the USB-IF) */
USB_SHORT_GET_LOW(PRODUCT_ID), USB_SHORT_GET_HIGH(PRODUCT_ID), /* Product ID (assigned by the manufacturer) */
USB_SHORT_GET_LOW(DEVICE_VER), USB_SHORT_GET_HIGH(DEVICE_VER), /* Device release number in binary-coded decimal */
0x01U, /* Index of string descriptor describing manufacturer */
0x02U, /* Index of string descriptor describing product */
0x03U, /* Index of string descriptor describing the device's serial number */
USB_CONFIGURE_COUNT, /* Number of possible configurations is 1 */
};
USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
uint8_t g_UsbDeviceConfigurationDescriptor[] = {
USB_DESCRIPTOR_LENGTH_CONFIGURE, /* Size of this descriptor in bytes 0x09*/
USB_DESCRIPTOR_TYPE_CONFIGURE, /* CONFIGURATION Descriptor Type 0x02*/
USB_SHORT_GET_LOW(CONFIG_DESC_SIZE ), /* CONFIG_DESC_SIZE 9 + 9 + 7 + 9 + 9*/
USB_SHORT_GET_HIGH(CONFIG_DESC_SIZE), /* Total length of data returned for this configuration. */
USB_MSC_INTERFACE_COUNT, /* Number of interfaces supported by this configuration is 2*/
USB_MSC_CONFIGURE_INDEX, /* Value to use as an argument to the SetConfiguration() request to select this configuration is 1*/
0U, /* Index of string descriptor describing this configuration */
(USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK) |
(USB_DEVICE_CONFIG_SELF_POWER << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_SHIFT) |
(USB_DEVICE_CONFIG_REMOTE_WAKEUP << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_SHIFT),
/* Configuration characteristics
D7: Reserved (set to one)
D6: Self-powered
D5: Remote Wakeup
D4...0: Reserved (reset to zero)
*/
USB_DEVICE_MAX_POWER, /* Maximum power consumption of the USB
device from the bus in this specific
configuration when the device is fully
operational. Expressed in 2 mA units
(i.e., 50 = 100 mA).
*/
USB_DESCRIPTOR_LENGTH_INTERFACE, /* Size of this descriptor in bytes 0x09 */
USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type 0x04*/
USB_MSC_INTERFACE_INDEX, /* Number of this interface 0x00 */
0x00U, /* Value used to select this alternate setting
for the interface identified in the prior field */
USB_MSC_ENDPOINT_COUNT, /* Number of endpoints used by this interface (excluding endpoint zero) is 0x01 */
VENDOR_SPEC_CLASS, /* Class code 0xFF */
0, /* Subclass code (assigned by the USB-IF). */
0, /* Protocol code (assigned by the USB). */
0x00U, /* Index of string descriptor describing this interface */
USB_DESCRIPTOR_LENGTH_ENDPOINT, /* Size of this descriptor in bytes 0x07 */
USB_DESCRIPTOR_TYPE_ENDPOINT, /* ENDPOINT Descriptor Type 0x01 */
USB_MSC_BULK_OUT_ENDPOINT| (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), /* The address of the endpoint on the USB device
//described by this descriptor. */
USB_ENDPOINT_BULK, /* This field describes the endpoint's attributes */
USB_SHORT_GET_LOW(FS_MSC_BULK_OUT_PACKET_SIZE), /*size is 64 */
USB_SHORT_GET_HIGH(FS_MSC_BULK_OUT_PACKET_SIZE),
0x00U, /Useless for bulk in endpoint/
// interface descriptor, DFU Mode (DFU spec Table 4.4)
9, // bLength
4, // bDescriptorType
DFU_INTERFACE, // bInterfaceNumber
0, // bAlternateSetting
0, // bNumEndpoints
0xFE, // bInterfaceClass
0x01, // bInterfaceSubClass
0x01, // bInterfaceProtocol (Runtime)
4, // iInterface
// DFU Functional Descriptor (DFU spec TAble 4.2)
9, // bLength
0x21, // bDescriptorType
0x0D, // bmAttributes
USB_SHORT_GET_LOW(DFU_DETACH_TIMEOUT), // wDetachTimeOut
USB_SHORT_GET_HIGH(DFU_DETACH_TIMEOUT),
USB_SHORT_GET_LOW(DFU_TRANSFER_SIZE), // wTransferSize
USB_SHORT_GET_HIGH(DFU_TRANSFER_SIZE),
0x01,0x01, // bcdDFUVersion
};
In function USB_DeviceMscBulkOut(), comment
if (!mscHandle->transferRemaining)
{
mscHandle->dataOutFlag = 0;
{
// USB_DeviceSendRequest(g_msc.deviceHandle, mscHandle->bulkInEndpoint, (uint8_t *)mscHandle->mscCsw,
// USB_DEVICE_MSC_CSW_LENGTH);
//increase the size USB_DEVICE_MSC_CSW_LENGTH from 31 to 64
USB_DeviceSendRequest(g_msc.deviceHandle, mscHandle->bulkInEndpoint, (uint8_t *)mscHandle->mscCsw,
64);
mscHandle->cswPrimeFlag = 1;
}
}
// else if ((mscHandle->cbwValidFlag) && (event->length == USB_DEVICE_MSC_CBW_LENGTH) &&
// (mscHandle->mscCbw->signature == USB_DEVICE_MSC_DCBWSIGNATURE) &&
// (!((mscHandle->mscCbw->logicalUnitNumber & 0xF0) || (mscHandle->mscCbw->cbLength & 0xE0))) &&
// (mscHandle->mscCbw->logicalUnitNumber < (mscHandle->logicalUnitNumber + 1)) &&
// ((mscHandle->mscCbw->cbLength >= 0x01) && (mscHandle->mscCbw->cbLength <= 0x10)))
// {
//put the code below instead.
else if ((mscHandle->cbwValidFlag) && (event->length == 64))
{
……
}
//comment out error = USB_DeviceMscProcessUfiCommand(mscHandle); //make it return success
//comment out
// if (!((mscHandle->dataOutFlag) || ((mscHandle->dataInFlag) || (mscHandle->needInStallFlag))))
// {
// USB_DeviceSendRequest(g_msc.deviceHandle, mscHandle->bulkInEndpoint, (uint8_t *)mscHandle->mscCsw,
// USB_DEVICE_MSC_CSW_LENGTH);
// mscHandle->cswPrimeFlag = 1;
// }
In function USB_DeviceMscEndpointsInit(), comment out
// epCallback.callbackFn = USB_DeviceMscBulkIn; //phuong
// epCallback.callbackParam = (void *)&g_msc.mscStruct;
//
// epInitStruct.zlt = 0;
// epInitStruct.transferType = USB_ENDPOINT_BULK;
// epInitStruct.endpointAddress =
// USB_MSC_BULK_IN_ENDPOINT | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
// g_mscHandle->bulkInEndpoint = epInitStruct.endpointAddress;
// if (USB_SPEED_HIGH == g_msc.speed)
// {
// epInitStruct.maxPacketSize = HS_MSC_BULK_IN_PACKET_SIZE;
// }
// else
// {
// epInitStruct.maxPacketSize = FS_MSC_BULK_IN_PACKET_SIZE;
// }
//
// USB_DeviceInitEndpoint(g_msc.deviceHandle, &epInitStruct, &epCallback);
In function USB_DeviceCallback()
case kUSB_DeviceEventSetConfiguration:
if (g_mscHandle->configuration == *temp8)
{
break;
}
if (g_mscHandle->configuration)
{
USB_DeviceMscEndpointsDeinit();
}
g_mscHandle->configuration = *temp8;
if (USB_MSC_CONFIGURE_INDEX == (*temp8))
{
/USB_DeviceMscEndpointsDeinit();/
error = USB_DeviceMscEndpointsInit();
// USB_DeviceRecvRequest(g_msc.deviceHandle, g_mscHandle->bulkOutEndpoint, (uint8_t *)g_mscHandle->mscCbw,
// USB_DEVICE_MSC_CBW_LENGTH);
USB_DeviceRecvRequest(g_msc.deviceHandle, g_mscHandle->bulkOutEndpoint, (uint8_t *)g_mscHandle->mscCbw,
64); //phuong
g_mscHandle->cbwPrimeFlag = 1;
g_msc.attach = 1;
}
break;
In function USB_DeviceApplicationInit()
// ufi->requestSense = &g_requestSense;
// ufi->readCapacity = &g_readCapacity;
// ufi->readCapacity16 = &g_readCapacity16;
// ufi->formatCapacityData = &g_formatCapacityData[0];
//
// ufi->requestSense->validErrorCode = USB_DEVICE_MSC_UFI_REQ_SENSE_VALID_ERROR_CODE;
// ufi->requestSense->additionalSenseLength = USB_DEVICE_MSC_UFI_REQ_SENSE_ADDITIONAL_SENSE_LEN;
// ufi->requestSense->senseKey = USB_DEVICE_MSC_UFI_NO_SENSE;
// ufi->requestSense->additionalSenseCode = USusbB_DEVICE_MSC_UFI_NO_SENSE;
// ufi->requestSense->additionalSenseQualifer = USB_DEVICE_MSC_UFI_NO_SENSE;
//
// ufi->readCapacity->lastLogicalBlockAddress = USB_LONG_TO_BIG_ENDIAN(g_mscHandle->totalLogicalBlockNumber - 1);
// ufi->readCapacity->blockSize = USB_LONG_TO_BIG_ENDIAN((uint32_t)g_mscHandle->lengthOfEachLba);
// ufi->readCapacity16->lastLogicalBlockAddress1 = USB_LONG_TO_BIG_ENDIAN(g_mscHandle->totalLogicalBlockNumber - 1);
// ufi->readCapacity16->blockSize = USB_LONG_TO_BIG_ENDIAN((uint32_t)g_mscHandle->lengthOfEachLba);
// by phuong
I know there is a lot of flag of mscHandle that I don’t need that should be removed. However, there were so many of them tangle together that I don’t understand clearly their purpose. Please give me suggestion.
Thank you very much
Phuong
Hi Phuong Ly,
Thanks for your reply.
According to your reply, I guess you would like to create a DFU class device base on MSC demo, however, it doesn't well, is it right?
In further, after a review of attachment, I don't find the process of enumeration, I was wondering if you can share it.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------