From c783918289daa4ff2dbe6ddc9743884d6d79f083 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 22 Aug 2023 21:33:25 -0300 Subject: [PATCH 1/2] Fixes ESP32 BT Memory Releasing --- cores/esp32/esp32-hal-bt.c | 4 ++++ cores/esp32/esp32-hal-misc.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/cores/esp32/esp32-hal-bt.c b/cores/esp32/esp32-hal-bt.c index 7b6a54e1a..b4c381aa1 100644 --- a/cores/esp32/esp32-hal-bt.c +++ b/cores/esp32/esp32-hal-bt.c @@ -16,8 +16,12 @@ #ifdef CONFIG_BT_ENABLED +#if CONFIG_IDF_TARGET_ESP32 +bool btInUse(){ return true; } +#else // user may want to change it to free resources __attribute__((weak)) bool btInUse(){ return true; } +#endif #include "esp_bt.h" diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 9bc1b3a3a..835cce6f0 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -209,9 +209,15 @@ bool verifyRollbackLater() { return false; } #endif #ifdef CONFIG_BT_ENABLED +#if CONFIG_IDF_TARGET_ESP32 +//overwritten in esp32-hal-bt.c +bool btInUse() __attribute__((weak)); +bool btInUse(){ return false; } +#else //from esp32-hal-bt.c extern bool btInUse(); #endif +#endif void initArduino() { From 6d1706cd70a7e8777ab9a1cd7ed3e8cd3e22637b Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 23 Aug 2023 20:31:29 -0300 Subject: [PATCH 2/2] allows setting buffer size after or before begin() --- cores/esp32/HWCDC.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index cc0202f65..5dcc1b4b5 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -173,9 +173,18 @@ void HWCDC::begin(unsigned long baud) if(tx_lock == NULL) { tx_lock = xSemaphoreCreateMutex(); } - setRxBufferSize(256);//default if not preset - setTxBufferSize(256);//default if not preset - + //RX Buffer default has 256 bytes if not preset + if(rx_queue == NULL) { + if (!setRxBufferSize(256)) { + log_e("HW CDC RX Buffer error"); + } + } + //TX Buffer default has 256 bytes if not preset + if (tx_ring_buf == NULL) { + if (!setTxBufferSize(256)) { + log_e("HW CDC TX Buffer error"); + } + } usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK); usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET);