Browse Source

Merge branch 'nimble/iram_allocation_strategy' into 'master'

NimBLE: Add support to IRAM allocation strategy

See merge request espressif/esp-idf!8015
Angus Gratton 6 years ago
parent
commit
88bf21b21e

+ 11 - 1
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"

+ 4 - 0
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

+ 3 - 0
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