usb_config.h 8.2 KB

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