usb_config.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright : (C) 2024 Phytium Information Technology, Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Modify History:
  7. * Ver   Who        Date         Changes
  8. * ----- ------     --------    --------------------------------------
  9. * 1.0 zhugengyu 2024/6/26 first commit
  10. */
  11. #ifndef CHERRYUSB_CONFIG_H
  12. #define CHERRYUSB_CONFIG_H
  13. #include "rtthread.h"
  14. /* ================ USB common Configuration ================ */
  15. #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
  16. void *xhci_mem_malloc(size_t align, size_t size);
  17. void xhci_mem_free(void *ptr);
  18. #define XHCI_DCACHE_FLUSH (1 << 0)
  19. #define XHCI_DCACHE_INVALIDATE (1 << 1)
  20. void xhci_dcache_sync(void *ptr, size_t len, uint32_t flags);
  21. unsigned long usb_hc_get_register_base(uint32_t id);
  22. #define usb_malloc(size) xhci_mem_malloc(sizeof(int), size)
  23. #define usb_free(ptr) xhci_mem_free(ptr)
  24. #ifndef CONFIG_USB_DBG_LEVEL
  25. #if defined(CONFIG_LOG_ERROR)
  26. #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR
  27. #elif defined(CONFIG_LOG_WARN)
  28. #define CONFIG_USB_DBG_LEVEL USB_DBG_WARNING
  29. #elif defined(CONFIG_LOG_INFO)
  30. #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
  31. #elif defined(CONFIG_LOG_DEBUG) || defined(CONFIG_LOG_VERBOS)
  32. #define CONFIG_USB_DBG_LEVEL USB_DBG_LOG
  33. #else
  34. #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR
  35. #endif
  36. #endif
  37. /* Enable print with color */
  38. #define CONFIG_USB_PRINTF_COLOR_ENABLE
  39. /* data align size when use dma */
  40. #ifndef CONFIG_USB_ALIGN_SIZE
  41. #define CONFIG_USB_ALIGN_SIZE 4
  42. #endif
  43. /* attribute data into no cache ram */
  44. #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
  45. /* ================= USB Device Stack Configuration ================ */
  46. /* Ep0 in and out transfer buffer */
  47. #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
  48. #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
  49. #endif
  50. /* Setup packet log for debug */
  51. // #define CONFIG_USBDEV_SETUP_LOG_PRINT
  52. /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
  53. * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
  54. */
  55. // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
  56. /* Check if the input descriptor is correct */
  57. // #define CONFIG_USBDEV_DESC_CHECK
  58. /* Enable test mode */
  59. // #define CONFIG_USBDEV_TEST_MODE
  60. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  61. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  62. #endif
  63. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  64. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
  65. #endif
  66. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  67. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  68. #endif
  69. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  70. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  71. #endif
  72. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  73. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  74. #endif
  75. // #define CONFIG_USBDEV_MSC_THREAD
  76. #ifndef CONFIG_USBDEV_MSC_PRIO
  77. #define CONFIG_USBDEV_MSC_PRIO 4
  78. #endif
  79. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  80. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  81. #endif
  82. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  83. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  84. #endif
  85. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  86. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  87. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  88. #endif
  89. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  90. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  91. #endif
  92. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  93. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  94. #endif
  95. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  96. /* ================ USB HOST Stack Configuration ================== */
  97. #define CONFIG_USBHOST_MAX_RHPORTS 8
  98. #define CONFIG_USBHOST_MAX_EXTHUBS 4
  99. #define CONFIG_USBHOST_MAX_EHPORTS 8
  100. #define CONFIG_USBHOST_MAX_INTERFACES 8
  101. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
  102. #define CONFIG_USBHOST_MAX_ENDPOINTS 8
  103. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  104. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  105. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  106. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  107. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  108. #define CONFIG_USBHOST_DEV_NAMELEN 16
  109. #ifndef CONFIG_USBHOST_PSC_PRIO
  110. #define CONFIG_USBHOST_PSC_PRIO 0
  111. #endif
  112. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  113. #define CONFIG_USBHOST_PSC_STACKSIZE 8192
  114. #endif
  115. //#define CONFIG_USBHOST_GET_STRING_DESC
  116. // #define CONFIG_USBHOST_MSOS_ENABLE
  117. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  118. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  119. #endif
  120. /* Ep0 max transfer buffer */
  121. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  122. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
  123. #endif
  124. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  125. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  126. #endif
  127. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  128. #define CONFIG_USBHOST_MSC_TIMEOUT 0xffffffff
  129. #endif
  130. #ifndef CONFIG_INPUT_MOUSE_WHEEL
  131. #define CONFIG_INPUT_MOUSE_WHEEL
  132. #endif
  133. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  134. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  135. */
  136. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
  137. #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
  138. #endif
  139. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  140. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
  141. #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
  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_CDC_NCM_ETH_MAX_RX_SIZE
  147. #define CONFIG_USBHOST_CDC_NCM_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_CDC_NCM_ETH_MAX_TX_SIZE
  151. #define CONFIG_USBHOST_CDC_NCM_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_ASIX_ETH_MAX_RX_SIZE
  157. #define CONFIG_USBHOST_ASIX_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_ASIX_ETH_MAX_TX_SIZE
  161. #define CONFIG_USBHOST_ASIX_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_RTL8152_ETH_MAX_RX_SIZE
  167. #define CONFIG_USBHOST_RTL8152_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_RTL8152_ETH_MAX_TX_SIZE
  171. #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
  172. #endif
  173. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  174. // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
  175. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  176. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  177. #endif
  178. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  179. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  180. #endif
  181. /* ================ USB Device Port Configuration ================*/
  182. #ifndef CONFIG_USBDEV_MAX_BUS
  183. #define CONFIG_USBDEV_MAX_BUS 2 // for now, bus num must be 1 except hpm ip
  184. #endif
  185. #ifndef CONFIG_USBDEV_EP_NUM
  186. #define CONFIG_USBDEV_EP_NUM 8
  187. #endif
  188. /* ---------------- FSDEV Configuration ---------------- */
  189. //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
  190. /* ---------------- DWC2 Configuration ---------------- */
  191. // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
  192. // #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
  193. // #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4)
  194. // #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
  195. // #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
  196. // #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
  197. // #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
  198. // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
  199. // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
  200. // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
  201. /* ---------------- MUSB Configuration ---------------- */
  202. // #define CONFIG_USB_MUSB_SUNXI
  203. /* ================ USB Host Port Configuration ==================*/
  204. #ifndef CONFIG_USBHOST_MAX_BUS
  205. #define CONFIG_USBHOST_MAX_BUS 2
  206. #endif
  207. #ifndef CONFIG_USBHOST_PIPE_NUM
  208. #define CONFIG_USBHOST_PIPE_NUM 10
  209. #endif
  210. /* ---------------- EHCI Configuration ---------------- */
  211. #define CONFIG_USB_EHCI_HCCR_OFFSET (0x0)
  212. #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
  213. #define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
  214. #define CONFIG_USB_EHCI_QTD_NUM 3
  215. #define CONFIG_USB_EHCI_ITD_NUM 20
  216. // #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
  217. // #define CONFIG_USB_EHCI_CONFIGFLAG
  218. // #define CONFIG_USB_EHCI_ISO
  219. // #define CONFIG_USB_EHCI_WITH_OHCI
  220. /* ---------------- OHCI Configuration ---------------- */
  221. #define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
  222. /* ---------------- XHCI Configuration ---------------- */
  223. #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
  224. #ifndef CONFIG_USB_XHCI_ENABLE_SOFT_ISR
  225. #define CONFIG_USB_XHCI_ENABLE_SOFT_ISR 0
  226. #endif
  227. #endif