USB errors with LWIP USB Sample

cancel
Showing results for 
Search instead for 
Did you mean: 

USB errors with LWIP USB Sample

130 Views
Contributor I

I'm using MCUXpresso and an FRDMK66F board, I have imported the lwip_dhcp_usb_freertos code sample and made some alterations to suit my use case. When transferring ethernet frames via the USB RNDIS interface, I get USB errors if the frames are larger than around ~1250 bytes. I'm not sure exactly what size causes the error but frames of 1254 bytes definitely transfer OK, whereas I cannot successfully transfer frames of 1514 bytes (the typical maximum size for Ethernet, jumbo frames notwithstanding).

I have established the error is in the USB code in the sample, when large packets are attempted to be sent to FRDM-K66F from the Android phone it is tethered to the RNDIS USB event handler receives an event with event code 'kStatus_USB_TransferFailed'. In the USB Host EHCI code this status is set when the transfer status is checked against the EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK constant. I'm not a USB expert at all so I'm not sure where to proceed from here. I've already tried tweaking a few values in the USB HOST CONFIG such as increasing the value of USB_HOST_CONFIG_ENUMERATION_MAX_STALL_RETRIES, but not managed to make any difference to the issue in doing so.

Thanks in advance.

Tags (2)
0 Kudos
3 Replies

62 Views
Specialist V

Hi

You can also try the uTasker FRDM-K66F RNDIS host - there is a binary at this link:
https://www.utasker.com/kinetis/FRDM-K66F.html
which allows the board's HS host to be attached to memory sticks (and browse the file content) or to smart phones to use their tethered USB connections for Internet access.
Furthermore, devices connected on its Ethernet connection can use the Smart phone's gateway for Internet access or to communicate with the FRDM-K66s web or FTP servers, or to control the board via Telnet.
The application is available for any Kinetis with FS or HS USB and also on any i.MX RT part, but a HS USB is recommended.

With respect to your question: the following is the debug output of the reference when connecting to a certain smart phone, showing enumeration, RNDIS initialisation and then DHCP frames

USB HS device detected
USB device information ready:
USB2.0 device with 64 byte pipe
Vendor/Product = 0x12d1/0x108a
Manufacturer = "HUAWEI"
Product = "POT-LX1"
Serial Number = "39V4C2061600123"

Self-powered device with 2 interface(s)
Associated Interfaces = 2
Interface 0
2 = INTERRUPT with size 8 (interval = 32ms)
CDC (RNDIS) class
Interface 1
1 = BULK IN with size 512
1 = BULK OUT with size 512
CDC (RNDIS) class
Enumerated [1]
RNDIS Init
Device notification: REMOTE_NDIS_INITIALIZE_COMPLETE
Version = 1.1
ETHERNET type
Query: Device notification: REMOTE_NDIS_QUERY_COMPLETE
OIDs
00010101 = OID_GEN_SUPPORTED_LIST
00010102 = OID_GEN_HARDWARE_STATUS
00010103 = OID_GEN_MEDIA_SUPPORTED
00010104 = OID_GEN_MEDIA_IN_USE
00010106 = OID_GEN_MAXIMUM_FRAME_SIZE
00010107 = OID_GEN_LINK_SPEED
0001010a = OID_GEN_TRANSMIT_BLOCK_SIZE
0001010b = OID_GEN_RECEIVE_BLOCK_SIZE
0001010c = OID_GEN_VENDOR_ID
0001010d = OID_GEN_VENDOR_DESCRIPTION
00010116 = OID_GEN_VENDOR_DRIVER_VERSION
0001010e = OID_GEN_CURRENT_PACKET_FILTER
00010111 = OID_GEN_MAXIMUM_TOTAL_SIZE
00010114 = OID_GEN_MEDIA_CONNECT_STATUS
00010202 = Unknown
00020101 = OID_GEN_XMIT_OK
00020102 = OID_GEN_RCV_OK
00020103 = OID_GEN_XMIT_ERROR
00020104 = OID_GEN_RCV_ERROR
00020105 = OID_GEN_RCV_NO_BUFFER
01010101 = OID_802_3_PERMANENT_ADDRESS
01010102 = OID_802_3_CURRENT_ADDRESS
01010103 = OID_802_3_MULTICAST_LIST
01010105 = OID_802_3_MAC_OPTIONS
01010104 = OID_802_3_MAXIMUM_LIST_SIZE
01020101 = OID_802_3_RCV_ERROR_ALIGNMENT
01020102 = OID_802_3_XMIT_ONE_COLLISION
01020103 = OID_802_3_XMIT_MORE_COLLISIONS
Query: Device notification: RNDIS Status: Connected
Device notification: REMOTE_NDIS_QUERY_COMPLETE
OID 00010202 = Unknown received [0x00000000]
Query: Device notification: REMOTE_NDIS_QUERY_COMPLETE
OID 00010106 = OID_GEN_MAXIMUM_FRAME_SIZE received [0x000005dc]
Query: Device notification: REMOTE_NDIS_QUERY_COMPLETE
OID 00010107 = OID_GEN_LINK_SPEED received [0x00410000]
Query: Device notification: REMOTE_NDIS_QUERY_COMPLETE
OID 00010114 = OID_GEN_MEDIA_CONNECT_STATUS received [0x00000000]
Query: Device notification: REMOTE_NDIS_QUERY_COMPLETE
OID 01010102 = OID_802_3_CURRENT_ADDRESS received [ 0x02 0x03 0x39 0x51 0x37 0x46]
Query: Device notification: REMOTE_NDIS_QUERY_COMPLETE
OID 01010101 = OID_802_3_PERMANENT_ADDRESS received [ 0x02 0x03 0x39 0x51 0x37 0x46]
Query: Device notification: Set complete
Query: RNDIS->Eth:54-98
Device notification: Set complete
Query: Device notification: Set complete
Query: Device notification: REMOTE_NDIS_QUERY_COMPLETE
OID 00010111 = OID_GEN_MAXIMUM_TOTAL_SIZE received [0x00000616]
RNDIS initialisation complete
Starting DHCP
RNDIS operating
RNDIS->Eth:89-133
RNDIS->Eth:89-133
RNDIS->Eth:150-194
RNDIS->Eth:150-194
RNDIS->Eth:170-214
RNDIS->Eth:54-98
RNDIS->Eth:170-214
RNDIS->Eth:54-98
RNDIS->Eth:123-167
RNDIS->Eth:143-187
RNDIS->Eth:123-167
RNDIS->Eth:143-187
RNDIS->Eth:123-167
RNDIS->Eth:143-187
RNDIS->Eth:90-134
RNDIS->Eth:290-334
RNDIS->Eth:310-354
RNDIS->Eth:290-334
RNDIS->Eth:310-354
RNDIS->Eth:290-334
RNDIS->Eth:310-354
Stack->RNDIS:342-386
Stack->RNDIS:342-386
RNDIS->Stack->Eth:345-389
RNDIS->Stack->Eth:354-398
DHCP successful: 192.168.42.197

Note that during the initialisation the maximum frame size that the RNSID device can handle is reported in
OID 00010106 = OID_GEN_MAXIMUM_FRAME_SIZE received [0x000005dc] <--- 1500 bytes in this case, which is equal to the MTU of Ethernet

During subsequent operation (a PCC using it as gateway via Ethernet->RNDIS) the largest frames in any direction are:
Eth->RNDIS:1494:1538
RNDIS->Eth:1494-1538
which means that the RAW payload content is 1494 bytes in size, giving 1538 bytes on the USB bus (with the RNDIS header). This is symmetrical since the RNDIS data protocol is the same in both directions.

I think that you need to respect the MTU value reported and fragment any IP traffic that exceeds this to be able to operate correctly. Jumbo frames, for example, may work on Ethernet but can't pass via RNDIS unless packed into multiple IP fragments according to standard IP strategy.

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]

P.S: I just posted this using a PC connected to my FRDM-K66F's Ethernet interface and using the above HUAWEI smart phone as tethered connection via USB

63 Views
NXP TechSupport
NXP TechSupport

Also you should make sure the data length your device send is less than( <= ) 1518,     1518 is the real data size on the usb bus.

0 Kudos

64 Views
NXP TechSupport
NXP TechSupport

Hi Tom:

 

According to middleware/lwip/port/usb_ethernetif.h

#define RNDIS_DATA_MESSAGE (RNDIS_FRAME_MAX_FRAMELEN + RNDIS_DAT_MSG_HEADER_SIZE + 1)

The max frame length should be 1518.

 

Could you please let me know how to reproduce your issue with Frdm-k66 board?

 

There is a bare metal version of lwip_dhcp_usb demo,  did you try this demo? the same result?

 

Regards

Daniel

0 Kudos