Skip to content

Commit 086d305

Browse files
shubhamkulkarni97sylvioalves
authored andcommitted
hal: Add wrapper for k_malloc.
Fixes SPIRAM allocation being placed in internal memory Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
1 parent d6bee6f commit 086d305

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

zephyr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ if(CONFIG_SOC_ESP32)
6464
CONFIG_HEAP_MEM_POOL_SIZE
6565
gcc
6666
"-Wl,--wrap=k_calloc"
67-
"-Wl,--wrap=k_aligned_alloc"
67+
"-Wl,--wrap=k_malloc"
6868
)
6969

7070
zephyr_sources_ifdef(

zephyr/adapter/src/heap_caps.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#if (CONFIG_ESP_SPIRAM || (CONFIG_HEAP_MEM_POOL_SIZE > 0) || (CONFIG_ESP_HEAP_MEM_POOL_REGION_1_SIZE > 0))
1414
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
15-
void *__real_k_aligned_alloc(size_t align, size_t size);
15+
void *__real_k_malloc(size_t size);
1616
void *__real_k_calloc(size_t nmemb, size_t size);
1717
#endif
1818

@@ -91,7 +91,7 @@ static void *z_esp_alloc_internal(size_t align, size_t size)
9191
{
9292
void *ptr = NULL;
9393
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
94-
ptr = __real_k_aligned_alloc(align, size);
94+
ptr = __real_k_malloc(size);
9595
#endif
9696
#if (CONFIG_ESP_HEAP_MEM_POOL_REGION_1_SIZE > 0)
9797
if (ptr == NULL) {
@@ -116,27 +116,27 @@ static void *z_esp_calloc_internal(size_t nmemb, size_t size)
116116
}
117117

118118
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
119-
void *__wrap_k_aligned_alloc(size_t align, size_t size)
119+
void *__wrap_k_malloc(size_t size)
120120
#else
121-
void *k_aligned_alloc(size_t align, size_t size)
121+
void *k_malloc(size_t size)
122122
#endif
123123
{
124124
void *ptr = NULL;
125125
#if defined(CONFIG_ESP_SPIRAM)
126126
if (size < CONFIG_ESP_HEAP_MIN_EXTRAM_THRESHOLD) {
127127
#endif
128-
ptr = z_esp_alloc_internal(align, size);
128+
ptr = z_esp_alloc_internal(sizeof(void *), size);
129129
#if defined(CONFIG_ESP_HEAP_SEARCH_ALL_REGIONS)
130130
if (ptr == NULL) {
131-
ptr = z_esp_aligned_alloc(&_spiram_heap, align, size);
131+
ptr = z_esp_aligned_alloc(&_spiram_heap, sizeof(void *), size);
132132
}
133133
#endif
134134
#if defined(CONFIG_ESP_SPIRAM)
135135
} else {
136-
ptr = z_esp_aligned_alloc(&_spiram_heap, align, size);
136+
ptr = z_esp_aligned_alloc(&_spiram_heap, sizeof(void *), size);
137137
#if defined(CONFIG_ESP_HEAP_SEARCH_ALL_REGIONS)
138138
if (ptr == NULL) {
139-
ptr = z_esp_alloc_internal(align, size);
139+
ptr = z_esp_alloc_internal(sizeof(void *), size);
140140
}
141141
#endif
142142
}

0 commit comments

Comments
 (0)