Page 1 of 1

RNDIS or NCM with ESP32-S2 (Tinyusb)

Posted: Mon Aug 22, 2022 9:55 pm
by kino0924
Hi,

I am trying to implement Ethernet over USB so I can control my board with TCP/IP
I am going to connect from Windows machine so I thought RNDIS or NCM will be suitable.

I followed lots of Tinyusb example as well as ESP-IDF's implementation.

So, I created following code for to create USB Ethernet first but Windows is saying that its "This device cannot start. (Code 10)"
I also did pretty same implementation for ECM, just changing define and configuration_descriptor but no good

I am using VSCode + ESP-IDF v5.0-beta1

Can someone tell me what am I doing wrong?


Thank you.
  1. #define CFG_TUD_ECM_RNDIS     1
  2.  
  3. #include <stdlib.h>
  4. #include "esp_log.h"
  5. #include "driver/gpio.h"
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8. #include "tinyusb.h"
  9. #include "sdkconfig.h"
  10. #include "class/net/net_device.h"
  11.  
  12. static const char *TAG = "example";
  13.  
  14.  
  15. #define MAIN_CONFIG_TOTAL_LEN    (TUD_CONFIG_DESC_LEN + TUD_RNDIS_DESC_LEN)
  16. #define ALT_CONFIG_TOTAL_LEN     (TUD_CONFIG_DESC_LEN + TUD_CDC_ECM_DESC_LEN)
  17. #define NCM_CONFIG_TOTAL_LEN     (TUD_CONFIG_DESC_LEN + TUD_CDC_NCM_DESC_LEN)
  18.  
  19. #define EPNUM_NET_NOTIF   0x81
  20. #define EPNUM_NET_OUT     0x02
  21. #define EPNUM_NET_IN      0x82
  22.  
  23. // String Descriptor Index
  24. enum
  25. {
  26.   STRID_LANGID = 0,
  27.   STRID_MANUFACTURER,
  28.   STRID_PRODUCT,
  29.   STRID_SERIAL,
  30.   STRID_INTERFACE,
  31.   STRID_MAC
  32. };
  33.  
  34. enum
  35. {
  36.   ITF_NUM_CDC = 0,
  37.   ITF_NUM_CDC_DATA,
  38.   ITF_NUM_TOTAL
  39. };
  40.  
  41. enum
  42. {
  43.   CONFIG_ID_RNDIS = 0,
  44.   CONFIG_ID_COUNT
  45. };
  46.  
  47. tusb_desc_device_t const desc_device =
  48. {
  49.     .bLength            = sizeof(tusb_desc_device_t),
  50.     .bDescriptorType    = TUSB_DESC_DEVICE,
  51.     .bcdUSB             = 0x0200,
  52.  
  53.     // Use Interface Association Descriptor (IAD) device class
  54.     .bDeviceClass       = TUSB_CLASS_MISC,
  55.     .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
  56.     .bDeviceProtocol    = MISC_PROTOCOL_IAD,
  57.    
  58.     .bMaxPacketSize0    = CFG_TUD_ENDPOINT0_SIZE,
  59.  
  60.     .idVendor           = 0x1234,
  61.     .idProduct          = 0x5678,
  62.     .bcdDevice          = 0x0101,
  63.  
  64.     .iManufacturer      = STRID_MANUFACTURER,
  65.     .iProduct           = STRID_PRODUCT,
  66.     .iSerialNumber      = STRID_SERIAL,
  67.  
  68.     .bNumConfigurations = CONFIG_ID_COUNT // multiple configurations
  69. };
  70.  
  71. tusb_desc_strarray_device_t my_string_descriptor = {
  72.     [STRID_LANGID]       = (const char[]) { 0x09, 0x04 }, // supported language is English (0x0409)
  73.     [STRID_MANUFACTURER] = "TinyUSB",                     // Manufacturer
  74.     [STRID_PRODUCT]      = "TinyUSB Device",              // Product
  75.     [STRID_SERIAL]       = "123456",                      // Serial
  76.     [STRID_INTERFACE]    = "TinyUSB Network Interface"    // Interface Description
  77. };
  78.  
  79. uint8_t const * tud_rndis_descriptor_device_cb(void)
  80. {
  81.   return (uint8_t const *) &desc_device;
  82. }
  83.  
  84. static uint8_t const rndis_configuration[] =
  85. {
  86.   // Config number (index+1), interface count, string index, total length, attribute, power in mA
  87.   TUD_CONFIG_DESCRIPTOR(CONFIG_ID_RNDIS+1, ITF_NUM_TOTAL, 0, MAIN_CONFIG_TOTAL_LEN, 0, 100),
  88.  
  89.   // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
  90.   TUD_RNDIS_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, EPNUM_NET_NOTIF, 8, EPNUM_NET_OUT, EPNUM_NET_IN, CFG_TUD_NET_ENDPOINT_SIZE),
  91. };
  92.  
  93.  
  94. void app_main(void)
  95. {
  96.     ESP_LOGI(TAG, "USB initialization");
  97.  
  98.     const tinyusb_config_t tusb_cfg = {
  99.         .descriptor = &desc_device,
  100.         .string_descriptor = my_string_descriptor,
  101.         .external_phy = false,
  102.         .configuration_descriptor = rndis_configuration,
  103.     };
  104.  
  105.  
  106.     ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
  107.     ESP_LOGI(TAG, "USB initialization DONE");
  108. }
  1.  
  2.     =========================== USB Port13 ===========================
  3.  
  4. Connection Status        : 0x00 (No device is connected)
  5. Port Chain               : 2-13
  6. Properties               : 0x01
  7.  IsUserConnectable       : yes
  8.  PortIsDebugCapable      : no
  9.  PortHasMultiCompanions  : no
  10.  PortConnectorIsTypeC    : no
  11. ConnectionIndex          : 0x0D (Port 13)
  12. CompanionIndex           : 0
  13.  CompanionHubSymLnk      : USB#ROOT_HUB30#5&178f6c5f&0&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
  14.  CompanionPortNumber     : 0x05 (Port 5)
  15.  -> CompanionPortChain   : 2-5
  16.  
  17.       ========================== Summary =========================
  18. Vendor ID                : 0x1234 (Micro Science Co., Ltd.)
  19. Product ID               : 0x5678
  20. USB Version              : 2.0 -> but Device is Full-Speed only
  21. Port maximum Speed       : High-Speed (Companion Port 2-5 supports SuperSpeed)
  22. Device maximum Speed     : Full-Speed
  23. Device Connection Speed  : Full-Speed
  24. Device Manager Problem   : 10 (CM_PROB_FAILED_START)
  25. Used Endpoints           : 1
  26.  
  27.       ======================== USB Device ========================
  28.  
  29.         +++++++++++++++++ Device Information ++++++++++++++++++
  30. Device Description       : USB Composite Device
  31. Device ID                : USB\VID_1234&PID_5678\123456
  32. Hardware IDs             : USB\VID_1234&PID_5678&REV_0101 USB\VID_1234&PID_5678
  33. Driver KeyName           : {36fc9e60-c465-11cf-8056-444553540000}\0011 (GUID_DEVCLASS_USB)
  34. Driver                   : \SystemRoot\System32\drivers\usbccgp.sys (Version: 10.0.22000.1  Date: 2021-06-05)
  35. Driver Inf               : C:\WINDOWS\inf\usb.inf
  36. Legacy BusType           : PNPBus
  37. Class                    : USB
  38. Class GUID               : {36fc9e60-c465-11cf-8056-444553540000} (GUID_DEVCLASS_USB)
  39. Service                  : usbccgp
  40. Enumerator               : USB
  41. PDO                      : \Device\USBPDO-3
  42. Location Info            : Port_#0013.Hub_#0001
  43. Manufacturer Info        : (Standard USB Host Controller)
  44. Capabilities             : 0x14 (Removable, UniqueID)
  45. Status                   : 0x01806400 (DN_HAS_PROBLEM, DN_DISABLEABLE, DN_REMOVABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER)
  46. Problem Code             : 10 (CM_PROB_FAILED_START)
  47. Address                  : 13
  48. HcDisableSelectiveSuspend: 0
  49. EnableSelectiveSuspend   : 0
  50. SelectiveSuspendEnabled  : 0
  51. EnhancedPowerMgmtEnabled : 0
  52. IdleInWorkingState       : 0
  53. WakeFromSleepState       : 0
  54. Power State              : D3 (supported: D0, D3, wake from D0)
  55.  
  56.         +++++++++++++++++ Registry USB Flags +++++++++++++++++
  57. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags\123456780101
  58.  osvc                    : REG_BINARY 00 00
  59.  
  60.         ---------------- Connection Information ---------------
  61. Connection Index         : 0x0D (Port 13)
  62. Connection Status        : 0x00 (NoDeviceConnected)
  63. Current Config Value     : 0x00 (Configuration 0)
  64. Device Address           : 0x30 (48)
  65. Is Hub                   : 0x00 (no)
  66. Device Bus Speed         : 0x01 (Full-Speed)
  67. Number Of Open Pipes     : 0x00 (0 pipes to data endpoints)
  68. Data (HexDump)           : 0D 00 00 00 12 01 00 02 EF 02 01 40 34 12 78 56   ...........@4.xV
  69.                            01 01 01 02 03 01 00 01 00 30 00 00 00 00 00 00   .........0......
  70.                            00 00 00                                          ...
  71.  
  72.         --------------- Connection Information V2 -------------
  73. Connection Index         : 0x0D (13)
  74. Length                   : 0x10 (16 bytes)
  75. SupportedUsbProtocols    : 0x03
  76.  Usb110                  : 1 (yes, port supports USB 1.1)
  77.  Usb200                  : 1 (yes, port supports USB 2.0)
  78.  Usb300                  : 0 (no, port not supports USB 3.0) -> but Companion Port 2-5 does
  79.  ReservedMBZ             : 0x00
  80. Flags                    : 0x00
  81.  DevIsOpAtSsOrHigher     : 0 (Device is not operating at SuperSpeed or higher)
  82.  DevIsSsCapOrHigher      : 0 (Device is not SuperSpeed capable or higher)
  83.  DevIsOpAtSsPlusOrHigher : 0 (Device is not operating at SuperSpeedPlus or higher)
  84.  DevIsSsPlusCapOrHigher  : 0 (Device is not SuperSpeedPlus capable or higher)
  85.  ReservedMBZ             : 0x00
  86. Data (HexDump)           : 0D 00 00 00 10 00 00 00 03 00 00 00 00 00 00 00   ................
  87.  
  88.     ---------------------- Device Descriptor ----------------------
  89. bLength                  : 0x12 (18 bytes)
  90. bDescriptorType          : 0x01 (Device Descriptor)
  91. bcdUSB                   : 0x200 (USB Version 2.0) -> but device is Full-Speed only
  92. bDeviceClass             : 0xEF (Miscellaneous)
  93. bDeviceSubClass          : 0x02
  94. bDeviceProtocol          : 0x01 (IAD - Interface Association Descriptor)
  95. bMaxPacketSize0          : 0x40 (64 bytes)
  96. idVendor                 : 0x1234 (Micro Science Co., Ltd.)
  97. idProduct                : 0x5678
  98. bcdDevice                : 0x0101
  99. iManufacturer            : 0x01 (String Descriptor 1)
  100. iProduct                 : 0x02 (String Descriptor 2)
  101. iSerialNumber            : 0x03 (String Descriptor 3)
  102. bNumConfigurations       : 0x01 (1 Configuration)
  103. Data (HexDump)           : 12 01 00 02 EF 02 01 40 34 12 78 56 01 01 01 02   .......@4.xV....
  104.                            03 01                                             ..
  105.  
  106.     ----------------- Device Qualifier Descriptor -----------------
  107. Error                    : ERROR_GEN_FAILURE  (because the device has problem code CM_PROB_FAILED_START)
  108.  
  109.       -------------------- String Descriptors -------------------
  110. String descriptors are not available  (because the device has problem code CM_PROB_FAILED_START)

Re: RNDIS or NCM with ESP32-S2 (Tinyusb)

Posted: Tue Aug 23, 2022 7:03 am
by chegewara