usb_config.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. #define CONFIG_USB_DCACHE_ENABLE
  18. /* data align size when use dma or use dcache */
  19. #ifdef CONFIG_USB_DCACHE_ENABLE
  20. #define CONFIG_USB_ALIGN_SIZE HPM_L1C_CACHELINE_SIZE // 32 or 64
  21. #else
  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. /* use usb_memcpy default for high performance but cost more flash memory.
  27. * And, arm libc has a bug that memcpy() may cause data misalignment when the size is not a multiple of 4.
  28. */
  29. // #define CONFIG_USB_MEMCPY_DISABLE
  30. /* ================= USB Device Stack Configuration ================ */
  31. /* Ep0 in and out transfer buffer */
  32. #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
  33. #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
  34. #endif
  35. /* Setup packet log for debug */
  36. // #define CONFIG_USBDEV_SETUP_LOG_PRINT
  37. /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
  38. * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
  39. */
  40. // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
  41. /* Check if the input descriptor is correct */
  42. // #define CONFIG_USBDEV_DESC_CHECK
  43. /* Enable test mode */
  44. // #define CONFIG_USBDEV_TEST_MODE
  45. /* enable advance desc register api */
  46. #define CONFIG_USBDEV_ADVANCE_DESC
  47. /* move ep0 setup handler from isr to thread */
  48. // #define CONFIG_USBDEV_EP0_THREAD
  49. #ifndef CONFIG_USBDEV_EP0_PRIO
  50. #define CONFIG_USBDEV_EP0_PRIO 4
  51. #endif
  52. #ifndef CONFIG_USBDEV_EP0_STACKSIZE
  53. #define CONFIG_USBDEV_EP0_STACKSIZE 2048
  54. #endif
  55. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  56. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  57. #endif
  58. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  59. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
  60. #endif
  61. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  62. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  63. #endif
  64. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  65. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  66. #endif
  67. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  68. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  69. #endif
  70. /* move msc read & write from isr to while(1), you should call usbd_msc_polling in while(1) */
  71. // #define CONFIG_USBDEV_MSC_POLLING
  72. /* move msc read & write from isr to thread */
  73. // #define CONFIG_USBDEV_MSC_THREAD
  74. #ifndef CONFIG_USBDEV_MSC_PRIO
  75. #define CONFIG_USBDEV_MSC_PRIO 4
  76. #endif
  77. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  78. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  79. #endif
  80. #ifndef CONFIG_USBDEV_MTP_MAX_BUFSIZE
  81. #define CONFIG_USBDEV_MTP_MAX_BUFSIZE 2048
  82. #endif
  83. #ifndef CONFIG_USBDEV_MTP_MAX_OBJECTS
  84. #define CONFIG_USBDEV_MTP_MAX_OBJECTS 256
  85. #endif
  86. #ifndef CONFIG_USBDEV_MTP_MAX_PATHNAME
  87. #define CONFIG_USBDEV_MTP_MAX_PATHNAME 256
  88. #endif
  89. #define CONFIG_USBDEV_MTP_THREAD
  90. #ifndef CONFIG_USBDEV_MTP_PRIO
  91. #define CONFIG_USBDEV_MTP_PRIO 4
  92. #endif
  93. #ifndef CONFIG_USBDEV_MTP_STACKSIZE
  94. #define CONFIG_USBDEV_MTP_STACKSIZE 4096
  95. #endif
  96. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  97. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  98. #endif
  99. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  100. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  101. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  102. #endif
  103. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  104. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  105. #endif
  106. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  107. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  108. #endif
  109. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  110. #define CONFIG_USBDEV_CDC_ECM_USING_LWIP
  111. /* ================ USB HOST Stack Configuration ================== */
  112. #define CONFIG_USBHOST_MAX_RHPORTS 1
  113. #define CONFIG_USBHOST_MAX_EXTHUBS 1
  114. #define CONFIG_USBHOST_MAX_EHPORTS 4
  115. #define CONFIG_USBHOST_MAX_INTERFACES 8
  116. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
  117. #define CONFIG_USBHOST_MAX_ENDPOINTS 4
  118. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  119. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  120. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  121. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  122. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  123. #define CONFIG_USBHOST_DEV_NAMELEN 16
  124. #ifndef CONFIG_USBHOST_PSC_PRIO
  125. #define CONFIG_USBHOST_PSC_PRIO 0
  126. #endif
  127. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  128. #define CONFIG_USBHOST_PSC_STACKSIZE 2048
  129. #endif
  130. //#define CONFIG_USBHOST_GET_STRING_DESC
  131. // #define CONFIG_USBHOST_MSOS_ENABLE
  132. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  133. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  134. #endif
  135. /* Ep0 max transfer buffer */
  136. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  137. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
  138. #endif
  139. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  140. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  141. #endif
  142. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  143. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  144. #endif
  145. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  146. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  147. */
  148. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
  149. #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
  150. #endif
  151. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  152. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
  153. #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
  154. #endif
  155. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  156. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  157. */
  158. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
  159. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
  160. #endif
  161. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  162. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
  163. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
  164. #endif
  165. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  166. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  167. */
  168. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
  169. #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
  170. #endif
  171. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  172. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
  173. #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
  174. #endif
  175. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  176. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  177. */
  178. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
  179. #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
  180. #endif
  181. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  182. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
  183. #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
  184. #endif
  185. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  186. // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
  187. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  188. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  189. #endif
  190. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  191. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  192. #endif
  193. /* ================ USB Device Port Configuration ================*/
  194. #ifndef CONFIG_USBDEV_MAX_BUS
  195. #define CONFIG_USBDEV_MAX_BUS USB_SOC_MAX_COUNT // for now, bus num must be 1 except hpm ip
  196. #endif
  197. #ifndef CONFIG_USBDEV_EP_NUM
  198. #define CONFIG_USBDEV_EP_NUM USB_SOC_DCD_MAX_ENDPOINT_COUNT
  199. #endif
  200. // #define CONFIG_USBDEV_SOF_ENABLE
  201. /* When your chip hardware supports high-speed and wants to initialize it in high-speed mode, the relevant IP will configure the internal or external high-speed PHY according to CONFIG_USB_HS. */
  202. #define CONFIG_USB_HS
  203. /* ---------------- FSDEV Configuration ---------------- */
  204. //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
  205. /* ---------------- DWC2 Configuration ---------------- */
  206. /* (5 * number of control endpoints + 8) + ((largest USB packet used / 4) + 1 for
  207. * status information) + (2 * number of OUT endpoints) + 1 for Global NAK
  208. */
  209. // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
  210. /* IN Endpoints Max packet Size / 4 */
  211. // #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
  212. // #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (1024 / 4)
  213. // #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
  214. // #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
  215. // #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
  216. // #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
  217. // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
  218. // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
  219. // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
  220. // #define CONFIG_USB_DWC2_DMA_ENABLE
  221. /* ---------------- MUSB Configuration ---------------- */
  222. // #define CONFIG_USB_MUSB_SUNXI
  223. /* ================ USB Host Port Configuration ==================*/
  224. #ifndef CONFIG_USBHOST_MAX_BUS
  225. #define CONFIG_USBHOST_MAX_BUS USB_SOC_MAX_COUNT
  226. #endif
  227. #ifndef CONFIG_USBHOST_PIPE_NUM
  228. #define CONFIG_USBHOST_PIPE_NUM 10
  229. #endif
  230. /* ---------------- EHCI Configuration ---------------- */
  231. #define CONFIG_USB_EHCI_HCCR_OFFSET (0x100)
  232. #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
  233. #define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
  234. #define CONFIG_USB_EHCI_QTD_NUM (CONFIG_USB_EHCI_QH_NUM * 3)
  235. #define CONFIG_USB_EHCI_ITD_NUM 4
  236. // #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
  237. // #define CONFIG_USB_EHCI_CONFIGFLAG
  238. // #define CONFIG_USB_EHCI_ISO
  239. // #define CONFIG_USB_EHCI_WITH_OHCI
  240. // #define CONFIG_USB_EHCI_DESC_DCACHE_ENABLE
  241. /* ---------------- OHCI Configuration ---------------- */
  242. #define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
  243. #define CONFIG_USB_OHCI_ED_NUM CONFIG_USBHOST_PIPE_NUM
  244. #define CONFIG_USB_OHCI_TD_NUM 3
  245. // #define CONFIG_USB_OHCI_DESC_DCACHE_ENABLE
  246. /* ---------------- XHCI Configuration ---------------- */
  247. #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
  248. /* ---------------- DWC2 Configuration ---------------- */
  249. /* largest non-periodic USB packet used / 4 */
  250. // #define CONFIG_USB_DWC2_NPTX_FIFO_SIZE (512 / 4)
  251. /* largest periodic USB packet used / 4 */
  252. // #define CONFIG_USB_DWC2_PTX_FIFO_SIZE (1024 / 4)
  253. /*
  254. * (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
  255. * 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
  256. */
  257. // #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
  258. /* ---------------- MUSB Configuration ---------------- */
  259. // #define CONFIG_USB_MUSB_SUNXI
  260. #ifndef usb_phyaddr2ramaddr
  261. #define usb_phyaddr2ramaddr(addr) (addr)
  262. #endif
  263. #ifndef usb_ramaddr2phyaddr
  264. #define usb_ramaddr2phyaddr(addr) (addr)
  265. #endif
  266. #define CONFIG_USB_EHCI_HPMICRO 1
  267. #endif