diff --git a/components/bt/host/nimble/Kconfig.in b/components/bt/host/nimble/Kconfig.in index 275bd9d230..c763cca383 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 95d0d930ec..44b8d0f5c9 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 0000000000..e4f6ca2ca1 --- /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