usb_config.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Copyright (c) 2022, sakumisu
  3. * Copyright (c) 2022-2025, HPMicro
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. */
  7. #ifndef CHERRYUSB_CONFIG_H
  8. #define CHERRYUSB_CONFIG_H
  9. #include "board.h"
  10. /* ================ USB common Configuration ================ */
  11. #ifdef __RTTHREAD__
  12. #include <rtthread.h>
  13. #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
  14. #else
  15. #define CONFIG_USB_PRINTF(...) printf(__VA_ARGS__)
  16. #endif
  17. #ifndef CONFIG_USB_DBG_LEVEL
  18. #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
  19. #endif
  20. #if defined(CONFIG_USB_DEVICE_FS) || defined(CONFIG_USB_DEVICE_FORCE_FULL_SPEED)
  21. #undef CONFIG_USB_HS
  22. #else
  23. #define CONFIG_USB_HS
  24. #endif
  25. /* Enable print with color */
  26. #define CONFIG_USB_PRINTF_COLOR_ENABLE
  27. /* #define CONFIG_USB_DCACHE_ENABLE */
  28. /* data align size when use dma or use dcache */
  29. #ifdef CONFIG_USB_DCACHE_ENABLE
  30. #define CONFIG_USB_ALIGN_SIZE HPM_L1C_CACHELINE_SIZE
  31. #else
  32. #define CONFIG_USB_ALIGN_SIZE 4
  33. #endif
  34. /* descriptor common define */
  35. #define USBD_VID 0x34B7 /* HPMicro VID */
  36. #define USBD_PID 0xFFFF
  37. #define USBD_MAX_POWER 200
  38. /* attribute data into no cache ram */
  39. #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable.non_init")))
  40. /* use usb_memcpy default for high performance but cost more flash memory.
  41. * And, arm libc has a bug that memcpy() may cause data misalignment when the size is not a multiple of 4.
  42. */
  43. /* #define CONFIG_USB_MEMCPY_DISABLE */
  44. /* ================= USB Device Stack Configuration ================ */
  45. /* Ep0 in and out transfer buffer */
  46. #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
  47. #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
  48. #endif
  49. /* Setup packet log for debug */
  50. /* #define CONFIG_USBDEV_SETUP_LOG_PRINT */
  51. /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
  52. * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
  53. */
  54. /* #define CONFIG_USBDEV_EP0_INDATA_NO_COPY */
  55. /* Check if the input descriptor is correct */
  56. /* #define CONFIG_USBDEV_DESC_CHECK */
  57. /* Enable test mode */
  58. #define CONFIG_USBDEV_TEST_MODE
  59. /* enable advance desc register api */
  60. #define CONFIG_USBDEV_ADVANCE_DESC
  61. /* move ep0 setup handler from isr to thread */
  62. /* #define CONFIG_USBDEV_EP0_THREAD */
  63. #ifndef CONFIG_USBDEV_EP0_PRIO
  64. #define CONFIG_USBDEV_EP0_PRIO 4
  65. #endif
  66. #ifndef CONFIG_USBDEV_EP0_STACKSIZE
  67. #define CONFIG_USBDEV_EP0_STACKSIZE 2048
  68. #endif
  69. #ifndef CONFIG_USBDEV_MSC_MAX_LUN
  70. #define CONFIG_USBDEV_MSC_MAX_LUN 1
  71. #endif
  72. #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
  73. #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
  74. #endif
  75. #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
  76. #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
  77. #endif
  78. #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
  79. #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
  80. #endif
  81. #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
  82. #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
  83. #endif
  84. /* move msc read & write from isr to while(1), you should call usbd_msc_polling in while(1) */
  85. /* #define CONFIG_USBDEV_MSC_POLLING */
  86. /* move msc read & write from isr to thread */
  87. /* #define CONFIG_USBDEV_MSC_THREAD */
  88. #ifndef CONFIG_USBDEV_MSC_PRIO
  89. #define CONFIG_USBDEV_MSC_PRIO 4
  90. #endif
  91. #ifndef CONFIG_USBDEV_MSC_STACKSIZE
  92. #define CONFIG_USBDEV_MSC_STACKSIZE 2048
  93. #endif
  94. #ifndef CONFIG_USBDEV_MTP_MAX_BUFSIZE
  95. #define CONFIG_USBDEV_MTP_MAX_BUFSIZE 2048
  96. #endif
  97. #ifndef CONFIG_USBDEV_MTP_MAX_OBJECTS
  98. #define CONFIG_USBDEV_MTP_MAX_OBJECTS 256
  99. #endif
  100. #ifndef CONFIG_USBDEV_MTP_MAX_PATHNAME
  101. #define CONFIG_USBDEV_MTP_MAX_PATHNAME 256
  102. #endif
  103. #define CONFIG_USBDEV_MTP_THREAD
  104. #ifndef CONFIG_USBDEV_MTP_PRIO
  105. #define CONFIG_USBDEV_MTP_PRIO 4
  106. #endif
  107. #ifndef CONFIG_USBDEV_MTP_STACKSIZE
  108. #define CONFIG_USBDEV_MTP_STACKSIZE 4096
  109. #endif
  110. #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
  111. #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
  112. #endif
  113. /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
  114. #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
  115. #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
  116. #endif
  117. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
  118. #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
  119. #endif
  120. #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
  121. #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "HPMicro"
  122. #endif
  123. #define CONFIG_USBDEV_RNDIS_USING_LWIP
  124. #define CONFIG_USBDEV_CDC_ECM_USING_LWIP
  125. /* ================ USB HOST Stack Configuration ================== */
  126. #define CONFIG_USBHOST_MAX_RHPORTS 1
  127. #define CONFIG_USBHOST_MAX_EXTHUBS 1
  128. #define CONFIG_USBHOST_MAX_EHPORTS 4
  129. #define CONFIG_USBHOST_MAX_INTERFACES 8
  130. #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 2
  131. #define CONFIG_USBHOST_MAX_ENDPOINTS 4
  132. #define CONFIG_USBHOST_MAX_SERIAL_CLASS 4
  133. #define CONFIG_USBHOST_MAX_HID_CLASS 4
  134. #define CONFIG_USBHOST_MAX_MSC_CLASS 2
  135. #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
  136. #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
  137. #define CONFIG_USBHOST_DEV_NAMELEN 16
  138. #ifndef CONFIG_USBHOST_PSC_PRIO
  139. #define CONFIG_USBHOST_PSC_PRIO 0
  140. #endif
  141. #ifndef CONFIG_USBHOST_PSC_STACKSIZE
  142. #define CONFIG_USBHOST_PSC_STACKSIZE 2048
  143. #endif
  144. /* #define CONFIG_USBHOST_GET_STRING_DESC */
  145. /* #define CONFIG_USBHOST_MSOS_ENABLE */
  146. #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
  147. #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
  148. #endif
  149. /* Ep0 max transfer buffer */
  150. #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
  151. #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 4096
  152. #endif
  153. #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
  154. #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
  155. #endif
  156. #ifndef CONFIG_USBHOST_MSC_TIMEOUT
  157. #define CONFIG_USBHOST_MSC_TIMEOUT 5000
  158. #endif
  159. #ifndef CONFIG_USBHOST_SERIAL_RX_SIZE
  160. #define CONFIG_USBHOST_SERIAL_RX_SIZE 2048
  161. #endif
  162. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  163. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  164. */
  165. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
  166. #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (16 * 1024)
  167. #endif
  168. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  169. #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
  170. #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
  171. #endif
  172. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  173. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  174. */
  175. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
  176. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
  177. #endif
  178. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  179. #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
  180. #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
  181. #endif
  182. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  183. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  184. */
  185. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
  186. #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
  187. #endif
  188. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  189. #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
  190. #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
  191. #endif
  192. /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
  193. * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
  194. */
  195. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
  196. #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
  197. #endif
  198. /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
  199. #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
  200. #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
  201. #endif
  202. #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
  203. /* #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG */
  204. #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
  205. #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
  206. #endif
  207. #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
  208. #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
  209. #endif
  210. /* ================ USB Device Port Configuration ================*/
  211. #define CONFIG_USBDEV_MAX_BUS USB_SOC_MAX_COUNT
  212. #ifndef CONFIG_HPM_USBD_BASE
  213. #define CONFIG_HPM_USBD_BASE HPM_USB0_BASE
  214. #endif
  215. #ifndef CONFIG_HPM_USBD_IRQn
  216. #define CONFIG_HPM_USBD_IRQn IRQn_USB0
  217. #endif
  218. /* ================ USB Host Port Configuration ==================*/
  219. #define CONFIG_USBHOST_MAX_BUS USB_SOC_MAX_COUNT
  220. #ifndef CONFIG_HPM_USBH_BASE
  221. #define CONFIG_HPM_USBH_BASE HPM_USB0_BASE
  222. #endif
  223. #ifndef CONFIG_HPM_USBH_IRQn
  224. #define CONFIG_HPM_USBH_IRQn IRQn_USB0
  225. #endif
  226. /* ================ EHCI Configuration ================ */
  227. #define CONFIG_USB_EHCI_HPMICRO (1)
  228. #define CONFIG_USB_EHCI_HCCR_OFFSET (0x100u)
  229. #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
  230. #define CONFIG_USB_EHCI_QH_NUM 10
  231. #define CONFIG_USB_EHCI_QTD_NUM 64
  232. /* ================ Addr Convert Configuration ==================*/
  233. #ifndef usb_phyaddr2ramaddr
  234. #define usb_phyaddr2ramaddr(addr) core_local_mem_to_sys_address(BOARD_RUNNING_CORE, addr)
  235. #endif
  236. #ifndef usb_ramaddr2phyaddr
  237. #define usb_ramaddr2phyaddr(addr) sys_address_to_core_local_mem(BOARD_RUNNING_CORE, addr)
  238. #endif
  239. #define ATTR_FAST_RAM_SECTION __attribute__((section(".fast")))
  240. // #define CONFIG_USB_EHCI_ISO
  241. #endif