From 67a6fd6f3b75fd0c6aaf1bf3cb7dafd23422c796 Mon Sep 17 00:00:00 2001 From: Hrishikesh Dhayagude Date: Wed, 18 Mar 2020 13:53:12 +0530 Subject: [PATCH] NimBLE: Add support to IRAM allocation strategy Added IRAM allocation provision under nimble_platform_mem_malloc() --- components/bt/host/nimble/Kconfig.in | 12 +++++++++++- components/bt/host/nimble/port/src/esp_nimble_mem.c | 4 ++++ examples/bluetooth/nimble/blehr/sdkconfig.ci | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 examples/bluetooth/nimble/blehr/sdkconfig.ci diff --git a/components/bt/host/nimble/Kconfig.in b/components/bt/host/nimble/Kconfig.in index 275bd9d23..c763cca38 100644 --- a/components/bt/host/nimble/Kconfig.in +++ b/components/bt/host/nimble/Kconfig.in @@ -10,6 +10,7 @@ choice BT_NIMBLE_MEM_ALLOC_MODE - External SPIRAM memory only - Either internal or external memory based on default malloc() behavior in ESP-IDF + - Internal IRAM memory wherever applicable else internal DRAM Recommended mode here is always internal, since that is most preferred from security perspective. But if application requirement does not @@ -26,7 +27,16 @@ choice BT_NIMBLE_MEM_ALLOC_MODE config BT_NIMBLE_MEM_ALLOC_MODE_DEFAULT bool "Default alloc mode" -endchoice + config BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT + bool "Internal IRAM" + depends on ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY + help + Allows to use IRAM memory region as 8bit accessible region. + + Every unaligned (8bit or 16bit) access will result in an exception + and incur penalty of certain clock cycles per unaligned read/write. + +endchoice #BT_NIMBLE_MEM_ALLOC_MODE config BT_NIMBLE_MAX_CONNECTIONS int "Maximum number of concurrent connections" diff --git a/components/bt/host/nimble/port/src/esp_nimble_mem.c b/components/bt/host/nimble/port/src/esp_nimble_mem.c index 95d0d930e..44b8d0f5c 100644 --- a/components/bt/host/nimble/port/src/esp_nimble_mem.c +++ b/components/bt/host/nimble/port/src/esp_nimble_mem.c @@ -30,6 +30,8 @@ IRAM_ATTR void *nimble_platform_mem_malloc(size_t size) 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 @@ -41,6 +43,8 @@ IRAM_ATTR void *nimble_platform_mem_calloc(size_t n, size_t size) 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 diff --git a/examples/bluetooth/nimble/blehr/sdkconfig.ci b/examples/bluetooth/nimble/blehr/sdkconfig.ci new file mode 100644 index 000000000..e4f6ca2ca --- /dev/null +++ b/examples/bluetooth/nimble/blehr/sdkconfig.ci @@ -0,0 +1,3 @@ +CONFIG_FREERTOS_UNICORE=y +CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY=y +CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT=y