Skip to content

Commit 111929a

Browse files
committed
Merge branch 'feat/usb_wireless_disk_4bit_sdcard' into 'master'
feat: improve usb wireless disk performance Closes AEG-2710 See merge request ae_group/esp-iot-solution!1358
2 parents 38107bc + 27fe099 commit 111929a

File tree

19 files changed

+2086
-139
lines changed

19 files changed

+2086
-139
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"]

components/sensors/humiture/aht20/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ I2C driver and definition of AHT20 humidity and temperature sensor.
55

66
Components compatible with AHT30 and AHT21 (AHT21 is deprecated).
77

8-
See [AHT20 datasheet](http://www.aosong.com/en/products-32.html), [AHT30 datasheet](http://www.aosong.com/en/products-131.html).
8+
See [AHT20 datasheet](https://asairsensors.com/wp-content/uploads/2021/09/Data-Sheet-AHT20-Humidity-and-Temperature-Sensor-ASAIR-V1.0.03.pdf), [AHT30 datasheet](https://asairsensors.com/product/aht30-integrated-temperature-and-humidity-sensor/).
99

1010
## Usage
1111

examples/camera/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The APIs included in the [esp32-camera](https://github.com/espressif/esp32-camer
7878
Convert image buffer to RGB565 buffer.
7979

8080
### Header File
81-
- [esp32-camera/conversions/include/esp_jpg_decode.h](https://github.com/espressif/esp32-camera/blob/master/conversions/include/esp_jpg_decode.h)
81+
- [esp32-camera/conversions/include/esp_jpg_decode.h](https://github.com/espressif/esp32-camera/blob/v2.0.0/conversions/include/esp_jpg_decode.h)
8282
#### Functions
8383
- `esp_err_t esp_jpg_decode(size_t len, jpg_scale_t scale, jpg_reader_cb reader, jpg_writer_cb writer, void * arg)`
8484
JPEG scaling function.

examples/usb/device/usb_extend_screen/components/espressif__esp_lvgl_port/examples/touchscreen/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Very simple example for demonstration of initialization and usage of the `esp_lv
44

55
## 1. LCD HW initialization - `app_lcd_init()`
66

7-
Standard HW initialization of the LCD using [`esp_lcd`](https://github.com/espressif/esp-idf/tree/master/components/esp_lcd) component. Settings of this example are fully compatible with [ESP-BOX](https://github.com/espressif/esp-bsp/tree/master/esp-box) board.
7+
Standard HW initialization of the LCD using [`esp_lcd`](https://github.com/espressif/esp-idf/tree/master/components/esp_lcd) component. Settings of this example are fully compatible with [ESP-BOX](https://github.com/espressif/esp-bsp/tree/master/bsp/esp-box-3) board.
88

99
## 2. Touch HW initialization - `app_touch_init()`
1010

11-
Standard HW initialization of the LCD touch using [`esp_lcd_touch`](https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch) component. Settings of this example are fully compatible with [ESP-BOX](https://github.com/espressif/esp-bsp/tree/master/esp-box) board.
11+
Standard HW initialization of the LCD touch using [`esp_lcd_touch`](https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch) component. Settings of this example are fully compatible with [ESP-BOX](https://github.com/espressif/esp-bsp/tree/master/bsp/esp-box-3) board.
1212

1313
## 3. LVGL port initialization - `app_lvgl_init()`
1414

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: 145 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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,51 +48,184 @@ 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 512
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

5372
config SDCARD_SPI_CS_PIN
5473
int "SD Card SPI CS pin"
5574
depends on SDCARD_INTFC_SPI
56-
default 34
75+
default 34 if ESP32_S3_USB_OTG
76+
default 10
5777

5878
config SDCARD_SPI_CLK_PIN
5979
int "SD Card SPI CLK pin"
6080
depends on SDCARD_INTFC_SPI
61-
default 36
81+
default 36 if ESP32_S3_USB_OTG
82+
default 12
6283

6384
config SDCARD_SPI_DI_PIN
6485
int "SD Card SPI DI pin"
6586
depends on SDCARD_INTFC_SPI
66-
default 35
87+
default 35 if ESP32_S3_USB_OTG
88+
default 11
6789

6890
config SDCARD_SPI_DO_PIN
6991
int "SD Card SPI DO pin"
7092
depends on SDCARD_INTFC_SPI
71-
default 37
93+
default 37 if ESP32_S3_USB_OTG
94+
default 13
7295

73-
config SDCARD_SDIO_DO_PIN
74-
int "SD Card SDIO DO pin"
96+
config SDCARD_SDIO_D0_PIN
97+
int "SD Card SDIO D0 pin"
7598
depends on SDCARD_INTFC_SDIO
76-
default 37
99+
default 37 if ESP32_S3_USB_OTG
100+
default 13
77101

78102
config SDCARD_SDIO_CMD_PIN
79103
int "SD Card SDIO CMD pin"
80104
depends on SDCARD_INTFC_SDIO
81-
default 35
105+
default 35 if ESP32_S3_USB_OTG
106+
default 11
82107

83108
config SDCARD_SDIO_CLK_PIN
84109
int "SD Card SDIO CLK pin"
85110
depends on SDCARD_INTFC_SDIO
86-
default 36
111+
default 36 if ESP32_S3_USB_OTG
112+
default 12
113+
114+
choice SDCARD_SDIO_DATA_WIDTH
115+
prompt "SDIO Data Width"
116+
depends on SDCARD_INTFC_SDIO
117+
default SDCARD_SDIO_DATA_WIDTH_4 if ESP32_S3_USB_OTG
118+
default SDCARD_SDIO_DATA_WIDTH_1
119+
help
120+
Select SDIO bus width: 1-line or 4-line.
121+
122+
config SDCARD_SDIO_DATA_WIDTH_1
123+
bool "1-line mode"
124+
125+
config SDCARD_SDIO_DATA_WIDTH_4
126+
bool "4-line mode"
127+
endchoice
128+
129+
config SDCARD_SDIO_D1_PIN
130+
int "SD Card SDIO D1 pin (for 4-line)"
131+
depends on SDCARD_INTFC_SDIO && SDCARD_SDIO_DATA_WIDTH_4
132+
default 38 if ESP32_S3_USB_OTG
133+
default 14
134+
135+
config SDCARD_SDIO_D2_PIN
136+
int "SD Card SDIO D2 pin (for 4-line)"
137+
depends on SDCARD_INTFC_SDIO && SDCARD_SDIO_DATA_WIDTH_4
138+
default 33 if ESP32_S3_USB_OTG
139+
default 9
140+
141+
config SDCARD_SDIO_D3_PIN
142+
int "SD Card SDIO D3 pin (for 4-line)"
143+
depends on SDCARD_INTFC_SDIO && SDCARD_SDIO_DATA_WIDTH_4
144+
default 34 if ESP32_S3_USB_OTG
145+
default 10
87146
endmenu
88147
endchoice
89148

90149
config WIFI_HTTP_ACCESS
91150
bool "Enable WiFi HTTP files server"
92151
default y
93152

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+
94229
menu "WiFi Settings"
95230
config ESP_WIFI_ROUTE_SSID
96231
string "WiFi Route SSID"

0 commit comments

Comments
 (0)