-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
soc: espressif: psram as shared multi heap
Currently, if the user wants to allocate heap on external RAM he needs to enable CONFIG_ESP_SPIRAM and set a threshold defined with CONFIG_ESP_HEAP_MIN_EXTRAM_THRESHOLD. This approach requires that we re-implement `k_malloc` and allocate the memory on the proper region based on the block size. By using the shared multi heap feature the proccess of allocating memory from external memory becomes more fluent and simple. The attribute SMH_REG_ATTR_EXTERNAL was added to reference the external memory. Signed-off-by: Lucas Tamborrino <[email protected]>
- Loading branch information
1 parent
6a101ae
commit d54c7e5
Showing
9 changed files
with
102 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
int esp_init_psram(void); | ||
|
||
int esp_psram_smh_init(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <string.h> | ||
#include <zephyr/kernel.h> | ||
#include <rom/ets_sys.h> | ||
#include <esp_psram.h> | ||
#include <esp_private/esp_psram_extram.h> | ||
#include <zephyr/multi_heap/shared_multi_heap.h> | ||
|
||
#define PSRAM_ADDR (DT_REG_ADDR(DT_NODELABEL(psram0))) | ||
|
||
extern int _spiram_heap_start; | ||
extern int _ext_ram_bss_start; | ||
extern int _ext_ram_bss_end; | ||
|
||
struct shared_multi_heap_region smh_psram = { | ||
.addr = (uintptr_t)&_spiram_heap_start, | ||
.size = CONFIG_ESP_SPIRAM_SIZE, | ||
.attr = SMH_REG_ATTR_EXTERNAL, | ||
}; | ||
|
||
int esp_psram_smh_init(void) | ||
{ | ||
shared_multi_heap_pool_init(); | ||
smh_psram.size = CONFIG_ESP_SPIRAM_SIZE - ((int)&_spiram_heap_start - PSRAM_ADDR); | ||
return shared_multi_heap_add(&smh_psram, NULL); | ||
} | ||
|
||
int esp_init_psram(void) | ||
{ | ||
esp_err_t err = esp_psram_init(); | ||
|
||
if (err != ESP_OK) { | ||
ets_printf("Failed to Initialize external RAM, aborting.\n"); | ||
return err; | ||
} | ||
|
||
if (esp_psram_get_size() < CONFIG_ESP_SPIRAM_SIZE) { | ||
ets_printf("External RAM size is less than configured, aborting.\n"); | ||
return err; | ||
} | ||
|
||
if (esp_psram_is_initialized()) { | ||
if (!esp_psram_extram_test()) { | ||
ets_printf("External RAM failed memory test!"); | ||
return err; | ||
} | ||
} | ||
|
||
memset(&_ext_ram_bss_start, 0, | ||
(&_ext_ram_bss_end - &_ext_ram_bss_start) * sizeof(_ext_ram_bss_start)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters