fix: restore non-display psram usage and clean stale qrcode log

Signed-off-by: Bo <boironic@gmail.com>
This commit is contained in:
Bo
2026-02-19 17:40:00 +08:00
parent 0c256d7653
commit f0a2741e0c
5 changed files with 17 additions and 10 deletions

View File

@@ -172,12 +172,13 @@ static void agent_loop_task(void *arg)
{
ESP_LOGI(TAG, "Agent loop started on core %d", xPortGetCoreID());
char *system_prompt = calloc(1, MIMI_CONTEXT_BUF_SIZE);
char *history_json = calloc(1, MIMI_LLM_STREAM_BUF_SIZE);
char *tool_output = calloc(1, TOOL_OUTPUT_SIZE);
/* Allocate large buffers from PSRAM */
char *system_prompt = heap_caps_calloc(1, MIMI_CONTEXT_BUF_SIZE, MALLOC_CAP_SPIRAM);
char *history_json = heap_caps_calloc(1, MIMI_LLM_STREAM_BUF_SIZE, MALLOC_CAP_SPIRAM);
char *tool_output = heap_caps_calloc(1, TOOL_OUTPUT_SIZE, MALLOC_CAP_SPIRAM);
if (!system_prompt || !history_json || !tool_output) {
ESP_LOGE(TAG, "Failed to allocate runtime buffers");
ESP_LOGE(TAG, "Failed to allocate PSRAM buffers");
vTaskDelete(NULL);
return;
}
@@ -317,8 +318,8 @@ static void agent_loop_task(void *arg)
free(msg.content);
/* Log memory status */
ESP_LOGI(TAG, "Free internal heap: %d bytes",
(int)heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
ESP_LOGI(TAG, "Free PSRAM: %d bytes",
(int)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
}
}

View File

@@ -195,6 +195,8 @@ static int cmd_heap_info(int argc, char **argv)
{
printf("Internal free: %d bytes\n",
(int)heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
printf("PSRAM free: %d bytes\n",
(int)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
printf("Total free: %d bytes\n",
(int)esp_get_free_heap_size());
return 0;

View File

@@ -7,6 +7,7 @@
#include "esp_log.h"
#include "esp_http_client.h"
#include "esp_crt_bundle.h"
#include "esp_heap_caps.h"
#include "nvs.h"
#include "cJSON.h"
@@ -90,7 +91,7 @@ typedef struct {
static esp_err_t resp_buf_init(resp_buf_t *rb, size_t initial_cap)
{
rb->data = calloc(1, initial_cap);
rb->data = heap_caps_calloc(1, initial_cap, MALLOC_CAP_SPIRAM);
if (!rb->data) return ESP_ERR_NO_MEM;
rb->len = 0;
rb->cap = initial_cap;
@@ -101,7 +102,7 @@ static esp_err_t resp_buf_append(resp_buf_t *rb, const char *data, size_t len)
{
while (rb->len + len >= rb->cap) {
size_t new_cap = rb->cap * 2;
char *tmp = realloc(rb->data, new_cap);
char *tmp = heap_caps_realloc(rb->data, new_cap, MALLOC_CAP_SPIRAM);
if (!tmp) return ESP_ERR_NO_MEM;
rb->data = tmp;
rb->cap = new_cap;

View File

@@ -99,7 +99,6 @@ void app_main(void)
{
/* Silence noisy components */
esp_log_level_set("esp-x509-crt-bundle", ESP_LOG_WARN);
esp_log_level_set("QRCODE", ESP_LOG_WARN);
ESP_LOGI(TAG, "========================================");
ESP_LOGI(TAG, " MimiClaw - ESP32-S3 AI Agent");
@@ -108,6 +107,8 @@ void app_main(void)
/* Print memory info */
ESP_LOGI(TAG, "Internal free: %d bytes",
(int)heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
ESP_LOGI(TAG, "PSRAM free: %d bytes",
(int)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
/* Input */
button_Init();

View File

@@ -7,6 +7,7 @@
#include "esp_log.h"
#include "esp_http_client.h"
#include "esp_crt_bundle.h"
#include "esp_heap_caps.h"
#include "nvs.h"
#include "cJSON.h"
@@ -255,8 +256,9 @@ esp_err_t tool_web_search_execute(const char *input_json, char *output, size_t o
snprintf(path, sizeof(path),
"/res/v1/web/search?q=%s&count=%d", encoded_query, SEARCH_RESULT_COUNT);
/* Allocate response buffer from PSRAM */
search_buf_t sb = {0};
sb.data = calloc(1, SEARCH_BUF_SIZE);
sb.data = heap_caps_calloc(1, SEARCH_BUF_SIZE, MALLOC_CAP_SPIRAM);
if (!sb.data) {
snprintf(output, output_size, "Error: Out of memory");
return ESP_ERR_NO_MEM;