usb_config.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 "sdkconfig.h"
  14. #include "FreeRTOS.h"
  15. #include "task.h"
  16. /* ================ USB common Configuration ================ */
  17. #define CONFIG_USB_PRINTF(...) printf(__VA_ARGS__)
  18. int xPortIsInsideInterrupt(void);
  19. void *usb_sys_mem_malloc(size_t size);
  20. void usb_sys_mem_free(void *ptr);
  21. void *usb_sys_malloc_align(size_t align, size_t size);
  22. #define usb_malloc(size) usb_sys_mem_malloc(size)
  23. #define usb_free(ptr) usb_sys_mem_free(ptr)
  24. #define usb_align(align, size) usb_sys_malloc_align(align, size)
  25. unsigned long usb_hc_get_register_base(uint32_t id);
  26. unsigned long usb_dc_get_register_base(uint32_t id);
  27. #ifndef CONFIG_USB_DBG_LEVEL
  28. #if defined(CONFIG_LOG_ERROR)
  29. #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR
  30. #elif defined(CONFIG_LOG_WARN)
  31. #define CONFIG_USB_DBG_LEVEL USB_DBG_WARNING
  32. #elif defined(CONFIG_LOG_INFO)
  33. #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
  34. #elif defined(CONFIG_LOG_DEBUG) || defined(CONFIG_LOG_VERBOS)
  35. #define CONFIG_USB_DBG_LEVEL USB_DBG_LOG
  36. #else
  37. #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR
  38. #endif
  39. #endif
  40. /* Enable print with color */
  41. #define CONFIG_USB_PRINTF_COLOR_ENABLE
  42. /* data align size when use dma */
  43. #ifndef CONFIG_USB_ALIGN_SIZE
  44. #define CONFIG_USB_ALIGN_SIZE 4
  45. #endif
  46. /* attribute data into no cache ram */
  47. #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
  48. /* ================= USB Device Stack Configuration ================ */
  49. /* Ep0 in and out transfer buffer */
  50. #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
  51. #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
  52. #endif
  53. /* Setup packet log for debug */
  54. // #define CONFIG_USBDEV_SETUP_LOG_PRINT
  55. /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
  56. * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
  57. */
  58. // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
  59. /* Check if the input descriptor is correct */
  60. // #define CONFIG_USBDEV_DESC_CHECK
  61. /* Enable test mode */
  62. // #define CONFIG_USBDEV_TEST_MODE
  63. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  64. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  65. #endif
  66. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  67. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 4096
  68. #endif
  69. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  70. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  71. #endif
  72. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  73. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  74. #endif
  75. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  76. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  77. #endif
  78. // #define CONFIG_USBDEV_MSC_THREAD
  79. #ifndef CONFIG_USBDEV_MSC_PRIO
  80. #define CONFIG_USBDEV_MSC_PRIO 4
  81. #endif
  82. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  83. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  84. #endif
  85. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  86. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  87. #endif
  88. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  89. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  90. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  91. #endif
  92. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  93. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  94. #endif
  95. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  96. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  97. #endif
  98. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  99. /* ================ USB HOST Stack Configuration ================== */
  100. #define CONFIG_USBHOST_MAX_RHPORTS 1
  101. #define CONFIG_USBHOST_MAX_EXTHUBS 0
  102. #define CONFIG_USBHOST_MAX_EHPORTS 8
  103. #define CONFIG_USBHOST_MAX_INTERFACES 8
  104. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
  105. #define CONFIG_USBHOST_MAX_ENDPOINTS 8
  106. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  107. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  108. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  109. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  110. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  111. #define CONFIG_USBHOST_DEV_NAMELEN 16
  112. #ifndef CONFIG_USBHOST_PSC_PRIO
  113. #define CONFIG_USBHOST_PSC_PRIO 0
  114. #endif
  115. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  116. #define CONFIG_USBHOST_PSC_STACKSIZE 8192
  117. #endif
  118. //#define CONFIG_USBHOST_GET_STRING_DESC
  119. // #define CONFIG_USBHOST_MSOS_ENABLE
  120. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  121. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  122. #endif
  123. /* Ep0 max transfer buffer */
  124. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  125. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
  126. #endif
  127. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  128. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  129. #endif
  130. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  131. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  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 1 // 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. /* (5 * number of control endpoints + 8) + ((largest USB packet used / 4) + 1 for
  192. * status information) + (2 * number of OUT endpoints) + 1 for Global NAK
  193. */
  194. // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
  195. /* IN Endpoints Max packet Size / 4 */
  196. // #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
  197. // #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4)
  198. // #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
  199. // #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
  200. // #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
  201. // #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
  202. // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
  203. // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
  204. // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
  205. /* ---------------- MUSB Configuration ---------------- */
  206. // #define CONFIG_USB_MUSB_SUNXI
  207. /* ================ USB Host Port Configuration ==================*/
  208. #ifndef CONFIG_INPUT_MOUSE_WHEEL
  209. #define CONFIG_INPUT_MOUSE_WHEEL
  210. #endif
  211. #ifndef CONFIG_USBHOST_MAX_BUS
  212. #define CONFIG_USBHOST_MAX_BUS 3
  213. #endif
  214. #ifndef CONFIG_USBHOST_PIPE_NUM
  215. #define CONFIG_USBHOST_PIPE_NUM 10
  216. #endif
  217. /* ---------------- XHCI Configuration ---------------- */
  218. #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
  219. /* ---------------- PUSB2 Configuration ---------------- */
  220. #define CONFIG_USB_PUSB2_BUS_NUM 3U
  221. #define CONFIG_USB_PUSB2_BUS_ID 0U
  222. #endif