usb_config.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. /* ================ USB common Configuration ================ */
  15. #define CONFIG_USB_PRINTF(...) printf(__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_dc_get_register_base(uint32_t id);
  23. size_t usb_osal_enter_critical_section(void);
  24. void usb_osal_leave_critical_section(size_t flag);
  25. #ifndef CONFIG_USB_DBG_LEVEL
  26. #if defined(CONFIG_LOG_ERROR)
  27. #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR
  28. #elif defined(CONFIG_LOG_WARN)
  29. #define CONFIG_USB_DBG_LEVEL USB_DBG_WARNING
  30. #elif defined(CONFIG_LOG_INFO)
  31. #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
  32. #elif defined(CONFIG_LOG_DEBUG) || defined(CONFIG_LOG_VERBOS)
  33. #define CONFIG_USB_DBG_LEVEL USB_DBG_LOG
  34. #else
  35. #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR
  36. #endif
  37. #endif
  38. /* Enable print with color */
  39. #define CONFIG_USB_PRINTF_COLOR_ENABLE
  40. /* data align size when use dma */
  41. #ifndef CONFIG_USB_ALIGN_SIZE
  42. #define CONFIG_USB_ALIGN_SIZE 4
  43. #endif
  44. /* attribute data into no cache ram */
  45. #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
  46. /* ================= USB Device Stack Configuration ================ */
  47. /* Ep0 in and out transfer buffer */
  48. #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
  49. #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
  50. #endif
  51. /* Setup packet log for debug */
  52. // #define CONFIG_USBDEV_SETUP_LOG_PRINT
  53. /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
  54. * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
  55. */
  56. // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
  57. /* Check if the input descriptor is correct */
  58. // #define CONFIG_USBDEV_DESC_CHECK
  59. /* Enable test mode */
  60. // #define CONFIG_USBDEV_TEST_MODE
  61. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  62. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  63. #endif
  64. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  65. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 4096
  66. #endif
  67. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  68. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  69. #endif
  70. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  71. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  72. #endif
  73. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  74. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  75. #endif
  76. // #define CONFIG_USBDEV_MSC_THREAD
  77. #ifndef CONFIG_USBDEV_MSC_PRIO
  78. #define CONFIG_USBDEV_MSC_PRIO 4
  79. #endif
  80. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  81. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  82. #endif
  83. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  84. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  85. #endif
  86. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  87. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  88. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  89. #endif
  90. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  91. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  92. #endif
  93. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  94. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  95. #endif
  96. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  97. /* ================ USB HOST Stack Configuration ================== */
  98. #define CONFIG_USBHOST_MAX_RHPORTS 1
  99. #define CONFIG_USBHOST_MAX_EXTHUBS 1
  100. #define CONFIG_USBHOST_MAX_EHPORTS 4
  101. #define CONFIG_USBHOST_MAX_INTERFACES 8
  102. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
  103. #define CONFIG_USBHOST_MAX_ENDPOINTS 4
  104. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  105. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  106. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  107. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  108. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  109. #define CONFIG_USBHOST_DEV_NAMELEN 16
  110. #ifndef CONFIG_USBHOST_PSC_PRIO
  111. #define CONFIG_USBHOST_PSC_PRIO 0
  112. #endif
  113. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  114. #define CONFIG_USBHOST_PSC_STACKSIZE 8192
  115. #endif
  116. //#define CONFIG_USBHOST_GET_STRING_DESC
  117. // #define CONFIG_USBHOST_MSOS_ENABLE
  118. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  119. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  120. #endif
  121. /* Ep0 max transfer buffer */
  122. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  123. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
  124. #endif
  125. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  126. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  127. #endif
  128. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  129. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  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_RNDIS_ETH_MAX_RX_SIZE
  135. #define CONFIG_USBHOST_RNDIS_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_RNDIS_ETH_MAX_TX_SIZE
  139. #define CONFIG_USBHOST_RNDIS_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_CDC_NCM_ETH_MAX_RX_SIZE
  145. #define CONFIG_USBHOST_CDC_NCM_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_CDC_NCM_ETH_MAX_TX_SIZE
  149. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
  150. #endif
  151. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  152. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  153. */
  154. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
  155. #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
  156. #endif
  157. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  158. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
  159. #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
  160. #endif
  161. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  162. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  163. */
  164. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
  165. #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
  166. #endif
  167. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  168. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
  169. #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
  170. #endif
  171. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  172. // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
  173. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  174. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  175. #endif
  176. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  177. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  178. #endif
  179. /* ================ USB Device Port Configuration ================*/
  180. #ifndef CONFIG_USBDEV_MAX_BUS
  181. #define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip
  182. #endif
  183. #ifndef CONFIG_USBDEV_EP_NUM
  184. #define CONFIG_USBDEV_EP_NUM 8
  185. #endif
  186. /* ---------------- FSDEV Configuration ---------------- */
  187. //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
  188. /* ---------------- DWC2 Configuration ---------------- */
  189. /* (5 * number of control endpoints + 8) + ((largest USB packet used / 4) + 1 for
  190. * status information) + (2 * number of OUT endpoints) + 1 for Global NAK
  191. */
  192. // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
  193. /* IN Endpoints Max packet Size / 4 */
  194. // #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
  195. // #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4)
  196. // #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
  197. // #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
  198. // #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
  199. // #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
  200. // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
  201. // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
  202. // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
  203. /* ---------------- MUSB Configuration ---------------- */
  204. // #define CONFIG_USB_MUSB_SUNXI
  205. /* ================ USB Host Port Configuration ==================*/
  206. #ifndef CONFIG_USBHOST_MAX_BUS
  207. #define CONFIG_USBHOST_MAX_BUS 1
  208. #endif
  209. #ifndef CONFIG_USBHOST_PIPE_NUM
  210. #define CONFIG_USBHOST_PIPE_NUM 10
  211. #endif
  212. /* ---------------- XHCI Configuration ---------------- */
  213. #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
  214. /* ---------------- PUSB2 Configuration ---------------- */
  215. #define CONFIG_USB_PUSB2_BUS_NUM 1U
  216. #define CONFIG_USB_PUSB2_BUS_ID 0U
  217. #endif