usb_config.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 "rtconfig.h"
  14. /* ================ USB common Configuration ================ */
  15. #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
  16. void *usb_sys_mem_malloc(size_t size);
  17. void usb_sys_mem_free(void *ptr);
  18. void *usb_sys_malloc_align(size_t align, size_t size);
  19. #define usb_malloc(size) usb_sys_mem_malloc(size)
  20. #define usb_free(ptr) usb_sys_mem_free(ptr)
  21. #define usb_align(align, size) usb_sys_malloc_align(align, size)
  22. unsigned long usb_hc_get_register_base(uint32_t id);
  23. unsigned long usb_dc_get_register_base(uint32_t id);
  24. #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR
  25. /* Enable print with color */
  26. #define CONFIG_USB_PRINTF_COLOR_ENABLE
  27. /* data align size when use dma */
  28. #ifndef CONFIG_USB_ALIGN_SIZE
  29. #define CONFIG_USB_ALIGN_SIZE 4
  30. #endif
  31. /* attribute data into no cache ram */
  32. #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
  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. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  49. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  50. #endif
  51. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  52. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 4096
  53. #endif
  54. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  55. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  56. #endif
  57. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  58. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  59. #endif
  60. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  61. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  62. #endif
  63. // #define CONFIG_USBDEV_MSC_THREAD
  64. #ifndef CONFIG_USBDEV_MSC_PRIO
  65. #define CONFIG_USBDEV_MSC_PRIO 4
  66. #endif
  67. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  68. #define CONFIG_USBDEV_MSC_STACKSIZE 8192
  69. #endif
  70. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  71. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  72. #endif
  73. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  74. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  75. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  76. #endif
  77. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  78. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  79. #endif
  80. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  81. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  82. #endif
  83. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  84. /* ================ USB HOST Stack Configuration ================== */
  85. #define CONFIG_USBHOST_MAX_RHPORTS 1
  86. #define CONFIG_USBHOST_MAX_EXTHUBS 0
  87. #define CONFIG_USBHOST_MAX_EHPORTS 8
  88. #define CONFIG_USBHOST_MAX_INTERFACES 8
  89. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
  90. #define CONFIG_USBHOST_MAX_ENDPOINTS 8
  91. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  92. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  93. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  94. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  95. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  96. #define CONFIG_USBHOST_DEV_NAMELEN 16
  97. #ifndef CONFIG_USBHOST_PSC_PRIO
  98. #define CONFIG_USBHOST_PSC_PRIO 0
  99. #endif
  100. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  101. #define CONFIG_USBHOST_PSC_STACKSIZE 8192
  102. #endif
  103. //#define CONFIG_USBHOST_GET_STRING_DESC
  104. // #define CONFIG_USBHOST_MSOS_ENABLE
  105. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  106. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  107. #endif
  108. /* Ep0 max transfer buffer */
  109. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  110. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
  111. #endif
  112. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  113. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  114. #endif
  115. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  116. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  117. #endif
  118. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  119. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  120. */
  121. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
  122. #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
  123. #endif
  124. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  125. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
  126. #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
  127. #endif
  128. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  129. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  130. */
  131. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
  132. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
  133. #endif
  134. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  135. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
  136. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
  137. #endif
  138. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  139. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  140. */
  141. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
  142. #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
  143. #endif
  144. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  145. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
  146. #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
  147. #endif
  148. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  149. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  150. */
  151. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
  152. #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
  153. #endif
  154. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  155. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
  156. #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
  157. #endif
  158. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  159. // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
  160. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  161. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  162. #endif
  163. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  164. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  165. #endif
  166. /* ================ USB Device Port Configuration ================*/
  167. #ifndef CONFIG_USBDEV_MAX_BUS
  168. #define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip
  169. #endif
  170. #ifndef CONFIG_USBDEV_EP_NUM
  171. #define CONFIG_USBDEV_EP_NUM 8
  172. #endif
  173. /* ---------------- FSDEV Configuration ---------------- */
  174. //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
  175. /* ---------------- DWC2 Configuration ---------------- */
  176. /* (5 * number of control endpoints + 8) + ((largest USB packet used / 4) + 1 for
  177. * status information) + (2 * number of OUT endpoints) + 1 for Global NAK
  178. */
  179. // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
  180. /* IN Endpoints Max packet Size / 4 */
  181. // #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
  182. // #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4)
  183. // #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
  184. // #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
  185. // #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
  186. // #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
  187. // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
  188. // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
  189. // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
  190. /* ---------------- MUSB Configuration ---------------- */
  191. // #define CONFIG_USB_MUSB_SUNXI
  192. /* ================ USB Host Port Configuration ==================*/
  193. #ifndef CONFIG_INPUT_MOUSE_WHEEL
  194. #define CONFIG_INPUT_MOUSE_WHEEL
  195. #endif
  196. #ifndef CONFIG_USBHOST_MAX_BUS
  197. #define CONFIG_USBHOST_MAX_BUS 3
  198. #endif
  199. #ifndef CONFIG_USBHOST_PIPE_NUM
  200. #define CONFIG_USBHOST_PIPE_NUM 10
  201. #endif
  202. /* ---------------- XHCI Configuration ---------------- */
  203. #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
  204. /* ---------------- PUSB2 Configuration ---------------- */
  205. #define CONFIG_USB_PUSB2_BUS_NUM 3U
  206. #define CONFIG_USB_PUSB2_BUS_ID 0U
  207. #endif