usb_config.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "sdkconfig.h"
  8. #include "esp_rom_sys.h"
  9. #include "esp_attr.h"
  10. /* ================ USB common Configuration ================ */
  11. #define CONFIG_USB_PRINTF(...) esp_rom_printf(__VA_ARGS__)
  12. #ifndef CONFIG_USB_DBG_LEVEL
  13. #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
  14. #endif
  15. /* Enable print with color */
  16. #define CONFIG_USB_PRINTF_COLOR_ENABLE
  17. /* data align size when use dma or use dcache */
  18. #ifndef CONFIG_USB_ALIGN_SIZE
  19. #define CONFIG_USB_ALIGN_SIZE 4
  20. #endif
  21. // #define CONFIG_USB_DCACHE_ENABLE
  22. /* attribute data into no cache ram */
  23. #define USB_NOCACHE_RAM_SECTION DRAM_DMA_ALIGNED_ATTR
  24. /* use usb_memcpy default for high performance but cost more flash memory.
  25. * And, arm libc has a bug that memcpy() may cause data misalignment when the size is not a multiple of 4.
  26. */
  27. // #define CONFIG_USB_MEMCPY_DISABLE
  28. /* ================= USB Device Stack Configuration ================ */
  29. /* Ep0 in and out transfer buffer */
  30. #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
  31. #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
  32. #endif
  33. /* Setup packet log for debug */
  34. // #define CONFIG_USBDEV_SETUP_LOG_PRINT
  35. /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
  36. * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
  37. */
  38. // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
  39. /* Check if the input descriptor is correct */
  40. // #define CONFIG_USBDEV_DESC_CHECK
  41. /* Enable test mode */
  42. // #define CONFIG_USBDEV_TEST_MODE
  43. /* enable advance desc register api */
  44. #define CONFIG_USBDEV_ADVANCE_DESC
  45. /* move ep0 setup handler from isr to thread */
  46. // #define CONFIG_USBDEV_EP0_THREAD
  47. #ifndef CONFIG_USBDEV_EP0_PRIO
  48. #define CONFIG_USBDEV_EP0_PRIO 4
  49. #endif
  50. #ifndef CONFIG_USBDEV_EP0_STACKSIZE
  51. #define CONFIG_USBDEV_EP0_STACKSIZE 2048
  52. #endif
  53. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  54. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  55. #endif
  56. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  57. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
  58. #endif
  59. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  60. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  61. #endif
  62. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  63. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  64. #endif
  65. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  66. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  67. #endif
  68. /* move msc read & write from isr to while(1), you should call usbd_msc_polling in while(1) */
  69. // #define CONFIG_USBDEV_MSC_POLLING
  70. /* move msc read & write from isr to thread */
  71. #define CONFIG_USBDEV_MSC_THREAD
  72. #ifndef CONFIG_USBDEV_MSC_PRIO
  73. #define CONFIG_USBDEV_MSC_PRIO 4
  74. #endif
  75. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  76. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  77. #endif
  78. #ifndef CONFIG_USBDEV_MTP_MAX_BUFSIZE
  79. #define CONFIG_USBDEV_MTP_MAX_BUFSIZE 2048
  80. #endif
  81. #ifndef CONFIG_USBDEV_MTP_MAX_OBJECTS
  82. #define CONFIG_USBDEV_MTP_MAX_OBJECTS 256
  83. #endif
  84. #ifndef CONFIG_USBDEV_MTP_MAX_PATHNAME
  85. #define CONFIG_USBDEV_MTP_MAX_PATHNAME 256
  86. #endif
  87. #define CONFIG_USBDEV_MTP_THREAD
  88. #ifndef CONFIG_USBDEV_MTP_PRIO
  89. #define CONFIG_USBDEV_MTP_PRIO 4
  90. #endif
  91. #ifndef CONFIG_USBDEV_MTP_STACKSIZE
  92. #define CONFIG_USBDEV_MTP_STACKSIZE 4096
  93. #endif
  94. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  95. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  96. #endif
  97. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  98. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  99. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  100. #endif
  101. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  102. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  103. #endif
  104. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  105. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  106. #endif
  107. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  108. #define CONFIG_USBDEV_CDC_ECM_USING_LWIP
  109. /* ================ USB HOST Stack Configuration ================== */
  110. #define CONFIG_USBHOST_MAX_RHPORTS 1
  111. #define CONFIG_USBHOST_MAX_EXTHUBS 1
  112. #define CONFIG_USBHOST_MAX_EHPORTS 4
  113. #define CONFIG_USBHOST_MAX_INTERFACES 8
  114. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 2
  115. #define CONFIG_USBHOST_MAX_ENDPOINTS 4
  116. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  117. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  118. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  119. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  120. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  121. #define CONFIG_USBHOST_DEV_NAMELEN 16
  122. #ifndef CONFIG_USBHOST_PSC_PRIO
  123. #define CONFIG_USBHOST_PSC_PRIO 0
  124. #endif
  125. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  126. #define CONFIG_USBHOST_PSC_STACKSIZE 4096
  127. #endif
  128. //#define CONFIG_USBHOST_GET_STRING_DESC
  129. // #define CONFIG_USBHOST_MSOS_ENABLE
  130. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  131. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  132. #endif
  133. /* Ep0 max transfer buffer */
  134. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  135. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 2048
  136. #endif
  137. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  138. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  139. #endif
  140. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  141. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  142. #endif
  143. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  144. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  145. */
  146. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
  147. #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
  148. #endif
  149. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  150. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
  151. #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
  152. #endif
  153. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  154. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  155. */
  156. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
  157. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
  158. #endif
  159. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  160. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
  161. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
  162. #endif
  163. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  164. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  165. */
  166. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
  167. #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
  168. #endif
  169. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  170. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
  171. #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
  172. #endif
  173. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  174. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  175. */
  176. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
  177. #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
  178. #endif
  179. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  180. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
  181. #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
  182. #endif
  183. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  184. // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
  185. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  186. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  187. #endif
  188. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  189. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  190. #endif
  191. #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
  192. #define ESP_USB_FS0_BASE 0x60080000
  193. #define ESP_USBD_BASE ESP_USB_FS0_BASE
  194. #define ESP_USBH_BASE ESP_USB_FS0_BASE
  195. #define CONFIG_USBDEV_MAX_BUS 1
  196. #define CONFIG_USBHOST_MAX_BUS 1
  197. #elif CONFIG_IDF_TARGET_ESP32P4
  198. #define ESP_USB_HS0_BASE 0x50000000
  199. #define ESP_USB_FS0_BASE 0x50040000
  200. #define ESP_USBD_BASE ESP_USB_HS0_BASE
  201. #define ESP_USBH_BASE ESP_USB_HS0_BASE
  202. #define CONFIG_USBDEV_MAX_BUS 2
  203. #define CONFIG_USBHOST_MAX_BUS 2
  204. #define CONFIG_USB_HS
  205. #else
  206. #error "Unsupported SoC"
  207. #endif
  208. #if CONFIG_IDF_TARGET_ESP32P4
  209. #define CONFIG_USB_DCACHE_ENABLE
  210. #undef CONFIG_USB_ALIGN_SIZE
  211. #define CONFIG_USB_ALIGN_SIZE CONFIG_CACHE_L1_CACHE_LINE_SIZE
  212. #endif