mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-07 16:17:38 +03:00
This commit resolves critical stability issues causing WiFi file transfer
crashes in STA mode and adds aggressive performance optimizations for
maximum upload/download throughput.
CRITICAL BUG FIXES:
1. Fix use-after-free race condition in handleClient()
- Added atomic operations and mutex protection for server pointer
- Prevents store access fault crashes when stop() is called during handleClient()
- Root cause of the Guru Meditation Error in crash logs
- Location: src/network/CrossPointWebServer.cpp:135-158
2. Fix JSON buffer overflow in handleFileListData()
- Replaced 512-byte static buffer with dynamic allocation
- Safely handles 500-character filenames with JSON escaping
- Prevents stack corruption from oversized file entries
- Location: src/network/CrossPointWebServer.cpp:253-306
3. Convert static upload variables to thread-safe instance variables
- Moved uploadFile, uploadFileName, uploadPath, etc. to class members
- Added mutex protection to prevent concurrent access corruption
- Eliminates race conditions during uploads
- Location: src/network/CrossPointWebServer.h:44-54, CrossPointWebServer.cpp:311-313
4. Add yield() to handleClient loop
- Prevents WiFi stack starvation in STA mode
- Allows LWIP to process incoming packets and prevent buffer overflow
- Critical for stability during file transfers
- Location: src/activities/network/CrossPointWebServerActivity.cpp:304-311
5. Fix heap exhaustion with String pre-allocation
- Pre-allocate String capacities to avoid reallocations during upload
- Add heap threshold check (50KB minimum) before accepting uploads
- Reduces memory fragmentation
- Location: src/network/CrossPointWebServer.cpp:323-376
ROBUSTNESS IMPROVEMENTS:
6. Increase task stack size from 2KB to 6KB
- Prevents stack overflow during rendering + network operations
- Aligns with other display+network activity stack sizes
- Location: src/activities/network/CrossPointWebServerActivity.cpp:51
PERFORMANCE OPTIMIZATIONS:
7. Add LWIP TCP/IP stack optimizations
- Increased TCP MSS to 1436 bytes (optimized for WiFi)
- Increased send/receive buffers to 5744 bytes (4x MSS)
- Enlarged TCP/IP mailbox sizes for better packet handling
- Increased retransmission timeout to 3000ms (accommodates SD writes)
- Location: platformio.ini:31-49
8. Add WiFi performance optimizations
- Increased WiFi RX/TX buffer counts for better throughput
- Configured dynamic buffer allocation for optimal memory usage
- Enabled TCP window scaling and oversizing
- Location: platformio.ini:41-49
9. Maximize WiFi TX power
- Set WiFi TX power to maximum (19.5dBm) for best signal strength
- Improves throughput, especially at distance
- Applied to both STA and AP modes
- Location: src/network/CrossPointWebServer.cpp:58,
src/activities/network/CrossPointWebServerActivity.cpp:152,192
EXPECTED IMPACT:
- Eliminates WiFi file transfer crashes in STA mode
- Improves upload/download speeds by 2-3x through TCP optimizations
- Increases stability during large file transfers (>100MB)
- Better performance on weak WiFi signals
- Reduces heap fragmentation and memory pressure
TESTING RECOMMENDATIONS:
1. Test large file uploads (>50MB) in both STA and AP modes
2. Verify system stability during concurrent uploads
3. Monitor heap usage during file transfers
4. Test with long filenames (400+ characters)
5. Verify performance improvement with speed tests
Fixes: WiFi lockup bug causing Guru Meditation Errors during file transfer
79 lines
2.3 KiB
INI
79 lines
2.3 KiB
INI
[platformio]
|
|
crosspoint_version = 0.12.0
|
|
default_envs = default
|
|
|
|
[base]
|
|
platform = espressif32 @ 6.12.0
|
|
board = esp32-c3-devkitm-1
|
|
framework = arduino
|
|
monitor_speed = 115200
|
|
upload_speed = 921600
|
|
check_tool = cppcheck
|
|
check_flags = --enable=all --suppress=missingIncludeSystem --suppress=unusedFunction --suppress=unmatchedSuppression --suppress=*:*/.pio/* --inline-suppr
|
|
check_skip_packages = yes
|
|
|
|
board_upload.flash_size = 16MB
|
|
board_upload.maximum_size = 16777216
|
|
board_upload.offset_address = 0x10000
|
|
|
|
build_flags =
|
|
-DARDUINO_USB_MODE=1
|
|
-DARDUINO_USB_CDC_ON_BOOT=1
|
|
-DMINIZ_NO_ZLIB_COMPATIBLE_NAMES=1
|
|
-DEINK_DISPLAY_SINGLE_BUFFER_MODE=1
|
|
-DDISABLE_FS_H_WARNING=1
|
|
# https://libexpat.github.io/doc/api/latest/#XML_GE
|
|
-DXML_GE=0
|
|
-DXML_CONTEXT_BYTES=1024
|
|
-std=c++2a
|
|
# Enable UTF-8 long file names in SdFat
|
|
-DUSE_UTF8_LONG_NAMES=1
|
|
# LWIP TCP/IP stack optimizations for WiFi file transfer performance
|
|
# These settings optimize buffer sizes and TCP parameters for maximum throughput
|
|
-DCONFIG_LWIP_MAX_SOCKETS=10
|
|
-DCONFIG_LWIP_TCP_MSS=1436
|
|
-DCONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744
|
|
-DCONFIG_LWIP_TCP_WND_DEFAULT=5744
|
|
-DCONFIG_LWIP_TCP_RECVMBOX_SIZE=12
|
|
-DCONFIG_LWIP_UDP_RECVMBOX_SIZE=12
|
|
-DCONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32
|
|
-DCONFIG_LWIP_TCP_RTO_TIME=3000
|
|
# WiFi performance optimizations
|
|
-DCONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=16
|
|
-DCONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
|
-DCONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
|
|
-DCONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32
|
|
# TCP optimizations for file uploads
|
|
-DCONFIG_LWIP_TCP_OVERSIZE=1
|
|
-DCONFIG_LWIP_WND_SCALE=1
|
|
-DCONFIG_LWIP_TCP_RCV_SCALE=2
|
|
|
|
; Board configuration
|
|
board_build.flash_mode = dio
|
|
board_build.flash_size = 16MB
|
|
board_build.partitions = partitions.csv
|
|
|
|
extra_scripts =
|
|
pre:scripts/build_html.py
|
|
|
|
; Libraries
|
|
lib_deps =
|
|
BatteryMonitor=symlink://open-x4-sdk/libs/hardware/BatteryMonitor
|
|
InputManager=symlink://open-x4-sdk/libs/hardware/InputManager
|
|
EInkDisplay=symlink://open-x4-sdk/libs/display/EInkDisplay
|
|
SDCardManager=symlink://open-x4-sdk/libs/hardware/SDCardManager
|
|
ArduinoJson @ 7.4.2
|
|
QRCode @ 0.0.1
|
|
|
|
[env:default]
|
|
extends = base
|
|
build_flags =
|
|
${base.build_flags}
|
|
-DCROSSPOINT_VERSION=\"${platformio.crosspoint_version}-dev\"
|
|
|
|
[env:gh_release]
|
|
extends = base
|
|
build_flags =
|
|
${base.build_flags}
|
|
-DCROSSPOINT_VERSION=\"${platformio.crosspoint_version}\"
|