cherryusb_config_template.h 11 KB

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