8000 esp32/mbedtls: Allocate buffers from the uPy heap. · DvdGiessen/micropython@d3a8f76 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit d3a8f76

Browse files
committed
esp32/mbedtls: Allocate buffers from the uPy heap.
1 parent a16a330 commit d3a8f76

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ports/esp32/boards/sdkconfig.base

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ CONFIG_LWIP_PPP_CHAP_SUPPORT=y
4646
# SSL
4747
# Use 4kiB output buffer instead of default 16kiB (because IDF heap is fragmented in 4.0)
4848
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
49+
# Use uPy heap allocator as custom allocator
50+
CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=n
51+
CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC=y
4952

5053
# ULP coprocessor support
5154
CONFIG_ESP32_ULP_COPROC_ENABLED=y

ports/esp32/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
#include "extmod/modbluetooth.h"
6868
#endif
6969

70+
#if MICROPY_PY_USSL && MICROPY_SSL_MBEDTLS && MICROPY_TRACKED_ALLOC && CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC
71+
#include "py/misc.h"
72+
#include "mbedtls/platform.h"
73+
#endif
74+
7075
// MicroPython runs as a task under FreeRTOS
7176
#define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1)
7277
#define MP_TASK_STACK_SIZE (16 * 1024)
@@ -143,6 +148,11 @@ void mp_task(void *pvParameter) {
143148
mp_task_heap = malloc(mp_task_heap_size);
144149
}
145150

151+
#if MICROPY_PY_USSL && MICROPY_SSL_MBEDTLS && MICROPY_TRACKED_ALLOC && CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC
152+
// Configure mbedtls to allocate from the heap
153+
mbedtls_platform_set_calloc_free(&m_tracked_calloc, &m_tracked_free);
154+
#endif
155+
146156
soft_reset:
147157
// initialise the stack pointer for the main thread
148158
mp_stack_set_top((void *)sp);

0 commit comments

Comments
 (0)
0