From db3a8b1202831b4a5b8e4754b743c67428221680 Mon Sep 17 00:00:00 2001 From: crispyberry Date: Thu, 5 Feb 2026 18:55:12 +0800 Subject: [PATCH] feat: add sdkconfig defaults, partition table, and global config 16MB flash with custom partitions (2x2MB OTA + 12MB SPIFFS), PSRAM/WiFi/TLS tuning, and centralized compile-time constants. Co-Authored-By: Claude Opus 4.5 --- main/mimi_config.h | 66 ++++++++++++++++++++++++++++++++++++++ partitions.csv | 8 +++++ sdkconfig.defaults.esp32s3 | 38 ++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 main/mimi_config.h create mode 100644 partitions.csv diff --git a/main/mimi_config.h b/main/mimi_config.h new file mode 100644 index 0000000..e97cd3e --- /dev/null +++ b/main/mimi_config.h @@ -0,0 +1,66 @@ +#pragma once + +/* MimiClaw Global Configuration */ + +/* WiFi */ +#define MIMI_WIFI_MAX_RETRY 10 +#define MIMI_WIFI_RETRY_BASE_MS 1000 +#define MIMI_WIFI_RETRY_MAX_MS 30000 + +/* Telegram Bot */ +#define MIMI_TG_POLL_TIMEOUT_S 30 +#define MIMI_TG_MAX_MSG_LEN 4096 +#define MIMI_TG_POLL_STACK (8 * 1024) +#define MIMI_TG_POLL_PRIO 5 +#define MIMI_TG_POLL_CORE 0 + +/* Agent Loop */ +#define MIMI_AGENT_STACK (8 * 1024) +#define MIMI_AGENT_PRIO 6 +#define MIMI_AGENT_CORE 1 +#define MIMI_AGENT_MAX_HISTORY 20 + +/* LLM */ +#define MIMI_LLM_DEFAULT_MODEL "claude-opus-4-5-20251101" +#define MIMI_LLM_MAX_TOKENS 4096 +#define MIMI_LLM_API_URL "https://api.anthropic.com/v1/messages" +#define MIMI_LLM_API_VERSION "2023-06-01" +#define MIMI_LLM_STREAM_BUF_SIZE (32 * 1024) + +/* Message Bus */ +#define MIMI_BUS_QUEUE_LEN 8 +#define MIMI_OUTBOUND_STACK (4 * 1024) +#define MIMI_OUTBOUND_PRIO 5 +#define MIMI_OUTBOUND_CORE 0 + +/* Memory / SPIFFS */ +#define MIMI_SPIFFS_BASE "/spiffs" +#define MIMI_SPIFFS_CONFIG_DIR "/spiffs/config" +#define MIMI_SPIFFS_MEMORY_DIR "/spiffs/memory" +#define MIMI_SPIFFS_SESSION_DIR "/spiffs/sessions" +#define MIMI_MEMORY_FILE "/spiffs/memory/MEMORY.md" +#define MIMI_SOUL_FILE "/spiffs/config/SOUL.md" +#define MIMI_USER_FILE "/spiffs/config/USER.md" +#define MIMI_CONTEXT_BUF_SIZE (16 * 1024) +#define MIMI_SESSION_MAX_MSGS 20 + +/* WebSocket Gateway */ +#define MIMI_WS_PORT 18789 +#define MIMI_WS_MAX_CLIENTS 4 + +/* Serial CLI */ +#define MIMI_CLI_STACK (4 * 1024) +#define MIMI_CLI_PRIO 3 +#define MIMI_CLI_CORE 0 + +/* NVS Namespaces */ +#define MIMI_NVS_WIFI "wifi_config" +#define MIMI_NVS_TG "tg_config" +#define MIMI_NVS_LLM "llm_config" + +/* NVS Keys */ +#define MIMI_NVS_KEY_SSID "ssid" +#define MIMI_NVS_KEY_PASS "password" +#define MIMI_NVS_KEY_TG_TOKEN "bot_token" +#define MIMI_NVS_KEY_API_KEY "api_key" +#define MIMI_NVS_KEY_MODEL "model" diff --git a/partitions.csv b/partitions.csv new file mode 100644 index 0000000..24c8778 --- /dev/null +++ b/partitions.csv @@ -0,0 +1,8 @@ +# Name, Type, SubType, Offset, Size +nvs, data, nvs, 0x9000, 0x6000 +otadata, data, ota, 0xF000, 0x2000 +phy_init, data, phy, 0x11000, 0x1000 +ota_0, app, ota_0, 0x20000, 0x200000 +ota_1, app, ota_1, 0x220000, 0x200000 +spiffs, data, spiffs, 0x420000, 0xBD0000 +coredump, data, coredump,0xFF0000, 0x10000 diff --git a/sdkconfig.defaults.esp32s3 b/sdkconfig.defaults.esp32s3 index b01fdbe..57aa1b1 100644 --- a/sdkconfig.defaults.esp32s3 +++ b/sdkconfig.defaults.esp32s3 @@ -1 +1,39 @@ +# MimiClaw - ESP32-S3 Target Configuration CONFIG_IDF_TARGET="esp32s3" + +# Flash 16MB + QIO +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y + +# CPU 240MHz +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y + +# PSRAM 8MB Octal +CONFIG_SPIRAM=y +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_SPEED_80M=y +CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=2048 +CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=98304 +CONFIG_SPIRAM_MEMTEST=n + +# WiFi memory optimization +CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=3 +CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=6 +CONFIG_ESP_WIFI_RX_BA_WIN=3 +CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=16 + +# TLS optimization (PSRAM allocation + small buffers) +CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y +CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y +CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=4096 +CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096 + +# WebSocket support +CONFIG_HTTPD_WS_SUPPORT=y + +# Custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" + +# Console/UART for CLI +CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y