usb_config.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (c) 2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2025-01-17 Supperthomas first version
  9. */
  10. #ifndef CHERRYUSB_CONFIG_H
  11. #define CHERRYUSB_CONFIG_H
  12. /* ================ USB common Configuration ================ */
  13. #include "rtthread.h"
  14. #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
  15. #ifndef CONFIG_USB_DBG_LEVEL
  16. #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
  17. #endif
  18. /* Enable print with color */
  19. #define CONFIG_USB_PRINTF_COLOR_ENABLE
  20. /* data align size when use dma */
  21. #ifndef CONFIG_USB_ALIGN_SIZE
  22. #define CONFIG_USB_ALIGN_SIZE 4
  23. #endif
  24. /* attribute data into no cache ram */
  25. #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
  26. /* ================= USB Device Stack Configuration ================ */
  27. /* Ep0 in and out transfer buffer */
  28. #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
  29. #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
  30. #endif
  31. /* Setup packet log for debug */
  32. // #define CONFIG_USBDEV_SETUP_LOG_PRINT
  33. /* Check if the input descriptor is correct */
  34. // #define CONFIG_USBDEV_DESC_CHECK
  35. /* Enable test mode */
  36. // #define CONFIG_USBDEV_TEST_MODE
  37. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  38. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  39. #endif
  40. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  41. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
  42. #endif
  43. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  44. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  45. #endif
  46. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  47. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  48. #endif
  49. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  50. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  51. #endif
  52. // #define CONFIG_USBDEV_MSC_THREAD
  53. #ifndef CONFIG_USBDEV_MSC_PRIO
  54. #define CONFIG_USBDEV_MSC_PRIO 4
  55. #endif
  56. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  57. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  58. #endif
  59. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  60. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  61. #endif
  62. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  63. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 2048
  64. #endif
  65. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  66. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  67. #endif
  68. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  69. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  70. #endif
  71. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  72. /* ================ USB HOST Stack Configuration ================== */
  73. #define CONFIG_USBHOST_MAX_RHPORTS 1
  74. #define CONFIG_USBHOST_MAX_EXTHUBS 1
  75. #define CONFIG_USBHOST_MAX_EHPORTS 4
  76. #define CONFIG_USBHOST_MAX_INTERFACES 8
  77. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
  78. #define CONFIG_USBHOST_MAX_ENDPOINTS 4
  79. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  80. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  81. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  82. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  83. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  84. #define CONFIG_USBHOST_DEV_NAMELEN 16
  85. #ifndef CONFIG_USBHOST_PSC_PRIO
  86. #define CONFIG_USBHOST_PSC_PRIO 0
  87. #endif
  88. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  89. #define CONFIG_USBHOST_PSC_STACKSIZE 2048
  90. #endif
  91. //#define CONFIG_USBHOST_GET_STRING_DESC
  92. // #define CONFIG_USBHOST_MSOS_ENABLE
  93. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  94. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  95. #endif
  96. /* Ep0 max transfer buffer */
  97. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  98. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
  99. #endif
  100. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  101. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  102. #endif
  103. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  104. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  105. #endif
  106. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  107. * you can change with 2K,4K,8K,16K,default is 2K to get one TCP_MSS
  108. */
  109. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
  110. #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
  111. #endif
  112. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
  113. #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
  114. #endif
  115. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  116. * you can change with 2K,4K,8K,16K,default is 2K to get one TCP_MSS
  117. */
  118. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
  119. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
  120. #endif
  121. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
  122. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
  123. #endif
  124. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  125. // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
  126. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  127. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  128. #endif
  129. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  130. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  131. #endif
  132. /* ================ USB Device Port Configuration ================*/
  133. #ifndef CONFIG_USBDEV_MAX_BUS
  134. #define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip
  135. #endif
  136. #ifndef CONFIG_USBDEV_EP_NUM
  137. #define CONFIG_USBDEV_EP_NUM 6
  138. #endif
  139. /* ---------------- FSDEV Configuration ---------------- */
  140. //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
  141. /* ---------------- DWC2 Configuration ---------------- */
  142. // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
  143. #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
  144. #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (64 / 4)
  145. #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
  146. #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
  147. #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
  148. #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
  149. // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
  150. // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
  151. // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
  152. /* ---------------- MUSB Configuration ---------------- */
  153. // #define CONFIG_USB_MUSB_SUNXI
  154. /* ================ USB Host Port Configuration ==================*/
  155. #ifndef CONFIG_USBHOST_MAX_BUS
  156. #define CONFIG_USBHOST_MAX_BUS 1
  157. #endif
  158. #ifndef CONFIG_USBHOST_PIPE_NUM
  159. #define CONFIG_USBHOST_PIPE_NUM 12
  160. #endif
  161. /* ---------------- EHCI Configuration ---------------- */
  162. #define CONFIG_USB_EHCI_HCCR_OFFSET (0x0)
  163. #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
  164. #define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
  165. #define CONFIG_USB_EHCI_QTD_NUM 3
  166. #define CONFIG_USB_EHCI_ITD_NUM 20
  167. // #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
  168. // #define CONFIG_USB_EHCI_CONFIGFLAG
  169. // #define CONFIG_USB_EHCI_ISO
  170. // #define CONFIG_USB_EHCI_WITH_OHCI
  171. /* ---------------- OHCI Configuration ---------------- */
  172. #define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
  173. /* ---------------- XHCI Configuration ---------------- */
  174. #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
  175. /* ---------------- DWC2 Configuration ---------------- */
  176. /* largest non-periodic USB packet used / 4 */
  177. // #define CONFIG_USB_DWC2_NPTX_FIFO_SIZE (512 / 4)
  178. /* largest periodic USB packet used / 4 */
  179. // #define CONFIG_USB_DWC2_PTX_FIFO_SIZE (1024 / 4)
  180. /*
  181. * (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
  182. * 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
  183. */
  184. // #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
  185. /* ---------------- MUSB Configuration ---------------- */
  186. // #define CONFIG_USB_MUSB_SUNXI
  187. #endif