From b498873294971d1087d3eb7c372e819aa3ecab25 Mon Sep 17 00:00:00 2001 From: chenjintao Date: Wed, 26 Aug 2026 16:34:29 +0800 Subject: [PATCH] perf(memory): reduce factory CLI and LCD internal RAM use --- .../src/runtime/control_plane_factory_cli.c | 27 ++++++++++++++----- .../runtime/control_plane_runtime_workers.c | 2 +- main/Kconfig.projbuild | 6 ++--- sdkconfig.defaults | 4 +-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/components/control_plane/src/runtime/control_plane_factory_cli.c b/components/control_plane/src/runtime/control_plane_factory_cli.c index 1e8f805..316df0f 100644 --- a/components/control_plane/src/runtime/control_plane_factory_cli.c +++ b/components/control_plane/src/runtime/control_plane_factory_cli.c @@ -19,6 +19,7 @@ #include #include "domain.h" +#include "esp_heap_caps.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/portmacro.h" @@ -34,7 +35,7 @@ #define FACTORY_CLI_READ_TIMEOUT_MS 100 #define FACTORY_CLI_RESET_REPLY_DELAY_MS 100 #ifndef CONFIG_TQ_FACTORY_CLI_TASK_STACK_BYTES -#define CONFIG_TQ_FACTORY_CLI_TASK_STACK_BYTES (10U * 1024U) +#define CONFIG_TQ_FACTORY_CLI_TASK_STACK_BYTES (7U * 1024U) #endif #define FACTORY_CLI_WORKER_STACK_BYTES CONFIG_TQ_FACTORY_CLI_TASK_STACK_BYTES @@ -341,11 +342,18 @@ static void handle_get_wifi(void) return; } - char json[FACTORY_CLI_WIFI_JSON_MAX_LEN] = {0}; + char *json = (char *)heap_caps_calloc(1, + FACTORY_CLI_WIFI_JSON_MAX_LEN, + MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); + if (json == NULL) { + cli_write_error("no_memory"); + return; + } + size_t offset = 0; char prefix[48] = {0}; snprintf(prefix, sizeof(prefix), "{\"count\":%u,\"networks\":[", (unsigned)networks.count); - bool valid = json_append_text(json, sizeof(json), &offset, prefix); + bool valid = json_append_text(json, FACTORY_CLI_WIFI_JSON_MAX_LEN, &offset, prefix); for (size_t i = 0; valid && i < networks.count; ++i) { char item_prefix[40] = {0}; snprintf(item_prefix, @@ -353,20 +361,25 @@ static void handle_get_wifi(void) "%s{\"priority\":%u,\"ssid\":", i == 0U ? "" : ",", (unsigned)i); - valid = json_append_text(json, sizeof(json), &offset, item_prefix) && + valid = json_append_text(json, + FACTORY_CLI_WIFI_JSON_MAX_LEN, + &offset, + item_prefix) && json_append_escaped_string(json, - sizeof(json), + FACTORY_CLI_WIFI_JSON_MAX_LEN, &offset, networks.ssids[i]) && - json_append_text(json, sizeof(json), &offset, "}"); + json_append_text(json, FACTORY_CLI_WIFI_JSON_MAX_LEN, &offset, "}"); } - valid = valid && json_append_text(json, sizeof(json), &offset, "]}"); + valid = valid && json_append_text(json, FACTORY_CLI_WIFI_JSON_MAX_LEN, &offset, "]}"); if (!valid) { + heap_caps_free(json); cli_write_error("wifi_response_too_large"); return; } cli_write_line(json); + heap_caps_free(json); cli_write_ok(); } diff --git a/components/control_plane/src/runtime/control_plane_runtime_workers.c b/components/control_plane/src/runtime/control_plane_runtime_workers.c index 71f9ac5..8f8040a 100644 --- a/components/control_plane/src/runtime/control_plane_runtime_workers.c +++ b/components/control_plane/src/runtime/control_plane_runtime_workers.c @@ -21,7 +21,7 @@ #include "sdkconfig.h" #ifndef CONFIG_TQ_LCD_RENDER_TASK_STACK_BYTES -#define CONFIG_TQ_LCD_RENDER_TASK_STACK_BYTES (10U * 1024U) +#define CONFIG_TQ_LCD_RENDER_TASK_STACK_BYTES (8U * 1024U) #endif #define CONTROL_PLANE_MODEL_CMD_TASK_STACK_SIZE (1024 * 4) diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 6e988b7..01f74ce 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -728,7 +728,7 @@ menu "TQ Cat Configuration" config TQ_LCD_RENDER_TASK_STACK_BYTES int "LCD render task stack (bytes)" - default 10240 + default 8192 range 8192 16384 depends on TQ_SCREEN_ENABLE help @@ -1350,8 +1350,8 @@ menu "TQ Cat Configuration" config TQ_FACTORY_CLI_TASK_STACK_BYTES int "Factory CLI task stack (bytes)" - default 10240 - range 8192 16384 + default 7168 + range 7168 16384 depends on TQ_FACTORY_CLI_ENABLE help Stack size in bytes for the serial factory provisioning worker. diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 2636466..913dcf2 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -40,7 +40,7 @@ CONFIG_TQ_BOOT_SOUND_TIMEOUT_MS=3000 CONFIG_TQ_BOOT_SOUND_FILE="boot.opus" CONFIG_TQ_NETWORK_TASK_CORE=0 CONFIG_TQ_LOCAL_TASK_CORE=1 -CONFIG_TQ_LCD_RENDER_TASK_STACK_BYTES=10240 +CONFIG_TQ_LCD_RENDER_TASK_STACK_BYTES=8192 CONFIG_TQ_TASK_MONITOR_INTERVAL_MS=30000 CONFIG_TQ_TASK_MONITOR_MAX_TASKS=64 CONFIG_TQ_MEMORY_MONITOR_ENABLE=y @@ -200,7 +200,7 @@ CONFIG_TQ_MULTIMODAL_WATCHDOG_TASK_STACK_BYTES=6144 # CONFIG_MULTIMODAL_AUTH_BYPASS_TOKEN_SERVICE is not set CONFIG_AUTH_V2_ENABLE=y CONFIG_TQ_FACTORY_CLI_ENABLE=y -CONFIG_TQ_FACTORY_CLI_TASK_STACK_BYTES=10240 +CONFIG_TQ_FACTORY_CLI_TASK_STACK_BYTES=7168 CONFIG_MULTIMODAL_UPSTREAM_MODE="push2talk" CONFIG_MULTIMODAL_PTT_BUTTON_GPIO=3 CONFIG_MULTIMODAL_PTT_BUTTON_ACTIVE_LEVEL=0