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 <lucas.tamborrino@espressif.com>
This commit is contained in:
parent
cfeb325b4f
commit
5dc545290c
8 changed files with 102 additions and 94 deletions
|
@ -19,12 +19,10 @@
|
|||
#include <sdkconfig.h>
|
||||
|
||||
#if CONFIG_ESP_SPIRAM
|
||||
#include <esp_psram.h>
|
||||
#include <esp_private/esp_psram_extram.h>
|
||||
#include "psram.h"
|
||||
#endif
|
||||
|
||||
#include <zephyr/kernel_structs.h>
|
||||
#include <string.h>
|
||||
#include <zephyr/toolchain.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <zephyr/linker/linker-defs.h>
|
||||
|
@ -50,11 +48,6 @@
|
|||
|
||||
#define TAG "boot.esp32s3"
|
||||
|
||||
#if CONFIG_ESP_SPIRAM
|
||||
extern int _ext_ram_bss_start;
|
||||
extern int _ext_ram_bss_end;
|
||||
#endif
|
||||
|
||||
extern void z_prep_c(void);
|
||||
extern void esp_reset_reason_init(void);
|
||||
|
||||
|
@ -161,28 +154,7 @@ void IRAM_ATTR __esp_platform_start(void)
|
|||
esp_mmu_map_init();
|
||||
|
||||
#if CONFIG_ESP_SPIRAM
|
||||
esp_err_t err = esp_psram_init();
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_EARLY_LOGE(TAG, "Failed to Initialize external RAM, aborting.");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (esp_psram_get_size() < CONFIG_ESP_SPIRAM_SIZE) {
|
||||
ESP_EARLY_LOGE(TAG, "External RAM size is less than configured, aborting.");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (esp_psram_is_initialized()) {
|
||||
if (!esp_psram_extram_test()) {
|
||||
ESP_EARLY_LOGE(TAG, "External RAM failed memory test!");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
memset(&_ext_ram_bss_start, 0,
|
||||
(&_ext_ram_bss_end - &_ext_ram_bss_start) * sizeof(_ext_ram_bss_start));
|
||||
|
||||
esp_init_psram();
|
||||
#endif /* CONFIG_ESP_SPIRAM */
|
||||
|
||||
/* Apply SoC patches */
|
||||
|
@ -214,6 +186,15 @@ void IRAM_ATTR __esp_platform_start(void)
|
|||
|
||||
esp_intr_initialize();
|
||||
|
||||
#if CONFIG_ESP_SPIRAM
|
||||
/* Init Shared Multi Heap for PSRAM */
|
||||
int err = esp_psram_smh_init();
|
||||
|
||||
if (err) {
|
||||
printk("Failed to initialize PSRAM shared multi heap (%d)\n", err);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Start Zephyr */
|
||||
z_prep_c();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue