From 80ecd7975a9a1874983894ca5ae32e35e97e9d2f Mon Sep 17 00:00:00 2001 From: "peter.marcisovsky" Date: Thu, 9 Jan 2025 18:58:36 +0100 Subject: [PATCH] fix(esp_tinyusb): Add possibility to configure NCM NTB buffers via menuconfig --- device/esp_tinyusb/CHANGELOG.md | 4 +++ device/esp_tinyusb/Kconfig | 45 ++++++++++++++++++++++++ device/esp_tinyusb/include/tusb_config.h | 8 ++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/device/esp_tinyusb/CHANGELOG.md b/device/esp_tinyusb/CHANGELOG.md index b7805b1e..a12544bb 100644 --- a/device/esp_tinyusb/CHANGELOG.md +++ b/device/esp_tinyusb/CHANGELOG.md @@ -1,3 +1,7 @@ +## [Unreleased] + +- esp_tinyusb: Added possibility to configure NCM Transfer Blocks (NTB) via menuconfig + ## 1.6.0 - CDC-ACM: Fixed memory leak on deinit diff --git a/device/esp_tinyusb/Kconfig b/device/esp_tinyusb/Kconfig index 0247e50d..409793b2 100644 --- a/device/esp_tinyusb/Kconfig +++ b/device/esp_tinyusb/Kconfig @@ -285,6 +285,51 @@ menu "TinyUSB Stack" config TINYUSB_NET_MODE_NONE bool "None" endchoice + + config TINYUSB_NCM_OUT_NTB_BUFFS_COUNT + int "Number of NCM NTB buffers for reception side" + depends on TINYUSB_NET_MODE_NCM + default 3 + range 1 6 + help + Number of NTB buffers for reception side. + Can be increased to improve performance and stability with the cost of additional RAM requirements. + Helps to mitigate "tud_network_can_xmit: request blocked" warning message when running NCM device. + + config TINYUSB_NCM_IN_NTB_BUFFS_COUNT + int "Number of NCM NTB buffers for transmission side" + depends on TINYUSB_NET_MODE_NCM + default 3 + range 1 6 + help + Number of NTB buffers for transmission side. + Can be increased to improve performance and stability with the cost of additional RAM requirements. + Helps to mitigate "tud_network_can_xmit: request blocked" warning message when running NCM device. + + config TINYUSB_NCM_OUT_NTB_BUFF_MAX_SIZE + int "NCM NTB Buffer size for reception size" + depends on TINYUSB_NET_MODE_NCM + default 8192 + range 1600 10240 + help + Size of NTB buffers on the reception side. The minimum size used by Linux is 2048 bytes. + NTB buffer size must be significantly larger than the MTU (Maximum Transmission Unit). + The typical default MTU size for Ethernet is 1500 bytes, plus an additional packet overhead. + To improve performance, the NTB buffer size should be large enough to fit multiple MTU-sized + frames in a single NTB buffer and it's length should be multiple of 4. + + config TINYUSB_NCM_IN_NTB_BUFF_MAX_SIZE + int "NCM NTB Buffer size for transmission size" + depends on TINYUSB_NET_MODE_NCM + default 8192 + range 1600 10240 + help + Size of NTB buffers on the transmission side. The minimum size used by Linux is 2048 bytes. + NTB buffer size must be significantly larger than the MTU (Maximum Transmission Unit). + The typical default MTU size for Ethernet is 1500 bytes, plus an additional packet overhead. + To improve performance, the NTB buffer size should be large enough to fit multiple MTU-sized + frames in a single NTB buffer and it's length should be multiple of 4. + endmenu # "Network driver (ECM/NCM/RNDIS)" menu "Vendor Specific Interface" diff --git a/device/esp_tinyusb/include/tusb_config.h b/device/esp_tinyusb/include/tusb_config.h index 32afa788..6fb564a9 100644 --- a/device/esp_tinyusb/include/tusb_config.h +++ b/device/esp_tinyusb/include/tusb_config.h @@ -1,6 +1,6 @@ /* * SPDX-FileCopyrightText: 2019 Ha Thach (tinyusb.org), - * SPDX-FileContributor: 2020-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileContributor: 2020-2025 Espressif Systems (Shanghai) CO LTD * SPDX-License-Identifier: MIT * * Copyright (c) 2019 Ha Thach (tinyusb.org), @@ -173,6 +173,12 @@ extern "C" { #define CFG_TUD_DFU_RUNTIME CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME #define CFG_TUD_BTH CONFIG_TINYUSB_BTH_ENABLED +// NCM NET Mode NTB buffers configuration +#define CFG_TUD_NCM_OUT_NTB_N CONFIG_TINYUSB_NCM_OUT_NTB_BUFFS_COUNT +#define CFG_TUD_NCM_IN_NTB_N CONFIG_TINYUSB_NCM_IN_NTB_BUFFS_COUNT +#define CFG_TUD_NCM_OUT_NTB_MAX_SIZE CONFIG_TINYUSB_NCM_OUT_NTB_BUFF_MAX_SIZE +#define CFG_TUD_NCM_IN_NTB_MAX_SIZE CONFIG_TINYUSB_NCM_IN_NTB_BUFF_MAX_SIZE + #ifdef __cplusplus } #endif