1 /* 2 * Copyright : (C) 2024 Phytium Information Technology, Inc. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Modify History: 7 * Ver Who Date Changes 8 * ----- ------ -------- -------------------------------------- 9 * 1.0 zhugengyu 2024/6/26 first commit 10 */ 11 #ifndef CHERRYUSB_CONFIG_H 12 #define CHERRYUSB_CONFIG_H 13 14 #include "rtthread.h" 15 16 /* ================ USB common Configuration ================ */ 17 18 #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__) 19 20 void *xhci_mem_malloc(size_t align, size_t size); 21 void xhci_mem_free(void *ptr); 22 23 #define XHCI_DCACHE_FLUSH (1 << 0) 24 #define XHCI_DCACHE_INVALIDATE (1 << 1) 25 void xhci_dcache_sync(void *ptr, size_t len, uint32_t flags); 26 27 unsigned long usb_hc_get_register_base(uint32_t id); 28 29 #define usb_malloc(size) xhci_mem_malloc(sizeof(int), size) 30 #define usb_free(ptr) xhci_mem_free(ptr) 31 32 #ifndef CONFIG_USB_DBG_LEVEL 33 #if defined(CONFIG_LOG_ERROR) 34 #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR 35 #elif defined(CONFIG_LOG_WARN) 36 #define CONFIG_USB_DBG_LEVEL USB_DBG_WARNING 37 #elif defined(CONFIG_LOG_INFO) 38 #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO 39 #elif defined(CONFIG_LOG_DEBUG) || defined(CONFIG_LOG_VERBOS) 40 #define CONFIG_USB_DBG_LEVEL USB_DBG_LOG 41 #else 42 #define CONFIG_USB_DBG_LEVEL USB_DBG_ERROR 43 #endif 44 #endif 45 46 /* Enable print with color */ 47 #define CONFIG_USB_PRINTF_COLOR_ENABLE 48 49 /* data align size when use dma */ 50 #ifndef CONFIG_USB_ALIGN_SIZE 51 #define CONFIG_USB_ALIGN_SIZE 4 52 #endif 53 54 /* attribute data into no cache ram */ 55 #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable"))) 56 57 /* ================= USB Device Stack Configuration ================ */ 58 59 /* Ep0 in and out transfer buffer */ 60 #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN 61 #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512 62 #endif 63 64 /* Setup packet log for debug */ 65 // #define CONFIG_USBDEV_SETUP_LOG_PRINT 66 67 /* Send ep0 in data from user buffer instead of copying into ep0 reqdata 68 * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE 69 */ 70 // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY 71 72 /* Check if the input descriptor is correct */ 73 // #define CONFIG_USBDEV_DESC_CHECK 74 75 /* Enable test mode */ 76 // #define CONFIG_USBDEV_TEST_MODE 77 78 #ifndef CONFIG_USBDEV_MSC_MAX_LUN 79 #define CONFIG_USBDEV_MSC_MAX_LUN 1 80 #endif 81 82 #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE 83 #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512 84 #endif 85 86 #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING 87 #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING "" 88 #endif 89 90 #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING 91 #define CONFIG_USBDEV_MSC_PRODUCT_STRING "" 92 #endif 93 94 #ifndef CONFIG_USBDEV_MSC_VERSION_STRING 95 #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01" 96 #endif 97 98 // #define CONFIG_USBDEV_MSC_THREAD 99 100 #ifndef CONFIG_USBDEV_MSC_PRIO 101 #define CONFIG_USBDEV_MSC_PRIO 4 102 #endif 103 104 #ifndef CONFIG_USBDEV_MSC_STACKSIZE 105 #define CONFIG_USBDEV_MSC_STACKSIZE 2048 106 #endif 107 108 #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 109 #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156 110 #endif 111 112 /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/ 113 #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 114 #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580 115 #endif 116 117 #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID 118 #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff 119 #endif 120 121 #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC 122 #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB" 123 #endif 124 125 #define CONFIG_USBDEV_RNDIS_USING_LWIP 126 127 /* ================ USB HOST Stack Configuration ================== */ 128 129 #define CONFIG_USBHOST_MAX_RHPORTS 8 130 #define CONFIG_USBHOST_MAX_EXTHUBS 4 131 #define CONFIG_USBHOST_MAX_EHPORTS 8 132 #define CONFIG_USBHOST_MAX_INTERFACES 8 133 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8 134 #define CONFIG_USBHOST_MAX_ENDPOINTS 8 135 136 #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4 137 #define CONFIG_USBHOST_MAX_HID_CLASS 4 138 #define CONFIG_USBHOST_MAX_MSC_CLASS 2 139 #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1 140 #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1 141 142 #define CONFIG_USBHOST_DEV_NAMELEN 16 143 144 #ifndef CONFIG_USBHOST_PSC_PRIO 145 #define CONFIG_USBHOST_PSC_PRIO 0 146 #endif 147 #ifndef CONFIG_USBHOST_PSC_STACKSIZE 148 #define CONFIG_USBHOST_PSC_STACKSIZE 8192 149 #endif 150 151 //#define CONFIG_USBHOST_GET_STRING_DESC 152 153 // #define CONFIG_USBHOST_MSOS_ENABLE 154 #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE 155 #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00 156 #endif 157 158 /* Ep0 max transfer buffer */ 159 #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN 160 #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512 161 #endif 162 163 #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 164 #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500 165 #endif 166 167 #ifndef CONFIG_USBHOST_MSC_TIMEOUT 168 #define CONFIG_USBHOST_MSC_TIMEOUT 0xffffffff 169 #endif 170 171 #ifndef CONFIG_INPUT_MOUSE_WHEEL 172 #define CONFIG_INPUT_MOUSE_WHEEL 173 #endif 174 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_RNDIS_ETH_MAX_RX_SIZE 179 #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048) 180 #endif 181 182 /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */ 183 #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE 184 #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048) 185 #endif 186 187 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size, 188 * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow. 189 */ 190 #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE 191 #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048) 192 #endif 193 /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */ 194 #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE 195 #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048) 196 #endif 197 198 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size, 199 * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow. 200 */ 201 #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE 202 #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048) 203 #endif 204 /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */ 205 #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE 206 #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048) 207 #endif 208 209 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size, 210 * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow. 211 */ 212 #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE 213 #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048) 214 #endif 215 /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */ 216 #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE 217 #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048) 218 #endif 219 220 #define CONFIG_USBHOST_BLUETOOTH_HCI_H4 221 // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG 222 223 #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE 224 #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048 225 #endif 226 #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE 227 #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048 228 #endif 229 230 /* ================ USB Device Port Configuration ================*/ 231 232 #ifndef CONFIG_USBDEV_MAX_BUS 233 #define CONFIG_USBDEV_MAX_BUS 2 // for now, bus num must be 1 except hpm ip 234 #endif 235 236 #ifndef CONFIG_USBDEV_EP_NUM 237 #define CONFIG_USBDEV_EP_NUM 8 238 #endif 239 240 /* ---------------- FSDEV Configuration ---------------- */ 241 //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference 242 243 /* ---------------- DWC2 Configuration ---------------- */ 244 // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4) 245 // #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4) 246 // #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4) 247 // #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4) 248 // #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4) 249 // #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4) 250 // #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4) 251 // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4) 252 // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4) 253 // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4) 254 255 /* ---------------- MUSB Configuration ---------------- */ 256 // #define CONFIG_USB_MUSB_SUNXI 257 258 /* ================ USB Host Port Configuration ==================*/ 259 #ifndef CONFIG_USBHOST_MAX_BUS 260 #define CONFIG_USBHOST_MAX_BUS 2 261 #endif 262 263 #ifndef CONFIG_USBHOST_PIPE_NUM 264 #define CONFIG_USBHOST_PIPE_NUM 10 265 #endif 266 267 /* ---------------- EHCI Configuration ---------------- */ 268 269 #define CONFIG_USB_EHCI_HCCR_OFFSET (0x0) 270 #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024 271 #define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM 272 #define CONFIG_USB_EHCI_QTD_NUM 3 273 #define CONFIG_USB_EHCI_ITD_NUM 20 274 // #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE 275 // #define CONFIG_USB_EHCI_CONFIGFLAG 276 // #define CONFIG_USB_EHCI_ISO 277 // #define CONFIG_USB_EHCI_WITH_OHCI 278 279 /* ---------------- OHCI Configuration ---------------- */ 280 #define CONFIG_USB_OHCI_HCOR_OFFSET (0x0) 281 282 /* ---------------- XHCI Configuration ---------------- */ 283 #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0) 284 285 #ifndef CONFIG_USB_XHCI_ENABLE_SOFT_ISR 286 #define CONFIG_USB_XHCI_ENABLE_SOFT_ISR 0 287 #endif 288 289 #endif 290