cherryusb_config_template.h 10.0 KB

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