feat: Allows esp-mqtt task and work buffers to be allocated in external memory

This commit is contained in:
Euripedes Rocha Filho
2026-07-27 16:14:58 +02:00
parent 827875a087
commit b21e6bb3d4
7 changed files with 104 additions and 8 deletions
+19 -1
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -96,6 +96,12 @@
#endif
#endif
#if MQTT_CORE_SELECTION_ENABLED
#define MQTT_TASK_AFFINITY MQTT_TASK_CORE
#else
#define MQTT_TASK_AFFINITY tskNO_AFFINITY
#endif
#ifdef CONFIG_MQTT_OUTBOX_EXPIRED_TIMEOUT_MS
#define OUTBOX_EXPIRED_TIMEOUT_MS CONFIG_MQTT_OUTBOX_EXPIRED_TIMEOUT_MS
#else
@@ -119,5 +125,17 @@
#define MQTT_OUTBOX_MEMORY MALLOC_CAP_DEFAULT
#endif
#ifdef CONFIG_MQTT_BUFFERS_ON_EXTERNAL_MEMORY
#define MQTT_BUFFER_MEMORY MALLOC_CAP_SPIRAM
#else
#define MQTT_BUFFER_MEMORY MALLOC_CAP_DEFAULT
#endif
#ifdef CONFIG_MQTT_TASK_STACK_ON_EXTERNAL_MEMORY
#define MQTT_TASK_STACK_ON_EXTERNAL_MEMORY 1
#else
#define MQTT_TASK_STACK_ON_EXTERNAL_MEMORY 0
#endif
#define OUTBOX_MAX_SIZE (4*1024)
#endif
+2 -1
View File
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <string.h>
#include "esp_heap_caps.h"
#include "mqtt_client.h"
#include "mqtt_msg.h"
#include "mqtt_config.h"
@@ -633,7 +634,7 @@ int mqtt_has_valid_msg_hdr(uint8_t *buffer, size_t length)
esp_err_t mqtt_msg_buffer_init(mqtt_connection_t *connection, int buffer_size)
{
memset(&connection->outbound_message, 0, sizeof(mqtt_message_t));
connection->buffer = (uint8_t *)calloc(buffer_size, sizeof(uint8_t));
connection->buffer = (uint8_t *)heap_caps_calloc(buffer_size, sizeof(uint8_t), MQTT_BUFFER_MEMORY);
if (!connection->buffer) {
return ESP_ERR_NO_MEM;