Skip to content

Commit 4e57e78

Browse files
committed
feat(usb_wireless_disk): improve file upload performance
1 parent dc0f7e6 commit 4e57e78

16 files changed

+2020
-124
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,5 @@ output.json
123123

124124
#components cache
125125
**/dist/
126+
127+
*.log

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ default_install_hook_types: [pre-commit,commit-msg]
66

77
repos:
88
- repo: https://github.com/espressif/check-copyright/
9-
rev: v1.0.3
9+
rev: v1.1.1
1010
hooks:
1111
- id: check-copyright
1212
args: ['--config', 'tools/ci/check_copyright_config.yaml', '--ignore', 'tools/ci/check_copyright_ignore.txt']
1313
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: v4.6.0
14+
rev: v6.0.0
1515
hooks:
1616
- id: file-contents-sorter
1717
files: 'tools\/ci\/(executable-list\.txt|check_copyright_ignore\.txt)'
1818
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v4.6.0
19+
rev: v6.0.0
2020
hooks:
2121
- id: trailing-whitespace
2222
# note: whitespace exclusions use multiline regex, see https://pre-commit.com/#regular-expressions
@@ -53,7 +53,7 @@ repos:
5353
name: Do not use uppercase letters in the branch name
5454
args: ['--pattern', '^[^A-Z]*[A-Z]']
5555
- repo: https://github.com/espressif/astyle_py.git
56-
rev: v1.0.5
56+
rev: v1.1.0
5757
hooks:
5858
- id: astyle_py
5959
# If you are modifying astyle version, update tools/format.sh as well
@@ -83,15 +83,15 @@ repos:
8383
- pyyaml
8484
always_run: true
8585
- repo: https://github.com/espressif/conventional-precommit-linter
86-
rev: v1.8.0
86+
rev: v1.10.0
8787
hooks:
8888
- id: conventional-precommit-linter
8989
stages: [commit-msg]
9090
args:
9191
- --subject-min-length=15
9292
- --body-max-line-length=200
9393
- repo: https://github.com/codespell-project/codespell
94-
rev: v2.3.0
94+
rev: v2.4.1
9595
hooks:
9696
- id: codespell
9797
args: [-w, "--ignore-words=codespell-ignore-list", "--skip=*.js,*.vue,*/pnpm-lock.yaml,*/package-lock.json,*/yarn.lock,*.base64"]

examples/usb/device/usb_msc_wireless_disk/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,46 @@ This demo has enabled FATFS OEM multi-code page support. To manually adjust mult
4949
- This option controls the encoding method used by the filenames read by the FATFS API. For more details, please refer to the configuration help.
5050
- For web development, it is recommended to use UTF-8 encoding.
5151

52+
### Wireless Transfer Rate Optimization
53+
54+
**For optimal wireless access speeds, it is strongly recommended to use chips or modules with PSRAM, particularly ESP32-S3 equipped with 8MB or larger octal (OCT) PSRAM.**
55+
56+
#### Performance Test Results
57+
58+
The following chart shows the HTTP file upload speed analysis results with optimized configurations:
59+
60+
![ESP HTTP File Upload Speed Analysis](./tools/upload_test_20250826_150059_analysis_20250826_151202.png)
61+
62+
*Test results show an average upload speed of 4.24 MB/s with a maximum speed of 4.61 MB/s across 100 upload tests.*
63+
64+
You can further improve wireless file upload and download speeds using the following methods:
65+
66+
1. **Wi-Fi Configuration Optimization** (RAM impact: High)
67+
- The following parameters have been configured in the `sdkconfig.defaults.r8` file:
68+
- `CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=16`: Increases the number of static receive buffers (approx. 1.6KB each)
69+
- `CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=85`: Increases the number of dynamic receive buffers (approx. 1.6KB each)
70+
- `CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=64`: Increases the number of dynamic transmit buffers (approx. 1.6KB each)
71+
- `CONFIG_ESP_WIFI_TX_BA_WIN=32` and `CONFIG_ESP_WIFI_RX_BA_WIN=32`: Enlarges the Block ACK window size
72+
- `CONFIG_ESP_WIFI_EXTRA_IRAM_OPT=y`: Enables additional IRAM optimization (reduces RAM usage but increases IRAM usage)
73+
74+
2. **TCP/IP Stack Optimization** (RAM impact: Medium-High)
75+
- `CONFIG_LWIP_TCPIP_TASK_PRIO=23`: Increases TCP/IP task priority (no RAM impact)
76+
- `CONFIG_LWIP_IRAM_OPTIMIZATION=y` and `CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION=y`: Enables LWIP IRAM optimization (increases IRAM usage)
77+
- `CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65535` and `CONFIG_LWIP_TCP_WND_DEFAULT=65535`: Enlarges TCP send and receive windows (significantly increases RAM usage per connection)
78+
- `CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64`: Increases TCP/IP receive mailbox size (moderate RAM impact)
79+
- `CONFIG_LWIP_TCP_RECVMBOX_SIZE=64` and `CONFIG_LWIP_UDP_RECVMBOX_SIZE=64`: Increases TCP and UDP receive mailbox sizes (moderate RAM impact)
80+
81+
3. **File Operation Buffer Optimization** (RAM impact: High)
82+
- `CONFIG_FILE_WRITE_BUFFER_COUNT=10`: Increases the number of write buffers
83+
- `CONFIG_FILE_WRITE_BUFFER_SIZE=128`: Increases the size of write buffers
84+
- `CONFIG_FILE_DMA_BUFFER_SIZE=32`: Sets DMA buffer size
85+
- Total RAM impact approx: 10 × 128 + 32 = 1312 KB
86+
87+
## Changelog
88+
89+
### 2025-08-25
90+
91+
- Support for 4-bit SD card interface
92+
- The file system employs asynchronous writing to enhance performance.
93+
- A section on optimizing wireless transmission rates has been added, along with detailed configuration guidelines.
94+

examples/usb/device/usb_msc_wireless_disk/README_cn.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,47 @@
4848
- 本例程默认为 <kbd>API uses UTF-8 encoding</kbd> (`FATFS_API_ENCODING_UTF_8`)。
4949
- 该选项控制 FATFS API 读出的文件名所使用的编码方式,详见该配置项的说明。
5050
- 若进行 Web 开发,建议使用 UTF 8 编码。
51+
52+
### 无线传输速率优化
53+
54+
**如果您希望获得最佳的无线访问速度,强烈推荐选择带有 PSRAM 的芯片或模组,特别是配备 8MB 及以上容量、8 线(OCT)PSRAM 的 ESP32-S3。**
55+
56+
#### 性能测试结果
57+
58+
以下图表显示了使用优化配置后的 HTTP 文件上传速度分析结果:
59+
60+
![ESP HTTP File Upload Speed Analysis](./tools/upload_test_20250826_150059_analysis_20250826_151202.png)
61+
62+
*测试结果显示,在 100 次上传测试中,平均上传速度为 4.24 MB/s,最大速度达到 4.61 MB/s。*
63+
64+
通过以下方式可以进一步提高无线文件上传和下载的速度:
65+
66+
1. **Wi-Fi 配置优化** (RAM 开销: 高)
67+
-`sdkconfig.defaults.r8` 文件中已经配置了以下参数:
68+
- `CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=16`:增加静态接收缓冲区数量(每个缓冲区约 1.6KB)
69+
- `CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=85`:增加动态接收缓冲区数量(每个缓冲区约 1.6KB)
70+
- `CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=64`:增加动态发送缓冲区数量(每个缓冲区约 1.6KB)
71+
- `CONFIG_ESP_WIFI_TX_BA_WIN=32``CONFIG_ESP_WIFI_RX_BA_WIN=32`:增大 Block ACK 窗口大小
72+
- `CONFIG_ESP_WIFI_EXTRA_IRAM_OPT=y`:启用额外的 IRAM 优化(降低 RAM 使用但增加 IRAM 使用)
73+
74+
2. **TCP/IP 协议栈优化** (RAM 开销: 中高)
75+
- `CONFIG_LWIP_TCPIP_TASK_PRIO=23`:提高 TCP/IP 任务优先级(无 RAM 影响)
76+
- `CONFIG_LWIP_IRAM_OPTIMIZATION=y``CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION=y`:启用 LWIP 的 IRAM 优化(增加 IRAM 使用)
77+
- `CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65535``CONFIG_LWIP_TCP_WND_DEFAULT=65535`:增大 TCP 发送和接收窗口(显著增加每个连接的 RAM 使用)
78+
- `CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64`:增大 TCP/IP 接收邮箱大小(适度增加 RAM 使用)
79+
- `CONFIG_LWIP_TCP_RECVMBOX_SIZE=64``CONFIG_LWIP_UDP_RECVMBOX_SIZE=64`:增大 TCP 和 UDP 接收邮箱大小(适度增加 RAM 使用)
80+
81+
3. **文件操作缓冲区优化** (RAM 开销: 高)
82+
- `CONFIG_FILE_WRITE_BUFFER_COUNT=10`:增加写入缓冲区数量
83+
- `CONFIG_FILE_WRITE_BUFFER_SIZE=128`:增加写入缓冲区大小
84+
- `CONFIG_FILE_DMA_BUFFER_SIZE=32`:设置 DMA 缓冲区大小
85+
- 总计 RAM 开销约为: 10 × 128 + 32 = 1312 KB
86+
87+
## 变更日志
88+
89+
### 2025-08-25
90+
91+
- 支持 4-bit SD 卡接口
92+
- 文件系统使用异步写入以提升性能
93+
- 增加了无线传输速率优化章节,提供详细的配置指南
94+

examples/usb/device/usb_msc_wireless_disk/main/Kconfig.projbuild

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ menu "USB MSC Device Demo"
22

33
choice DEVELOPMENT_BOARD_SELECTION
44
prompt "Select the development board you are using"
5-
default ESP32_S3_GENERIC if IDF_TARGET_ESP32S3
5+
default ESP32_S3_USB_OTG if IDF_TARGET_ESP32S3
66
default ESP32_S2_GENERIC if IDF_TARGET_ESP32S2
77
help
88
Select this option to choose the board for the example.
@@ -23,6 +23,7 @@ menu "USB MSC Device Demo"
2323

2424
choice STORAGE_MEDIA
2525
prompt "Storage Media"
26+
default USE_EXTERNAL_SDCARD if ESP32_S3_USB_OTG
2627
default USE_INTERNAL_FLASH
2728

2829
config USE_INTERNAL_FLASH
@@ -34,6 +35,7 @@ menu "USB MSC Device Demo"
3435
choice SDCARD_INTERFACE
3536
prompt "SD Card Interface"
3637
depends on USE_EXTERNAL_SDCARD
38+
default SDCARD_INTFC_SDIO if ESP32_S3_USB_OTG
3739
default SDCARD_INTFC_SPI
3840

3941
config SDCARD_INTFC_SPI
@@ -46,7 +48,24 @@ menu "USB MSC Device Demo"
4648
config DISK_BLOCK_SIZE
4749
int "disk block size used for format"
4850
depends on USE_EXTERNAL_SDCARD
49-
default 8192
51+
range 512 32768
52+
default 16384
53+
help
54+
Block size used for formatting the disk. A larger block size can improve performance
55+
but may waste space on small files. Typical values are 4096 or 16384.
56+
57+
config FORMAT_IF_MOUNT_FAILED
58+
bool "Format file system if mount failed"
59+
default y
60+
help
61+
If this option is enabled, the file system will be formatted if mounting fails.
62+
63+
config FATFS_MAX_FILES
64+
int "Maximum number of open files"
65+
range 1 10
66+
default 3
67+
help
68+
Maximum number of files that can be open at the same time.
5069

5170
menu "SD Card PIN CONFIG"
5271

@@ -95,6 +114,7 @@ menu "USB MSC Device Demo"
95114
choice SDCARD_SDIO_DATA_WIDTH
96115
prompt "SDIO Data Width"
97116
depends on SDCARD_INTFC_SDIO
117+
default SDCARD_SDIO_DATA_WIDTH_4 if ESP32_S3_USB_OTG
98118
default SDCARD_SDIO_DATA_WIDTH_1
99119
help
100120
Select SDIO bus width: 1-line or 4-line.
@@ -130,6 +150,82 @@ menu "USB MSC Device Demo"
130150
bool "Enable WiFi HTTP files server"
131151
default y
132152

153+
config HTTP_UPLOAD_MAX_FILE_SIZE_MB
154+
int "Max upload file size (MB)"
155+
default -1
156+
depends on WIFI_HTTP_ACCESS
157+
help
158+
Set the maximum allowed file upload size in megabytes. Default is 20MB.
159+
Set to -1 for no limit.
160+
161+
config HTTP_REDIRECT_TO_ROOT
162+
bool "Redirect to root after file operations"
163+
default n
164+
depends on WIFI_HTTP_ACCESS
165+
help
166+
If enabled, after file upload or delete operations, the server will redirect to root path ("/").
167+
This will trigger a full disk scan to update the file list. Disable this on large file systems
168+
where scanning is slow.
169+
170+
config FILE_READ_BUFFER_SIZE
171+
int "Size of HTTP file read buffer (KB)"
172+
default 16
173+
range 4 128
174+
depends on WIFI_HTTP_ACCESS
175+
help
176+
Size of buffer used when reading files from storage during HTTP downloads in KB.
177+
This affects the chunk size sent to clients. Larger values may improve download speed
178+
but require more memory.
179+
180+
config FILE_WRITE_TASK_STACK_SIZE
181+
int "File write task stack size"
182+
default 4096
183+
depends on WIFI_HTTP_ACCESS
184+
help
185+
Stack size in bytes for the file write task.
186+
The task handles receiving data from the RingBuffer and
187+
writing it to the filesystem.
188+
189+
config FILE_WRITE_BUFFER_COUNT
190+
int "Number of RingBuffer items for file writes"
191+
default 3
192+
range 3 16
193+
depends on WIFI_HTTP_ACCESS
194+
help
195+
Number of items that can be stored in the RingBuffer.
196+
Higher values allow for more pending file chunks in the buffer,
197+
which can improve throughput with slower SD cards.
198+
199+
config FILE_WRITE_BUFFER_SIZE
200+
int "Size of each RingBuffer item (KB)"
201+
default 16
202+
range 16 512
203+
depends on WIFI_HTTP_ACCESS
204+
help
205+
Size of each RingBuffer item in KB. This determines the maximum
206+
size of each data chunk during file transfers. Larger values
207+
may improve throughput but require more memory.
208+
209+
config FILE_DMA_BUFFER_SIZE
210+
int "Size of DMA buffer for fwrite operations (KB)"
211+
default 32
212+
range 8 64
213+
depends on WIFI_HTTP_ACCESS
214+
help
215+
Size of DMA buffer for file write operations in KB (kilobytes).
216+
This buffer is used by the file system to improve write performance.
217+
Increasing this value can improve SD card write throughput.
218+
219+
config FILE_WRITE_TIMEOUT_MS
220+
int "File write timeout (milliseconds)"
221+
default -1
222+
range -1 300000
223+
depends on WIFI_HTTP_ACCESS
224+
help
225+
Maximum time to wait for file write completion in milliseconds.
226+
After this timeout, the HTTP upload will fail with a timeout error.
227+
Default is -1, which means wait indefinitely.
228+
133229
menu "WiFi Settings"
134230
config ESP_WIFI_ROUTE_SSID
135231
string "WiFi Route SSID"

0 commit comments

Comments
 (0)