Skip to content

Commit 4a0c683

Browse files
committed
Fix build with IDF 4 based Arduino cores
1 parent 22012e8 commit 4a0c683

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/nimble/esp_port/port/include/esp_nimble_mem.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,52 @@
1313
extern "C" {
1414
#endif
1515

16+
#if ESP_IDF_VERSION_MAJOR >= 5
1617
// #pragma message "This file should be replaced with bt_osi_mem.h, used here for compatibility"
1718

1819
#include "bt_osi_mem.h"
1920
#define nimble_platform_mem_malloc bt_osi_mem_malloc
2021
#define nimble_platform_mem_calloc bt_osi_mem_calloc
2122
#define nimble_platform_mem_free bt_osi_mem_free
2223

24+
#else
25+
26+
#include "esp_attr.h"
27+
#include "esp_heap_caps.h"
28+
#include "nimconfig.h"
29+
#include "../include/esp_nimble_mem.h"
30+
31+
IRAM_ATTR void *nimble_platform_mem_malloc(size_t size)
32+
{
33+
#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL
34+
return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
35+
#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL
36+
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT);
37+
#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT
38+
return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
39+
#else
40+
return malloc(size);
41+
#endif
42+
}
43+
44+
IRAM_ATTR void *nimble_platform_mem_calloc(size_t n, size_t size)
45+
{
46+
#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL
47+
return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
48+
#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL
49+
return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT);
50+
#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT
51+
return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
52+
#else
53+
return calloc(n, size);
54+
#endif
55+
}
56+
57+
IRAM_ATTR void nimble_platform_mem_free(void *ptr)
58+
{
59+
heap_caps_free(ptr);
60+
}
61+
2362
#ifdef __cplusplus
2463
}
2564
#endif

0 commit comments

Comments
 (0)