From 1931215068940d072e0e2a5b669f4daa82eb9650 Mon Sep 17 00:00:00 2001 From: shangjinlong Date: Thu, 29 Oct 2026 11:19:20 +0800 Subject: [PATCH] fix(cores3): preserve internal DMA memory for camera startup Move the 7 KiB LVGL task stack to PSRAM and require external stack support in the CoreS3 board profile. Limit the project DVP DMA setting to 8192 bytes and log DMA free memory and the largest contiguous block at startup. Extend host fault injection for stack allocation, readiness timeout, retryable cleanup, repeated attachment and pending display DMA callbacks. Update the memory documentation and validation matrix. Validation: CoreS3 video zh-CN and en-US ESP-IDF v5.5.2 builds and size checks; CoreS3 and ST7789 host tests with UBSan; formatting, SPDX and whitespace checks. ASan was unavailable because the host runtime crashed even for a minimal program. A user-provided device log confirms DVP initialization and stream startup with an 11776-byte largest DMA block. Frame upload and repeated lifecycle and audio/UI regressions still require real-device validation. --- CHANGELOG.md | 15 ++++- VENDORED_SOURCES.md | 6 +- .../boards/m5stack-core-s3/README.md | 3 + .../boards/m5stack-core-s3/board.cmake | 1 + .../boards/m5stack-core-s3/sdkconfig.defaults | 1 + .../adapters/lvgl/ili9342_lvgl_adapter.cc | 8 ++- .../src/drivers/video/cores3_camera_video.c | 13 +++++ docs/CORES3_UI.md | 17 ++++-- docs/CORES3_UI.zh-CN.md | 12 +++- docs/CORES3_VIDEO.md | 56 ++++++++++++++----- docs/CORES3_VIDEO.zh-CN.md | 44 +++++++++++---- docs/VALIDATION.md | 24 +++++++- main/Kconfig.projbuild | 7 +++ tests/cores3_pixel_ui/README.md | 10 +++- tests/cores3_pixel_ui/test_adapter.cc | 56 +++++++++++++++++-- tests/st7789_lifecycle/mocks/esp_heap_caps.h | 5 ++ tests/st7789_lifecycle/mocks/host_platform.h | 3 +- 17 files changed, 236 insertions(+), 45 deletions(-) create mode 100644 tests/st7789_lifecycle/mocks/esp_heap_caps.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 72b9d9e..ec17afa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -172,8 +172,8 @@ Versioning and Conventional Commits. RTM-to-LCD indicator handling and device-service response parsing. - Request CoreS3 DVP capture at most five times per second, holding capture buffers between samples so idle periods stop DMA and copying. The sensor retains its 20 fps timing and JPEG - uplink remains capped at 1 fps. Increase the DVP DMA configuration to 16,384 bytes - (15 KiB allocated for QVGA YUYV), and reduce shared UI activity animation to 5 fps. + uplink remains capped at 1 fps. Use an 8,192-byte DVP DMA configuration + (7.5 KiB allocated for QVGA YUYV), and reduce shared UI activity animation to 5 fps. - Count in-flight SPI callbacks across consecutive CoreS3 LVGL UI flushes so teardown waits for all pending transfers. @@ -224,6 +224,17 @@ Current build coverage, real-device results and unsupported features are tracked ### Fixed +- Move CoreS3's 7,168-byte LVGL task stack to PSRAM through the existing port's stack-capability + setting, preserving the internal display DMA stripe. Require external-stack support in the board + profile and log `ui_stack_bytes=7168 ui_stack=psram` during display initialization. This saves + 7 KiB of internal stack storage; real-device audio/video/UI, + provisioning and volume-persistence NVS regressions remain to be verified. +- Reduce CoreS3's contiguous internal DMA buffer requirement from 15 KiB to 7.5 KiB with a + project Kconfig default override without changing vendored driver code. Log the configured DMA + bound and free/largest internal DMA memory before stream startup and when streaming does not + start. A device still failed with 13,187 bytes free but a largest block of 5,120 bytes; this + footprint reduction alone did not resolve the allocation failure. The smaller buffer increases + DMA events per active frame and requires concurrent audio/UI validation. - Restrict batch-builder cleanup to dedicated, owned generated directories. Reject repository ancestors, source directories, symlink components, traversal and overlapping roots before any cleanup; preserve unmarked existing data and anchor child deletion to directory descriptors. diff --git a/VENDORED_SOURCES.md b/VENDORED_SOURCES.md index 0669107..e6f2be7 100644 --- a/VENDORED_SOURCES.md +++ b/VENDORED_SOURCES.md @@ -116,8 +116,10 @@ Firmware integration differences are limited to the active ESP32-S3 build: - The video components include only the GC0308 DVP path, native I2C SCCB, and the ESP32-S3 JPEG library. Local CMake/Kconfig replace registry metadata and pin component versions; sensor detection uses the static table, the default format is QVGA YUYV, and SCCB timeout is 100 ms. - The local DVP DMA-size default is 16,384 bytes with video enabled; the driver's frame alignment - allocates 15 KiB of internal DMA memory for QVGA YUYV. The platform supplies capture buffers + With video enabled, `main/Kconfig.projbuild` overrides the component's 16,384-byte DVP DMA-size + default with 8,192 bytes; the vendored Kconfig and driver remain unchanged. The driver's frame + alignment allocates 7,680 bytes (7.5 KiB) of contiguous internal DMA memory for QVGA YUYV. + The platform supplies capture buffers at most five times per second while retaining the sensor's 20 fps register configuration. Unused transports, sensors, examples, and registry caches are omitted. Video sources and the JPEG binary are linked only with `CONFIG_MYBOT_ENABLE_VIDEO=y`. diff --git a/components/mybot_platform/boards/m5stack-core-s3/README.md b/components/mybot_platform/boards/m5stack-core-s3/README.md index 38c1710..0eea552 100644 --- a/components/mybot_platform/boards/m5stack-core-s3/README.md +++ b/components/mybot_platform/boards/m5stack-core-s3/README.md @@ -22,6 +22,9 @@ DIN GPIO14、DOUT GPIO13;GPIO0 用于音频时钟,不作为配网按键。LCD SPI3 为 MOSI GPIO37、 SCLK GPIO36、CS GPIO3、DC GPIO35。 +LVGL 对象与 7 KiB UI 任务栈使用 PSRAM,显示条带仍使用 10 KiB 内部 DMA 内存。 +板级配置要求开启 `CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM`,为摄像头及音频保留内部内存。 + 无已保存的 Wi-Fi 信息时自动进入配网并显示热点名称、播放提示音。已有网络时联网后启动 MyBot;长按触摸会先停止 MyBot 再配网。设备音量保存在 NVS,重启后恢复。 diff --git a/components/mybot_platform/boards/m5stack-core-s3/board.cmake b/components/mybot_platform/boards/m5stack-core-s3/board.cmake index f61da21..84156cd 100644 --- a/components/mybot_platform/boards/m5stack-core-s3/board.cmake +++ b/components/mybot_platform/boards/m5stack-core-s3/board.cmake @@ -11,6 +11,7 @@ set(MYBOT_BOARD_REQUIRED_CONFIGS CONFIG_SPIRAM CONFIG_SPIRAM_MODE_QUAD CONFIG_SPIRAM_SPEED_80M + CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM CONFIG_CODEC_ES7210_SUPPORT CONFIG_CODEC_AW88298_SUPPORT ) diff --git a/components/mybot_platform/boards/m5stack-core-s3/sdkconfig.defaults b/components/mybot_platform/boards/m5stack-core-s3/sdkconfig.defaults index fddf22f..e82bdd9 100644 --- a/components/mybot_platform/boards/m5stack-core-s3/sdkconfig.defaults +++ b/components/mybot_platform/boards/m5stack-core-s3/sdkconfig.defaults @@ -10,6 +10,7 @@ CONFIG_ESPTOOLPY_FLASHMODE_QIO=y CONFIG_SPIRAM=y CONFIG_SPIRAM_MODE_QUAD=y CONFIG_SPIRAM_SPEED_80M=y +CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y CONFIG_CODEC_ES7210_SUPPORT=y CONFIG_CODEC_AW88298_SUPPORT=y diff --git a/components/mybot_platform/src/drivers/display/adapters/lvgl/ili9342_lvgl_adapter.cc b/components/mybot_platform/src/drivers/display/adapters/lvgl/ili9342_lvgl_adapter.cc index 094227e..4410b24 100644 --- a/components/mybot_platform/src/drivers/display/adapters/lvgl/ili9342_lvgl_adapter.cc +++ b/components/mybot_platform/src/drivers/display/adapters/lvgl/ili9342_lvgl_adapter.cc @@ -13,6 +13,7 @@ #include +#include "esp_heap_caps.h" #include "esp_lvgl_port.h" #include "esp_log.h" #include "esp_timer.h" @@ -240,6 +241,7 @@ int initialize(void **out_ctx) { port_config.task_priority = 1; port_config.task_affinity = 1; port_config.task_stack = UI_STACK_BYTES; + port_config.task_stack_caps = MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT; port_config.task_max_sleep_ms = 500; port_config.timer_period_ms = 5; lvgl_port_display_cfg_t config{}; @@ -302,9 +304,11 @@ int initialize(void **out_ctx) { result = 0; ESP_LOGI(TAG, "event=lcd action=initialize backend=lvgl result=ok width=%d height=%d " - "dma_bytes=%u ui_core=1 ui_priority=1 objects=psram", + "dma_bytes=%u ui_core=1 ui_priority=1 ui_stack_bytes=%u ui_stack=psram " + "objects=psram", MYBOT_DISPLAY_WIDTH, MYBOT_DISPLAY_HEIGHT, - (unsigned)(MYBOT_DISPLAY_WIDTH * ILI9342_LCD_TRANSFER_ROWS * sizeof(uint16_t))); + (unsigned)(MYBOT_DISPLAY_WIDTH * ILI9342_LCD_TRANSFER_ROWS * sizeof(uint16_t)), + (unsigned)UI_STACK_BYTES); done: if (result < 0) { ESP_LOGE(TAG, "event=lcd action=initialize backend=lvgl result=error"); diff --git a/components/mybot_platform/src/drivers/video/cores3_camera_video.c b/components/mybot_platform/src/drivers/video/cores3_camera_video.c index 45deff9..5badb07 100644 --- a/components/mybot_platform/src/drivers/video/cores3_camera_video.c +++ b/components/mybot_platform/src/drivers/video/cores3_camera_video.c @@ -239,6 +239,17 @@ static bool wait_for_capture_slot(int64_t deadline_us) { return false; } +static void log_capture_memory(const char *stage) { + const uint32_t dma_caps = MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL; + ESP_LOGI(TAG, + "event=video_memory stage=%s dma_buffer_max=%d dma_free=%zu dma_largest=%zu " + "internal_free=%zu psram_free=%zu", + stage, CONFIG_CAM_CTRL_DVP_DMA_BUFFER_SIZE, heap_caps_get_free_size(dma_caps), + heap_caps_get_largest_free_block(dma_caps), + heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT), + heap_caps_get_free_size(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)); +} + static void video_worker(void *argument) { (void)argument; unsigned int captured = 0, encoded = 0, sent = 0, rejected = 0, dropped = 0, capture_errors = 0; @@ -264,7 +275,9 @@ static void video_worker(void *argument) { } capture_pending = true; const enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + log_capture_memory("before_stream_on"); if (should_stop() || ioctl(s_video.fd, VIDIOC_STREAMON, &type) < 0) { + log_capture_memory("stream_on_not_started"); ESP_LOGW(TAG, "event=video action=stream_on result=not_started"); goto done; } diff --git a/docs/CORES3_UI.md b/docs/CORES3_UI.md index 6a7ac83..1781faf 100644 --- a/docs/CORES3_UI.md +++ b/docs/CORES3_UI.md @@ -113,10 +113,17 @@ saved configuration values. Current status is tracked in the [validation matrix] ## Rendering, resources and provenance -The existing LVGL task runs on Core 1 at priority 1. Objects and drawing scratch space use PSRAM; -SPI transfers retain a 320 × 16 RGB565 stripe, or 10,240 bytes of internal DMA memory. The UI task -stack and driver/synchronization allocations are additional memory. Partial redraws avoid a -full-screen page cache or decoded full-face buffer. +The existing LVGL task runs on Core 1 at priority 1. Its 7,168-byte stack now uses PSRAM through +the existing port's `task_stack_caps`, moving 7 KiB of stack storage out of internal RAM. The +CoreS3 profile requires `CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y`; board defaults enable it. +Objects and drawing scratch space also use PSRAM. SPI transfers retain a 320 × 16 RGB565 stripe, +or 10,240 bytes of internal DMA memory; driver/synchronization allocations are additional memory. +Partial redraws avoid a full-screen page cache or decoded full-face buffer. + +The display initialization log includes `ui_stack_bytes=7168 ui_stack=psram`. Moving the stack +reduces internal memory use but does not guarantee the largest free DMA block required by the +camera. Check `event=video_memory` as described in [CoreS3 video](CORES3_VIDEO.md); total free +memory alone does not establish that streaming can start. Fixed LVGL widgets and curves draw the face. Five immutable A8 masks contribute 13,631 alpha bytes for hearts, stars, ellipses, cheeks and tears, excluding descriptor overhead. The terminal @@ -143,6 +150,8 @@ Current build and hardware status is tracked only in the - Test animation enabled/disabled, overflowing SSID/instructions, and web-console pairing. - Regress short touch, three-second provisioning, Wi-Fi recovery and repeated SDK stop/start. - Run full-duplex audio with video off and with the existing 1 fps camera uplink enabled. +- Validate the PSRAM UI stack with concurrent audio/video/UI and provisioning/volume-persistence + NVS writes; this real-device regression remains pending. - Record CPU load, internal/PSRAM peaks, minimum free heap and largest blocks; repeat sessions to check resource lifetime and sustained memory growth. diff --git a/docs/CORES3_UI.zh-CN.md b/docs/CORES3_UI.zh-CN.md index 5ac5388..18a5e49 100644 --- a/docs/CORES3_UI.zh-CN.md +++ b/docs/CORES3_UI.zh-CN.md @@ -100,10 +100,17 @@ idf.py -B build/cores3-pixel -p flash monitor ## 渲染、资源与来源 -现有LVGL任务运行于Core 1、优先级1。对象与绘制临时空间使用PSRAM,SPI继续使用 -320 × 16 RGB565条带,即10,240字节内部DMA内存;UI线程栈、驱动和同步资源另计。 +现有LVGL任务运行于Core 1、优先级1。7,168字节任务栈现通过已有port的 `task_stack_caps` +放入PSRAM,减少7 KiB内部栈存储。CoreS3 profile要求 +`CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y`,板级defaults已开启。 +对象与绘制临时空间也使用PSRAM,SPI继续使用320 × 16 RGB565条带,即10,240字节 +内部DMA内存;驱动和同步资源另计。 局部刷新不增加全屏页面缓存或整脸解码缓冲。 +显示初始化日志包含 `ui_stack_bytes=7168 ui_stack=psram`。搬栈减少内部内存占用,不能保证 +摄像头所需的最大DMA连续块;需结合[视频说明](CORES3_VIDEO.zh-CN.md)中的 +`event=video_memory`检查,不能只凭空闲内存总量判断采集能够启动。 + 固定LVGL控件和曲线绘制表情,五个不可变A8蒙版保存心形、星形、椭圆、脸颊与眼泪, alpha数据合计13,631字节,不含描述符。终端字库由DejaVu Sans Mono Bold派生并重命名, 保留Bitstream Vera许可;思源黑体UI子集仍为SIL OFL 1.1。蒙版与终端字库仅编入CoreS3 @@ -124,6 +131,7 @@ alpha数据合计13,631字节,不含描述符。终端字库由DejaVu Sans Mon - 开关动画,检查超宽SSID/提示滚动及网页控制台配对。 - 回归短触、三秒配网、断网恢复和反复SDK启停。 - 视频关闭及原1 fps摄像头上行开启时分别验证全双工音频。 +- PSRAM UI栈改动后的音频、视频与UI并行,以及配网、音量持久化NVS写入回归仍待真机验证。 - 记录CPU、内部/PSRAM峰值、最小空闲堆及最大连续块,多轮会话观察资源释放和内存增长。 结果需包含板型、固件语言、视频/动画配置、音量及串口日志。 diff --git a/docs/CORES3_VIDEO.md b/docs/CORES3_VIDEO.md index a4dd126..2b87720 100644 --- a/docs/CORES3_VIDEO.md +++ b/docs/CORES3_VIDEO.md @@ -33,8 +33,10 @@ Keep the audio packet duration at the supported 60 ms. A fresh build uses Chines `;ci/en-us.defaults` to the defaults list in a new build directory for English. All CoreS3 builds use LVGL; no separate UI enable flag is needed. When reusing a build directory, run `idf.py -B build/cores3-video reconfigure build` so changes -to the component's hidden DMA default are regenerated. Confirm -`CONFIG_CAM_CTRL_DVP_DMA_BUFFER_SIZE=16384` in that build's generated `sdkconfig`. +to the project's hidden DMA default are regenerated. Confirm +`CONFIG_CAM_CTRL_DVP_DMA_BUFFER_SIZE=8192` in that build's generated `sdkconfig`. +The CoreS3 profile also requires `CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y` for the PSRAM UI +stack; board defaults enable it. If an existing configuration saved `n`, enable it in menuconfig. ## Hardware and memory @@ -47,16 +49,35 @@ to the component's hidden DMA default are regenerated. Confirm | Reset | AW9523 P1_0; locked masked writes preserve LCD and audio reset lines | Two 153,600-byte capture buffers and one 131,072-byte JPEG buffer use about 428 KiB of PSRAM. -The encoder also allocates workspace. With video enabled, the current -[`CAM_CTRL_DVP_DMA_BUFFER_SIZE`](../components/esp_cam_sensor/Kconfig) default is 16,384 bytes. -For 320×240 YUYV, the DVP driver rounds this to two 7,680-byte halves, allocating 15 KiB of -internal DMA memory, plus descriptors and a 3-KiB capture-task stack. These figures use the current -defaults; check the generated DMA configuration when comparing older firmware. The encoding worker -has a 6-KiB stack. Check internal free memory -and the largest free block during a call, not only total PSRAM. LVGL objects use PSRAM and the UI -has a separate 10 KiB internal DMA buffer; it does not allocate a full-screen page cache. -The DMA increase consumes 7.5 KiB more internal RAM than the previous configuration, excluding -descriptors. Both PSRAM frame buffers remain allocated and rotate through the single queued slot. +The encoder also allocates workspace. With video enabled, +[`main/Kconfig.projbuild`](../main/Kconfig.projbuild) sets the hidden +`CAM_CTRL_DVP_DMA_BUFFER_SIZE` default to 8,192 bytes before the vendored component's default is +loaded. The vendored Kconfig and driver remain unchanged. For 320×240 YUYV, the driver chooses +two 3,840-byte halves that divide the 153,600-byte frame, allocating 7,680 bytes (7.5 KiB) of +contiguous internal DMA memory, plus descriptors and a 3-KiB capture-task stack. The earlier +16,384-byte setting allocated 15,360 bytes (15 KiB). Check the generated DMA configuration when +comparing firmware. The encoding worker has a 6-KiB stack. Both PSRAM frame buffers remain +allocated and rotate through the single queued slot. + +`no mem for CAM DVP DMA receive buffer` means the driver could not allocate its contiguous +internal DMA buffer when streaming starts, after RTC has connected. Free PSRAM cannot satisfy +this allocation; total free internal memory can also exceed the request while its largest DMA +block is too small. Descriptors, task stacks and other runtime allocations still need additional +memory. LVGL objects use PSRAM and the UI has a separate 10 KiB internal DMA buffer; it does not +allocate a full-screen page cache. + +Before moving the UI stack, a device log still reported allocation failure with +`dma_free=13187` and `dma_largest=5120`: the largest block was below the 7,680-byte requirement. +The CoreS3 adapter now places its 7,168-byte LVGL task stack in PSRAM through the existing port's +`task_stack_caps`, moving 7 KiB of stack storage out of internal RAM. The display DMA stripe stays +internal. This change does not statically guarantee a sufficient contiguous block or successful +camera startup; check the new device logs. + +The smaller buffer produces about 40 DMA data events per active frame instead of 20 and leaves +less time to service each half before reuse. The sensor's 20 fps timing during capture is unchanged +by the 5 fps request or 1 fps upload limits. Validate capture errors, timeouts and audio continuity +on a device with RTC audio and the UI active; this memory reduction alone does not establish that +the reported hardware failure is resolved. The JPEG worker uses priority 3 without fixed core affinity and no additional encoder helper task. The DVP copy task retains the upstream driver's higher priority for timely DMA service. @@ -86,6 +107,14 @@ Current build and hardware status is tracked only in the [validation matrix](VALIDATION.md). The following checks remain the device and server acceptance procedure. +The display initialization log includes `ui_stack_bytes=7168 ui_stack=psram`. +`event=video_memory` records `stage=before_stream_on` and, if streaming does not start, +`stage=stream_on_not_started`. Its fields are `dma_buffer_max` (the configured upper bound, +8,192 bytes by default), `dma_free`, `dma_largest`, `internal_free`, and `psram_free`, all in bytes. +`dma_free` and `dma_largest` use the driver's internal DMA memory capabilities. Compare the +pre-start `dma_largest` with the actual 7,680-byte buffer requirement; sufficient space for this +buffer does not guarantee enough memory for the rest of stream startup. + `cores3_video` emits lifecycle logs and `event=video_stats` every 10 seconds during streaming: `window_ms`, `captured`, `encoded`, `sent`, `rejected`, `dropped`, `capture_errors`, `last_bytes`, `quality`, `target_bps`, and `encode_max_us`. Counters and `encode_max_us` reset each interval; `last_bytes`, `quality`, and @@ -99,6 +128,7 @@ Validate GC0308 detection, correct colors/orientation, server reception/inferenc JPEG quality, CPU/heap use, and audio continuity. Exercise repeated conversation start/stop, Wi-Fi loss, long-touch provisioning, bitrate reduction, and missing camera. Confirm no frames after stop and stable memory after repeated cycles. Hardware and server acceptance must be recorded -separately. Compare `captured/window_ms`, +separately. Validation of the PSRAM UI stack with concurrent video, full-duplex audio and UI, +including provisioning and volume-persistence NVS writes, remains pending. Compare `captured/window_ms`, per-core CPU, internal free heap, and the largest free block while keeping the same scene and audio activity. The expected reduction in DMA traffic is not a measured CPU reduction. diff --git a/docs/CORES3_VIDEO.zh-CN.md b/docs/CORES3_VIDEO.zh-CN.md index d6cbe20..b4030eb 100644 --- a/docs/CORES3_VIDEO.zh-CN.md +++ b/docs/CORES3_VIDEO.zh-CN.md @@ -29,8 +29,10 @@ uplink (1 fps)`。`CONFIG_MYBOT_ENABLE_VIDEO` 默认关闭;其他板型开启 CoreS3-SE 没有 GC0308,不属于视频支持范围。音频帧长保持当前支持的 60 ms。 全新构建默认中文;英文版本在新的构建目录中给 defaults 列表追加 `;ci/en-us.defaults`。 所有 CoreS3 构建均使用 LVGL,不需要单独开启 UI。 -复用已有构建目录时,运行 `idf.py -B build/cores3-video reconfigure build`,让组件的隐藏 DMA -默认值重新生成;确认该目录的 `sdkconfig` 中为 `CONFIG_CAM_CTRL_DVP_DMA_BUFFER_SIZE=16384`。 +复用已有构建目录时,运行 `idf.py -B build/cores3-video reconfigure build`,让主项目的隐藏 DMA +默认值重新生成;确认该目录的 `sdkconfig` 中为 `CONFIG_CAM_CTRL_DVP_DMA_BUFFER_SIZE=8192`。 +CoreS3 profile 还要求 `CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y`,以支持 PSRAM 中的 UI +任务栈;板级 defaults 已开启。已有配置若保存为 `n`,需在 menuconfig 中开启。 ## 硬件与内存 @@ -43,16 +45,29 @@ CoreS3-SE 没有 GC0308,不属于视频支持范围。音频帧长保持当前 | Reset | AW9523 P1_0;加锁读改写,只改变本设备对应位 | 两张 153,600 字节采集缓冲和一张 131,072 字节 JPEG 缓冲共约 428 KiB PSRAM,编码器还会 -申请工作区。开启视频时,当前 -[`CAM_CTRL_DVP_DMA_BUFFER_SIZE`](../components/esp_cam_sensor/Kconfig) 默认值为 16,384 字节。 -对于 320×240 YUYV,DVP 驱动按整帧可分割的大小调整为两个 7,680 字节半缓冲,实际分配 -15 KiB 内部 DMA 内存,另有描述符和 3 KiB 采集任务栈。上述数值对应当前默认配置, -对比旧固件时先核对其生成配置中的 DMA 大小;JPEG 任务栈为 6 KiB。 -通话中应同时检查内部内存剩余和最大连续块,不能只看 PSRAM。LVGL 对象使用 PSRAM,UI -另有 10 KiB 内部 DMA 缓冲,不分配全屏页面缓存。 -本次 DMA 比之前多占用 7.5 KiB 内部 RAM,描述符另计。两张 PSRAM 帧缓冲仍保留,轮流使用, +申请工作区。开启视频时,[`main/Kconfig.projbuild`](../main/Kconfig.projbuild) 在加载第三方 +组件默认值之前,将隐藏配置 `CAM_CTRL_DVP_DMA_BUFFER_SIZE` 的默认值设为 8,192 字节, +第三方 Kconfig 和驱动保持原样。对于 320×240 YUYV,驱动选择可整除 153,600 字节整帧的 +两个 3,840 字节半缓冲,实际分配 7,680 字节(7.5 KiB)连续内部 DMA 内存,另有描述符和 +3 KiB 采集任务栈。此前 16,384 字节配置实际分配 15,360 字节(15 KiB)。对比固件时先核对 +生成配置中的 DMA 大小;JPEG 任务栈为 6 KiB。两张 PSRAM 帧缓冲仍保留,轮流使用, 同时最多只有一张已提交给驱动。 +`no mem for CAM DVP DMA receive buffer` 表示 RTC 连接后启动采集时,驱动无法分配所需的 +连续内部 DMA 缓冲。空闲 PSRAM 不能满足这项分配;即使内部剩余总量大于请求,最大的 +DMA 连续块也可能不足。描述符、任务栈和其他运行时分配仍需要额外内存。LVGL 对象使用 +PSRAM,UI 另有 10 KiB 内部 DMA 缓冲,不分配全屏页面缓存。 + +迁移 UI 栈之前的真机日志仍显示分配失败:`dma_free=13187`,但 `dma_largest=5120`, +最大连续块小于 7,680 字节需求。CoreS3 适配器现通过已有 port 的 `task_stack_caps`, +将 7,168 字节 LVGL 任务栈放入 PSRAM,减少 7 KiB 内部栈存储;显示 DMA 条带仍在内部内存。 +搬栈本身不能静态保证连续块充足或摄像头启动成功,需要检查新的真机日志。 + +缩小缓冲使每个活动帧的 DMA 数据事件由约 20 次增至 40 次,半缓冲被复用前可用于处理的 +时间更短。5 fps 采样请求和 1 fps 上传限制不会改变采集时的 20 fps 传感器时序。需要在 +RTC 音频和 UI 同时运行的真机上检查采集错误、超时及音频连续性;仅减少内存需求不能证明 +已解决所报告的硬件运行故障。 + JPEG 任务优先级为 3,不固定 CPU 核心,不额外创建编码辅助任务;DVP 拷贝任务保留上游 较高优先级以及时处理 DMA。摄像头不使用音频 I2S 外设。LCD 继续显示状态页,不提供摄像头预览。 @@ -73,6 +88,13 @@ Board 常驻 I2C 总线。 当前构建与真机状态统一记录在[验证矩阵](VALIDATION.md)中。以下项目是真机与服务端验收流程。 +显示初始化日志包含 `ui_stack_bytes=7168 ui_stack=psram`。 +`event=video_memory` 在启动采集前记录 `stage=before_stream_on`,采集未启动时还记录 +`stage=stream_on_not_started`。字段均以字节为单位:`dma_buffer_max` 为配置上限(默认 +8,192),`dma_free`、`dma_largest` 分别为符合驱动内部 DMA 内存要求的空闲总量和最大 +连续块,`internal_free`、`psram_free` 为内部内存和 PSRAM 空闲量。将启动前的 +`dma_largest` 与实际 7,680 字节缓冲需求比较;能分配此缓冲不代表后续启动所需内存也充足。 + `cores3_video` 打印生命周期日志,推流时每 10 秒汇总 `event=video_stats`:窗口时长 `window_ms`、成功出队数 `captured`、编码数 `encoded`、接受数 `sent`、拒绝数 `rejected`、 丢帧数 `dropped`、采集错误 `capture_errors`、 @@ -86,5 +108,7 @@ Board 常驻 I2C 总线。 真机需验证 GC0308 识别、颜色与方向、服务端收到并识别图像、发送间隔、图像质量、CPU/内存 以及音频连续性。覆盖重复开始/结束对话、断网、长按触摸配网、带宽降低和摄像头缺失,确认 停止后无回调、多轮运行无内存持续增长。真机和服务端验收另行记录。 +PSRAM UI 栈改动后的摄像头、全双工音频与 UI 并行运行,以及配网、音量持久化 NVS 写入回归 +仍待真机验证。 对比测试应保持相同场景和音频活动,观察 `captured/window_ms`、每核 CPU、内部剩余堆和 最大连续块;DMA 流量的理论减少不等于已经测得 CPU 降幅。 diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 2efe043..431b2d9 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -30,7 +30,7 @@ unsupported areas. Board READMEs describe hardware and operation only; the | `esp32-s3-touch-amoled-1.8-v2` | CI: zh-CN, en-US; recorded merged build / 已记录合并构建 | Not completed / 未完成 | Physical Flash/PSRAM, AXP2101/TCA9554 sequencing, 368x448 QSPI display, CST816S and 16 kHz ES8311 audio require device validation; no AXP2101 power-key action, battery reporting, sleep, shutdown or video. | | `esp32-s3-touch-lcd-1.85` | CI: zh-CN, en-US; recorded merged build / 已记录合并构建 | Not completed / 未完成 | Physical Flash/PSRAM, GPIO7 power hold, panel-version selection, backlight, CST816S and right-slot microphone/both-slot playback require device validation; GPIO6 power button, battery reporting, sleep, shutdown and video are not implemented. | | `genjutech-s3-1.54tft` | CI: zh-CN, en-US; recorded merged build / 已记录合并构建 | Not completed / 未完成 | Physical Flash/PSRAM, ST7789, ES8311, PA/display coupling, Boot and volume inputs require device validation; no touch, LED, battery/charging, sleep, shutdown or video. | -| `m5stack-core-s3` | CI: zh-CN, en-US, video, light-theme and static-animation variants; recorded video build / 已记录视频构建 | Partial / 部分通过: earlier provisioning, bidirectional audio, camera uplink and status-card UI; current pixel UI and shared UI changes pending / 旧通路通过,当前像素 UI 与共享 UI 待回归 | Current pixel UI, capture scheduling and DMA regression; no video downlink, camera preview, battery reporting or automatic sleep. Video is opt-in for direct builds. | +| `m5stack-core-s3` | CI: zh-CN, en-US, video, light-theme and static-animation variants; recorded video build / 已记录视频构建 | Partial / 部分通过: earlier provisioning, bidirectional audio, camera uplink and status-card UI; 2026-10-29 device log confirms camera stream startup with the PSRAM UI stack / UI 栈迁入 PSRAM 后摄像头启动通过 | Current pixel UI, capture cadence, frame upload and repeated start/stop regression; no video downlink, camera preview, battery reporting or automatic sleep. Video is opt-in for direct builds. | | `m5stack-stick-s3` | CI: zh-CN, en-US | Not completed / 未完成 | Power, audio, input and panel; no GPIO12 support, IMU, infrared, battery reporting, shutdown or low power. | | `respeaker-flex-xvf3800-circular4-xiao` | CI: zh-CN, en-US | Not completed / 未完成 | Requires separately flashed XVF3800 Circular-4 16 kHz two-channel I2S firmware; XVF version, clock direction, routing and audio pending. No Linear-4, XVF firmware update, LED ring, LCD or video. | | `sensecap-watcher` | CI: zh-CN, en-US | Not completed / 未完成 | Power sequencing, codec 16 kHz mode, audio, encoder and display; no camera, touch, LED, battery reporting, shutdown or low power. Preserve the factory-data partition. | @@ -94,6 +94,28 @@ unsupported areas. Board READMEs describe hardware and operation only; the | `atk-dnesp32s3-box` | CI: zh-CN, en-US; recorded merged build | Not completed / 未完成 | i80 ST7789 timing and orientation, ES8311 routing and XL9555/TCA9555 power sequencing require device validation; expander keys, camera, battery, dimming, sleep and shutdown are not implemented. The NS4168-only hardware variant is not supported. | | `tudouzi` | CI: zh-CN, en-US; recorded merged build | Not completed / 未完成 | Headless Wi-Fi subset; AXP2101 sequencing, ES8311/ES7210 routing, PA and keys require device validation. SSD1306 UI, ML307/4G, LED, battery reporting, sleep and shutdown are not implemented. | +## CoreS3 memory regression evidence / CoreS3 内存回归证据 + +On 2026-10-29, local ESP-IDF v5.5.2 `reconfigure/build/size` passed for CoreS3 video in +`zh-CN` and `en-US`. CoreS3 and ST7789 host fault-injection tests passed normally and with +UBSan; ASan could not run because even a minimal program failed at runtime startup on this host. +Formatting, SPDX and whitespace checks passed. + +A user-provided real-device log confirms RTC connected, `dma_buffer_max=8192`, +`dma_free=15703`, `dma_largest=11776`, DVP initialization and `stream_on` after moving the +7 KiB UI stack to PSRAM. Before this change, the largest DMA block was 5120 bytes and the +7680-byte allocation failed. This confirms one successful stream startup; frame capture, +SDK acceptance, server reception, audio/UI continuity, repeated start/stop and provisioning or +volume-persistence NVS writes still require validation with the current changes. + +2026-10-29,本地 CoreS3 视频中英文版本通过 ESP-IDF v5.5.2 的 `reconfigure/build/size`。 +CoreS3 与 ST7789 Host 故障注入测试的普通和 UBSan 版本通过;本机连最小程序也在 ASan +运行时启动阶段失败,因此未完成 ASan 验证。格式、SPDX 和空白检查通过。 +用户提供的真机日志确认,7 KiB UI 栈迁入 PSRAM 后,RTC 已连接,DMA 最大连续块从 +5120 字节增至 11776 字节,DVP 初始化和 `stream_on` 成功。该结果仅证明一次启动通过; +当前改动下的帧采集、SDK 接受、服务端接收、音频/UI 连续性、重复启停,以及配网和音量 +持久化 NVS 写入仍待验证。 + ## Global boundaries / 全局边界 - Local wake words are not implemented. diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index b0360a9..02d9d0d 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -80,6 +80,13 @@ menu "mybot" The platform requests DVP capture at most five times per second. Capture and software encoding consume additional RAM and CPU. + # Project defaults precede component defaults. Reduce the contiguous internal + # DMA allocation needed after RTC has allocated its own resources. + # For QVGA YUYV, the driver rounds this to two 3840-byte halves. + config CAM_CTRL_DVP_DMA_BUFFER_SIZE + int + default 8192 if MYBOT_ENABLE_VIDEO + config MYBOT_AUDIO_PLAYBACK_TEST bool "Run CoreS3 offline audio playback A/B test at boot" default n diff --git a/tests/cores3_pixel_ui/README.md b/tests/cores3_pixel_ui/README.md index caf62c9..0ef5909 100644 --- a/tests/cores3_pixel_ui/README.md +++ b/tests/cores3_pixel_ui/README.md @@ -4,7 +4,13 @@ Run `sh tests/cores3_pixel_ui/run.sh`. The test compiles the real CoreS3 adapter and expression policy with the existing ST7789 host declarations and mocked CoreS3 panel, LVGL port, Wi-Fi SSID snapshot, and view. It does not use hardware. -Coverage includes partial initialization failures, retryable cleanup, board/SDK -display references, pending DMA callbacks, copied pair codes and SSIDs, runtime +Coverage includes the 7-KiB PSRAM stack request, stack allocation and readiness +failures, partial initialization failures, retryable cleanup, board/SDK display +references, pending DMA callbacks and teardown timeout, copied pair codes and SSIDs, runtime status, automatic phase transitions, opener timing and retry, unknown indicator mask handling, hangup and detach cancellation. + +The port mock tracks stack allocation and release across failure, retry and repeated +initialization. It does not establish actual PSRAM stack safety or DMA availability +on the device. Set `CORES3_PIXEL_UI_SANITIZERS=1` to enable AddressSanitizer and +UndefinedBehaviorSanitizer. diff --git a/tests/cores3_pixel_ui/test_adapter.cc b/tests/cores3_pixel_ui/test_adapter.cc index 292d127..cceccec 100644 --- a/tests/cores3_pixel_ui/test_adapter.cc +++ b/tests/cores3_pixel_ui/test_adapter.cc @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: MIT */ #include "host_platform.h" +#include "esp_heap_caps.h" #include "display/ili9342_panel.h" #include "display/lvgl_view.h" #include "display/pixel_glasses.h" @@ -42,6 +43,8 @@ static host_display display{}; static host_timer timer{}; static bool port_open, port_locked, view_open, finish_on_delay; static unsigned pending_dma, updates, closes; +static void *ui_stack; +static unsigned stack_allocations, stack_releases; static int64_t now_us; static std::string fail_step, fail_cleanup; static mybot_lcd_content_t applied{}; @@ -70,7 +73,7 @@ static void send(mybot_lcd_screen_t screen, uint32_t indicators = 0) { CHECK(mybot_cores3_lcd_ops()->render(active_owner, &content) == 0); } static void complete_dma() { - CHECK(pending_dma && io.open && display.open && io.done); + CHECK(pending_dma && io.open && display.open && io.done && ui_stack); --pending_dma; io.done(&io, nullptr, io.user); } @@ -183,14 +186,28 @@ void lv_timer_delete(lv_timer_t *) { timer = {}; } esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg) { - CHECK(!port_open && cfg->task_priority == 1 && cfg->task_affinity == 1); + CHECK(!port_open && !ui_stack && cfg->task_priority == 1 && cfg->task_affinity == 1); + CHECK(cfg->task_stack == 7168); + CHECK(cfg->task_stack_caps == (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)); + if (fail("stack_alloc")) + return ESP_FAIL; + ui_stack = std::malloc(cfg->task_stack); + CHECK(ui_stack); + ++stack_allocations; port_open = true; + if (fail("port_init_timeout")) + return ESP_ERR_TIMEOUT; return fail("port_init") ? ESP_FAIL : ESP_OK; } esp_err_t lvgl_port_deinit(void) { - CHECK(!display.open && !panel.open && !io.open); + CHECK(!display.open && !panel.open && !io.open && !pending_dma); if (fail("port_deinit")) return ESP_FAIL; + if (ui_stack) { + std::free(ui_stack); + ui_stack = nullptr; + ++stack_releases; + } port_open = false; return ESP_OK; } @@ -265,6 +282,7 @@ int mybot_pixel_glasses_replay_expression(mybot_expression_t expression) { static void released() { CHECK(!io.open && !panel.open && !display.open && !timer.open && !view_open && !port_open); CHECK(!port_locked && !pending_dma); + CHECK(!ui_stack && stack_allocations == stack_releases); } static void init() { CHECK(mybot_cores3_lcd_ops()->init(&active_owner) == 0 && active_owner); @@ -279,8 +297,8 @@ static void stop() { static void lifecycle_tests() { const auto *ops = mybot_cores3_lcd_ops(); CHECK(ops->init(nullptr) < 0); - for (const char *failure : - {"panel_open", "port_init", "port_lock", "display", "register", "view", "timer"}) { + for (const char *failure : {"panel_open", "stack_alloc", "port_init", "port_init_timeout", + "port_lock", "display", "register", "view", "timer"}) { fail_step = failure; void *out = reinterpret_cast(1); CHECK(ops->init(&out) < 0 && !out && fail_step.empty()); @@ -291,9 +309,27 @@ static void lifecycle_tests() { fail_cleanup = failure; ops->destroy(active_owner); CHECK(fail_cleanup.empty()); + CHECK(ui_stack && stack_allocations == stack_releases + 1); CHECK(ops->init(&active_owner) == 0); // finishes deferred cleanup first stop(); } + fail_step = "port_init_timeout"; + fail_cleanup = "port_deinit"; + void *out = reinterpret_cast(1); + CHECK(ops->init(&out) < 0 && !out && fail_step.empty() && fail_cleanup.empty()); + CHECK(ui_stack && stack_allocations == stack_releases + 1); + init(); // Joins the failed initialization before allocating another stack. + stop(); + for (unsigned cycle = 0; cycle < 3; ++cycle) { + init(); + const unsigned allocations = stack_allocations; + void *sdk = nullptr; + CHECK(ops->init(&sdk) == 0 && sdk == active_owner); + CHECK(stack_allocations == allocations); + ops->destroy(sdk); + CHECK(ui_stack && stack_allocations == stack_releases + 1); + stop(); + } init(); const lv_area_t area{0, 0, 1, 0}; uint8_t pixels[]{0x34, 0x12, 0x78, 0x56}; @@ -303,6 +339,13 @@ static void lifecycle_tests() { stop(); CHECK(!finish_on_delay); init(); + display.flush(&display, &area, pixels); + ops->destroy(active_owner); // The missing callback must time out without freeing the stack. + CHECK(pending_dma == 1 && ui_stack && !display.refresh && !timer.open); + CHECK(stack_allocations == stack_releases + 1); + complete_dma(); + stop(); + init(); fail_step = "draw"; display.flush(&display, &area, pixels); CHECK(!pending_dma && fail_step.empty()); @@ -385,5 +428,6 @@ static void ui_tests() { int main() { lifecycle_tests(); ui_tests(); - std::puts("CoreS3 pixel adapter: lifecycle, DMA, indicator and phase checks passed"); + std::puts( + "CoreS3 pixel adapter: PSRAM stack, lifecycle, DMA, indicator and phase checks passed"); } diff --git a/tests/st7789_lifecycle/mocks/esp_heap_caps.h b/tests/st7789_lifecycle/mocks/esp_heap_caps.h new file mode 100644 index 0000000..dbed45e --- /dev/null +++ b/tests/st7789_lifecycle/mocks/esp_heap_caps.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: MIT */ +#pragma once + +#define MALLOC_CAP_8BIT (1U << 2) +#define MALLOC_CAP_SPIRAM (1U << 10) diff --git a/tests/st7789_lifecycle/mocks/host_platform.h b/tests/st7789_lifecycle/mocks/host_platform.h index 8cb9c37..c8741d0 100644 --- a/tests/st7789_lifecycle/mocks/host_platform.h +++ b/tests/st7789_lifecycle/mocks/host_platform.h @@ -311,10 +311,11 @@ typedef struct { int task_affinity; int task_stack; int task_max_sleep_ms; + unsigned task_stack_caps; int timer_period_ms; } lvgl_port_cfg_t; #define ESP_LVGL_PORT_INIT_CONFIG() \ - { 0, 0, 0, 0, 0 } + { 0, 0, 0, 0, 0, 0 } typedef struct { esp_lcd_panel_io_handle_t io_handle; esp_lcd_panel_handle_t panel_handle;