fix: restore non-display psram usage and clean stale qrcode log
Signed-off-by: Bo <boironic@gmail.com>
This commit is contained in:
@@ -172,12 +172,13 @@ static void agent_loop_task(void *arg)
|
|||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Agent loop started on core %d", xPortGetCoreID());
|
ESP_LOGI(TAG, "Agent loop started on core %d", xPortGetCoreID());
|
||||||
|
|
||||||
char *system_prompt = calloc(1, MIMI_CONTEXT_BUF_SIZE);
|
/* Allocate large buffers from PSRAM */
|
||||||
char *history_json = calloc(1, MIMI_LLM_STREAM_BUF_SIZE);
|
char *system_prompt = heap_caps_calloc(1, MIMI_CONTEXT_BUF_SIZE, MALLOC_CAP_SPIRAM);
|
||||||
char *tool_output = calloc(1, TOOL_OUTPUT_SIZE);
|
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) {
|
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);
|
vTaskDelete(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -317,8 +318,8 @@ static void agent_loop_task(void *arg)
|
|||||||
free(msg.content);
|
free(msg.content);
|
||||||
|
|
||||||
/* Log memory status */
|
/* Log memory status */
|
||||||
ESP_LOGI(TAG, "Free internal heap: %d bytes",
|
ESP_LOGI(TAG, "Free PSRAM: %d bytes",
|
||||||
(int)heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
|
(int)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,8 @@ static int cmd_heap_info(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
printf("Internal free: %d bytes\n",
|
printf("Internal free: %d bytes\n",
|
||||||
(int)heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
|
(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",
|
printf("Total free: %d bytes\n",
|
||||||
(int)esp_get_free_heap_size());
|
(int)esp_get_free_heap_size());
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_http_client.h"
|
#include "esp_http_client.h"
|
||||||
#include "esp_crt_bundle.h"
|
#include "esp_crt_bundle.h"
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
#include "nvs.h"
|
#include "nvs.h"
|
||||||
#include "cJSON.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)
|
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;
|
if (!rb->data) return ESP_ERR_NO_MEM;
|
||||||
rb->len = 0;
|
rb->len = 0;
|
||||||
rb->cap = initial_cap;
|
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) {
|
while (rb->len + len >= rb->cap) {
|
||||||
size_t new_cap = rb->cap * 2;
|
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;
|
if (!tmp) return ESP_ERR_NO_MEM;
|
||||||
rb->data = tmp;
|
rb->data = tmp;
|
||||||
rb->cap = new_cap;
|
rb->cap = new_cap;
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ void app_main(void)
|
|||||||
{
|
{
|
||||||
/* Silence noisy components */
|
/* Silence noisy components */
|
||||||
esp_log_level_set("esp-x509-crt-bundle", ESP_LOG_WARN);
|
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, "========================================");
|
||||||
ESP_LOGI(TAG, " MimiClaw - ESP32-S3 AI Agent");
|
ESP_LOGI(TAG, " MimiClaw - ESP32-S3 AI Agent");
|
||||||
@@ -108,6 +107,8 @@ void app_main(void)
|
|||||||
/* Print memory info */
|
/* Print memory info */
|
||||||
ESP_LOGI(TAG, "Internal free: %d bytes",
|
ESP_LOGI(TAG, "Internal free: %d bytes",
|
||||||
(int)heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
|
(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 */
|
/* Input */
|
||||||
button_Init();
|
button_Init();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_http_client.h"
|
#include "esp_http_client.h"
|
||||||
#include "esp_crt_bundle.h"
|
#include "esp_crt_bundle.h"
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
#include "nvs.h"
|
#include "nvs.h"
|
||||||
#include "cJSON.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),
|
snprintf(path, sizeof(path),
|
||||||
"/res/v1/web/search?q=%s&count=%d", encoded_query, SEARCH_RESULT_COUNT);
|
"/res/v1/web/search?q=%s&count=%d", encoded_query, SEARCH_RESULT_COUNT);
|
||||||
|
|
||||||
|
/* Allocate response buffer from PSRAM */
|
||||||
search_buf_t sb = {0};
|
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) {
|
if (!sb.data) {
|
||||||
snprintf(output, output_size, "Error: Out of memory");
|
snprintf(output, output_size, "Error: Out of memory");
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
|
|||||||
Reference in New Issue
Block a user