usb_config.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Copyright (c) 2022, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef CHERRYUSB_CONFIG_H
  7. #define CHERRYUSB_CONFIG_H
  8. #include <rtthread.h>
  9. #include "hpm_soc_feature.h"
  10. /* ================ USB common Configuration ================ */
  11. #define CONFIG_USB_PRINTF(...) rt_kprintf(__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 */
  18. #ifndef CONFIG_USB_ALIGN_SIZE
  19. #define CONFIG_USB_ALIGN_SIZE 4
  20. #endif
  21. /* attribute data into no cache ram */
  22. #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
  23. /* ================= USB Device Stack Configuration ================ */
  24. /* Ep0 in and out transfer buffer */
  25. #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
  26. #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
  27. #endif
  28. /* Setup packet log for debug */
  29. // #define CONFIG_USBDEV_SETUP_LOG_PRINT
  30. /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
  31. * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
  32. */
  33. // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
  34. /* Check if the input descriptor is correct */
  35. // #define CONFIG_USBDEV_DESC_CHECK
  36. /* Enable test mode */
  37. // #define CONFIG_USBDEV_TEST_MODE
  38. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  39. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  40. #endif
  41. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  42. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
  43. #endif
  44. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  45. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  46. #endif
  47. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  48. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  49. #endif
  50. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  51. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  52. #endif
  53. /* move msc read & write from isr to while(1), you should call usbd_msc_polling in while(1) */
  54. // #define CONFIG_USBDEV_MSC_POLLING
  55. /* move msc read & write from isr to thread */
  56. // #define CONFIG_USBDEV_MSC_THREAD
  57. #ifndef CONFIG_USBDEV_MSC_PRIO
  58. #define CONFIG_USBDEV_MSC_PRIO 4
  59. #endif
  60. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  61. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  62. #endif
  63. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  64. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  65. #endif
  66. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  67. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  68. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  69. #endif
  70. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  71. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  72. #endif
  73. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  74. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  75. #endif
  76. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  77. /* ================ USB HOST Stack Configuration ================== */
  78. #define CONFIG_USBHOST_MAX_RHPORTS 1
  79. #define CONFIG_USBHOST_MAX_EXTHUBS 1
  80. #define CONFIG_USBHOST_MAX_EHPORTS 4
  81. #define CONFIG_USBHOST_MAX_INTERFACES 8
  82. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
  83. #define CONFIG_USBHOST_MAX_ENDPOINTS 4
  84. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  85. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  86. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  87. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  88. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  89. #define CONFIG_USBHOST_DEV_NAMELEN 16
  90. #ifndef CONFIG_USBHOST_PSC_PRIO
  91. #define CONFIG_USBHOST_PSC_PRIO 0
  92. #endif
  93. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  94. #define CONFIG_USBHOST_PSC_STACKSIZE 2048
  95. #endif
  96. //#define CONFIG_USBHOST_GET_STRING_DESC
  97. // #define CONFIG_USBHOST_MSOS_ENABLE
  98. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  99. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  100. #endif
  101. /* Ep0 max transfer buffer */
  102. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  103. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
  104. #endif
  105. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  106. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  107. #endif
  108. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  109. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  110. #endif
  111. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  112. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  113. */
  114. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
  115. #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
  116. #endif
  117. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  118. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
  119. #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
  120. #endif
  121. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  122. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  123. */
  124. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
  125. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
  126. #endif
  127. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  128. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
  129. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
  130. #endif
  131. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  132. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  133. */
  134. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
  135. #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
  136. #endif
  137. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  138. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
  139. #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
  140. #endif
  141. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  142. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  143. */
  144. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
  145. #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
  146. #endif
  147. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  148. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
  149. #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
  150. #endif
  151. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  152. // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
  153. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  154. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  155. #endif
  156. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  157. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  158. #endif
  159. /* ================ USB Device Port Configuration ================*/
  160. #ifndef CONFIG_USBDEV_MAX_BUS
  161. #define CONFIG_USBDEV_MAX_BUS USB_SOC_MAX_COUNT // for now, bus num must be 1 except hpm ip
  162. #endif
  163. #ifndef CONFIG_USBDEV_EP_NUM
  164. #define CONFIG_USBDEV_EP_NUM USB_SOC_DCD_MAX_ENDPOINT_COUNT
  165. #endif
  166. /* ---------------- FSDEV Configuration ---------------- */
  167. //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
  168. /* ---------------- DWC2 Configuration ---------------- */
  169. /* (5 * number of control endpoints + 8) + ((largest USB packet used / 4) + 1 for
  170. * status information) + (2 * number of OUT endpoints) + 1 for Global NAK
  171. */
  172. // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
  173. /* IN Endpoints Max packet Size / 4 */
  174. // #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
  175. // #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4)
  176. // #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
  177. // #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
  178. // #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
  179. // #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
  180. // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
  181. // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
  182. // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
  183. /* ---------------- MUSB Configuration ---------------- */
  184. // #define CONFIG_USB_MUSB_SUNXI
  185. /* ================ USB Host Port Configuration ==================*/
  186. #ifndef CONFIG_USBHOST_MAX_BUS
  187. #define CONFIG_USBHOST_MAX_BUS USB_SOC_MAX_COUNT
  188. #endif
  189. #ifndef CONFIG_USBHOST_PIPE_NUM
  190. #define CONFIG_USBHOST_PIPE_NUM 10
  191. #endif
  192. /* ---------------- EHCI Configuration ---------------- */
  193. #define CONFIG_USB_EHCI_HCCR_OFFSET (0x100)
  194. #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
  195. #define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
  196. #define CONFIG_USB_EHCI_QTD_NUM 3
  197. #define CONFIG_USB_EHCI_ITD_NUM 20
  198. // #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
  199. // #define CONFIG_USB_EHCI_CONFIGFLAG
  200. // #define CONFIG_USB_EHCI_ISO
  201. // #define CONFIG_USB_EHCI_WITH_OHCI
  202. /* ---------------- OHCI Configuration ---------------- */
  203. #define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
  204. /* ---------------- XHCI Configuration ---------------- */
  205. #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
  206. /* ---------------- DWC2 Configuration ---------------- */
  207. /* largest non-periodic USB packet used / 4 */
  208. // #define CONFIG_USB_DWC2_NPTX_FIFO_SIZE (512 / 4)
  209. /* largest periodic USB packet used / 4 */
  210. // #define CONFIG_USB_DWC2_PTX_FIFO_SIZE (1024 / 4)
  211. /*
  212. * (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
  213. * 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
  214. */
  215. // #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE) / 4)
  216. /* ---------------- MUSB Configuration ---------------- */
  217. // #define CONFIG_USB_MUSB_SUNXI
  218. #define CONFIG_USB_EHCI_HPMICRO (1)
  219. #endif