cherryusb_config_template.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
  39. * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
  40. */
  41. // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
  42. /* Check if the input descriptor is correct */
  43. // #define CONFIG_USBDEV_DESC_CHECK
  44. /* Enable test mode */
  45. // #define CONFIG_USBDEV_TEST_MODE
  46. /* enable advance desc register api */
  47. #define CONFIG_USBDEV_ADVANCE_DESC
  48. /* move ep0 setup handler from isr to thread */
  49. // #define CONFIG_USBDEV_EP0_THREAD
  50. #ifndef CONFIG_USBDEV_EP0_PRIO
  51. #define CONFIG_USBDEV_EP0_PRIO 4
  52. #endif
  53. #ifndef CONFIG_USBDEV_EP0_STACKSIZE
  54. #define CONFIG_USBDEV_EP0_STACKSIZE 2048
  55. #endif
  56. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  57. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  58. #endif
  59. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  60. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
  61. #endif
  62. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  63. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  64. #endif
  65. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  66. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  67. #endif
  68. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  69. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  70. #endif
  71. /* move msc read & write from isr to while(1), you should call usbd_msc_polling in while(1) */
  72. // #define CONFIG_USBDEV_MSC_POLLING
  73. /* move msc read & write from isr to thread */
  74. // #define CONFIG_USBDEV_MSC_THREAD
  75. #ifndef CONFIG_USBDEV_MSC_PRIO
  76. #define CONFIG_USBDEV_MSC_PRIO 4
  77. #endif
  78. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  79. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  80. #endif
  81. #ifndef CONFIG_USBDEV_MTP_MAX_BUFSIZE
  82. #define CONFIG_USBDEV_MTP_MAX_BUFSIZE 2048
  83. #endif
  84. #ifndef CONFIG_USBDEV_MTP_MAX_OBJECTS
  85. #define CONFIG_USBDEV_MTP_MAX_OBJECTS 256
  86. #endif
  87. #ifndef CONFIG_USBDEV_MTP_MAX_PATHNAME
  88. #define CONFIG_USBDEV_MTP_MAX_PATHNAME 256
  89. #endif
  90. #define CONFIG_USBDEV_MTP_THREAD
  91. #ifndef CONFIG_USBDEV_MTP_PRIO
  92. #define CONFIG_USBDEV_MTP_PRIO 4
  93. #endif
  94. #ifndef CONFIG_USBDEV_MTP_STACKSIZE
  95. #define CONFIG_USBDEV_MTP_STACKSIZE 4096
  96. #endif
  97. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  98. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  99. #endif
  100. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  101. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  102. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  103. #endif
  104. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  105. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  106. #endif
  107. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  108. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
  109. #endif
  110. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  111. #define CONFIG_USBDEV_CDC_ECM_USING_LWIP
  112. /* ================ USB HOST Stack Configuration ================== */
  113. #define CONFIG_USBHOST_MAX_RHPORTS 1
  114. #define CONFIG_USBHOST_MAX_EXTHUBS 1
  115. #define CONFIG_USBHOST_MAX_EHPORTS 4
  116. #define CONFIG_USBHOST_MAX_INTERFACES 8
  117. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 2
  118. #define CONFIG_USBHOST_MAX_ENDPOINTS 4
  119. #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
  120. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  121. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  122. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  123. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  124. #define CONFIG_USBHOST_DEV_NAMELEN 16
  125. #ifndef CONFIG_USBHOST_PSC_PRIO
  126. #define CONFIG_USBHOST_PSC_PRIO 0
  127. #endif
  128. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  129. #define CONFIG_USBHOST_PSC_STACKSIZE 2048
  130. #endif
  131. //#define CONFIG_USBHOST_GET_STRING_DESC
  132. // #define CONFIG_USBHOST_MSOS_ENABLE
  133. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  134. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  135. #endif
  136. /* Ep0 max transfer buffer */
  137. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  138. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
  139. #endif
  140. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  141. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  142. #endif
  143. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  144. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  145. #endif
  146. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  147. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  148. */
  149. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
  150. #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
  151. #endif
  152. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  153. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
  154. #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
  155. #endif
  156. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  157. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  158. */
  159. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
  160. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
  161. #endif
  162. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  163. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
  164. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
  165. #endif
  166. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  167. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  168. */
  169. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
  170. #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
  171. #endif
  172. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  173. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
  174. #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
  175. #endif
  176. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  177. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  178. */
  179. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
  180. #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
  181. #endif
  182. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  183. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
  184. #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
  185. #endif
  186. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  187. // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
  188. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  189. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  190. #endif
  191. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  192. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  193. #endif
  194. /* ================ USB Device Port Configuration ================*/
  195. #ifndef CONFIG_USBDEV_MAX_BUS
  196. #define CONFIG_USBDEV_MAX_BUS 1
  197. #endif
  198. // #define CONFIG_USBDEV_SOF_ENABLE
  199. /* ---------------- FSDEV Configuration ---------------- */
  200. //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
  201. /* ---------------- DWC2 Configuration ---------------- */
  202. /* enable dwc2 buffer dma mode for device
  203. * in xxx32 chips, only pb14/pb15 can support dma mode, pa11/pa12 is not supported(only a few supports, but we ignore them)
  204. */
  205. // #define CONFIG_USB_DWC2_DMA_ENABLE
  206. /* ---------------- MUSB Configuration ---------------- */
  207. #define CONFIG_USB_MUSB_EP_NUM 8
  208. // #define CONFIG_USB_MUSB_SUNXI
  209. /* ================ USB Host Port Configuration ==================*/
  210. #ifndef CONFIG_USBHOST_MAX_BUS
  211. #define CONFIG_USBHOST_MAX_BUS 1
  212. #endif
  213. /* ---------------- EHCI Configuration ---------------- */
  214. #define CONFIG_USB_EHCI_HCCR_OFFSET (0x0)
  215. #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
  216. #define CONFIG_USB_EHCI_QH_NUM 10
  217. #define CONFIG_USB_EHCI_QTD_NUM (CONFIG_USB_EHCI_QH_NUM * 3)
  218. #define CONFIG_USB_EHCI_ITD_NUM 4
  219. // #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
  220. // #define CONFIG_USB_EHCI_CONFIGFLAG
  221. // #define CONFIG_USB_EHCI_ISO
  222. // #define CONFIG_USB_EHCI_WITH_OHCI
  223. // #define CONFIG_USB_EHCI_DESC_DCACHE_ENABLE
  224. /* ---------------- OHCI Configuration ---------------- */
  225. #define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
  226. #define CONFIG_USB_OHCI_ED_NUM 10
  227. #define CONFIG_USB_OHCI_TD_NUM 3
  228. // #define CONFIG_USB_OHCI_DESC_DCACHE_ENABLE
  229. /* ---------------- XHCI Configuration ---------------- */
  230. #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
  231. /* ---------------- DWC2 Configuration ---------------- */
  232. // nothing to define
  233. /* ---------------- MUSB Configuration ---------------- */
  234. #define CONFIG_USB_MUSB_PIPE_NUM 8
  235. // #define CONFIG_USB_MUSB_SUNXI
  236. /* When your chip hardware supports high-speed and wants to initialize it in high-speed mode,
  237. * the relevant IP will configure the internal or external high-speed PHY according to CONFIG_USB_HS.
  238. *
  239. * in xxx32 chips, only pb14/pb15 can support hs mode, pa11/pa12 is not supported(only a few supports, but we ignore them).
  240. */
  241. // #define CONFIG_USB_HS
  242. #ifndef usb_phyaddr2ramaddr
  243. #define usb_phyaddr2ramaddr(addr) (addr)
  244. #endif
  245. #ifndef usb_ramaddr2phyaddr
  246. #define usb_ramaddr2phyaddr(addr) (addr)
  247. #endif
  248. #endif