From 0556ae199bd5dbe28b2878db28a579b0582a6c90 Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Mon, 29 Apr 2024 11:46:31 +0800 Subject: [PATCH] add config for cdc ncm transfer size --- cherryusb_config_template.h | 10 ++++++++++ class/cdc/usbh_cdc_ncm.c | 14 +++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cherryusb_config_template.h b/cherryusb_config_template.h index be53afa8..11a42195 100644 --- a/cherryusb_config_template.h +++ b/cherryusb_config_template.h @@ -149,6 +149,16 @@ #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048) #endif +/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size, + * you can change with 2K,4K,8K,16K,default is 2K to get one TCP_MSS + */ +#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE +#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048) +#endif +#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE +#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048) +#endif + #define CONFIG_USBHOST_BLUETOOTH_HCI_H4 // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG diff --git a/class/cdc/usbh_cdc_ncm.c b/class/cdc/usbh_cdc_ncm.c index 7723da2d..dd3e0d92 100644 --- a/class/cdc/usbh_cdc_ncm.c +++ b/class/cdc/usbh_cdc_ncm.c @@ -23,8 +23,16 @@ #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_SEGSZE 1514U -static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_rx_buffer[2048]; -static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_tx_buffer[2048]; +/* eth rx size must be a multiple of 512 or 64 */ +#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE +#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048) +#endif +#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE +#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048) +#endif + +static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_rx_buffer[CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE]; +static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_tx_buffer[CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE]; static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_inttx_buffer[16]; USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_buf[32]; @@ -344,7 +352,7 @@ err_t usbh_cdc_ncm_linkoutput(struct netif *netif, struct pbuf *p) } struct cdc_ncm_nth16 *nth16 = (struct cdc_ncm_nth16 *)&g_cdc_ncm_tx_buffer[0]; - + nth16->dwSignature = CDC_NCM_NTH16_SIGNATURE; nth16->wHeaderLength = 12; nth16->wSequence = g_cdc_ncm_class.bulkout_sequence++;