From f84b4617cb6e15f943ea81efeeafa651a9553445 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 10 Oct 2023 09:36:18 +0200 Subject: [PATCH] rp2/cyw43_configport: Use m_tracked_calloc and m_tracked_free. When using malloc and free there were out-of-memory situations depending on the arm-none-eabi package version. This commit changes malloc/free to use the MicroPython GC heap instead. Signed-off-by: robert-hh Signed-off-by: Damien George --- ports/rp2/boards/RPI_PICO_W/mpconfigboard.cmake | 3 --- ports/rp2/cyw43_configport.h | 9 +++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ports/rp2/boards/RPI_PICO_W/mpconfigboard.cmake b/ports/rp2/boards/RPI_PICO_W/mpconfigboard.cmake index 5610c313e6..cea6c38d73 100644 --- a/ports/rp2/boards/RPI_PICO_W/mpconfigboard.cmake +++ b/ports/rp2/boards/RPI_PICO_W/mpconfigboard.cmake @@ -2,9 +2,6 @@ set(PICO_BOARD "pico_w") -# The C malloc is needed by cyw43-driver Bluetooth -set(MICROPY_C_HEAP_SIZE 4096) - set(MICROPY_PY_LWIP ON) set(MICROPY_PY_NETWORK_CYW43 ON) diff --git a/ports/rp2/cyw43_configport.h b/ports/rp2/cyw43_configport.h index 929d83537b..8f64762df5 100644 --- a/ports/rp2/cyw43_configport.h +++ b/ports/rp2/cyw43_configport.h @@ -90,13 +90,14 @@ #define cyw43_schedule_internal_poll_dispatch(func) pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, func) -// Bluetooth uses the C heap to load its firmware (provided by pico-sdk). -// Space is reserved for this, see MICROPY_C_HEAP_SIZE. +// Bluetooth requires dynamic memory allocation to load its firmware (the allocation +// call is made from pico-sdk). This allocation is always done at thread-level, not +// from an IRQ, so is safe to delegate to the MicroPython GC heap. #ifndef cyw43_malloc -#define cyw43_malloc malloc +#define cyw43_malloc(nmemb) m_tracked_calloc(nmemb, 1) #endif #ifndef cyw43_free -#define cyw43_free free +#define cyw43_free m_tracked_free #endif void cyw43_post_poll_hook(void);