From cdc00f20767b045f815394aff8f44a57f5fb2a02 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu, 18 Aug 2022 10:08:53 +0200 Subject: [PATCH] missing PSRAM fix --- .../nimble/esp_port/port/src/esp_nimble_mem.c | 44 -------------- .../esp_port/port/src/esp_nimble_mem.cpp | 53 ++++++++++++++++ .../NimBLE-Arduino/tasmota_lib_changes.md | 60 +++++++++++++++++++ 3 files changed, 113 insertions(+), 44 deletions(-) delete mode 100644 lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.c create mode 100644 lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.cpp diff --git a/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.c b/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.c deleted file mode 100644 index 7e1899db6..000000000 --- a/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef ESP_PLATFORM - -#include "esp_attr.h" -#include "esp_heap_caps.h" -#include "nimconfig.h" -#include "../include/esp_nimble_mem.h" - -IRAM_ATTR void *nimble_platform_mem_malloc(size_t size) -{ -#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL - return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL - return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); -#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT - return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#else - return malloc(size); -#endif -} - -IRAM_ATTR void *nimble_platform_mem_calloc(size_t n, size_t size) -{ -#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL - return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL - return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); -#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT - return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#else - return calloc(n, size); -#endif -} - -IRAM_ATTR void nimble_platform_mem_free(void *ptr) -{ - heap_caps_free(ptr); -} -#endif diff --git a/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.cpp b/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.cpp new file mode 100644 index 000000000..407091c7f --- /dev/null +++ b/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.cpp @@ -0,0 +1,53 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifdef ESP_PLATFORM + +#include "esp_attr.h" +#include "esp_heap_caps.h" +#include "nimconfig.h" +#include "../include/esp_nimble_mem.h" + +//Tasmota Patch +extern void *special_malloc(uint32_t size); +extern void *special_calloc(size_t num, size_t size); + + +extern "C" { +IRAM_ATTR void *nimble_platform_mem_malloc(size_t size) +{ + return special_malloc((uint32_t)size); +// #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL +// return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL +// return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT +// return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #else +// return malloc(size); +// #endif +} + +IRAM_ATTR void *nimble_platform_mem_calloc(size_t n, size_t size) +{ + return special_calloc(n,size); +// #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL +// return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL +// return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT +// return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #else +// return calloc(n, size); +// #endif +} + +IRAM_ATTR void nimble_platform_mem_free(void *ptr) +{ + heap_caps_free(ptr); +} +} //extern "C" +#endif diff --git a/lib/libesp32_div/NimBLE-Arduino/tasmota_lib_changes.md b/lib/libesp32_div/NimBLE-Arduino/tasmota_lib_changes.md index 24048605f..1455c8138 100644 --- a/lib/libesp32_div/NimBLE-Arduino/tasmota_lib_changes.md +++ b/lib/libesp32_div/NimBLE-Arduino/tasmota_lib_changes.md @@ -24,3 +24,63 @@ Change in nimconfig.h `#define CONFIG_BT_NIMBLE_NVS_PERSIST 1` to `#define CONFIG_BT_NIMBLE_NVS_PERSIST 0` + +Rename /src/nimble/esp_port/port/src/esp_nimble_mem.c to esp_nimble_mem.c + +and replace all in the file with + +``` +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifdef ESP_PLATFORM + +#include "esp_attr.h" +#include "esp_heap_caps.h" +#include "nimconfig.h" +#include "../include/esp_nimble_mem.h" + +//Tasmota Patch +extern void *special_malloc(uint32_t size); +extern void *special_calloc(size_t num, size_t size); + + +extern "C" { +IRAM_ATTR void *nimble_platform_mem_malloc(size_t size) +{ + return special_malloc((uint32_t)size); +// #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL +// return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL +// return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT +// return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #else +// return malloc(size); +// #endif +} + +IRAM_ATTR void *nimble_platform_mem_calloc(size_t n, size_t size) +{ + return special_calloc(n,size); +// #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL +// return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL +// return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT +// return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #else +// return calloc(n, size); +// #endif +} + +IRAM_ATTR void nimble_platform_mem_free(void *ptr) +{ + heap_caps_free(ptr); +} +} //extern "C" +#endif +```