Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp32s3: psram: add sources to suport code relocation #423

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/esp_psram/mmu_psram_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ void instruction_flash_page_info_init(uint32_t psram_start_physical_page)
instr_end_page = instr_start_page + instr_page_cnt - 1;
instr_flash2spiram_offs = instr_start_page - psram_start_physical_page;
instruction_in_spiram = 1;
ESP_DRAM_LOGV("mmu_psram", "Instructions from flash page%d copy to SPIRAM page%d, Offset: %d", instr_start_page, psram_start_physical_page, instr_flash2spiram_offs);
ESP_DRAM_LOGV("mmu_psram", "Instructions in flash pages %d..%d copy to SPIRAM page %d, Offset: %d",
instr_start_page, instr_end_page, psram_start_physical_page, instr_flash2spiram_offs);
}

uint32_t esp_spiram_instruction_access_enabled(void)
Expand Down
13 changes: 11 additions & 2 deletions components/spi_flash/spi_flash_os_func_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static const char TAG[] = "spi_flash";

#if SPI_FLASH_CACHE_NO_DISABLE
K_MUTEX_DEFINE(s_spi1_flash_mutex);
static unsigned int s_spi1_key;
#endif // #if SPI_FLASH_CACHE_NO_DISABLE

/*
Expand Down Expand Up @@ -83,7 +84,11 @@ static IRAM_ATTR esp_err_t spi1_start(void *arg)
* From 1 to 3, the lock efficiency decreases.
*/
#if SPI_FLASH_CACHE_NO_DISABLE
k_mutex_lock(&s_spi1_flash_mutex, K_FOREVER);
if (k_is_pre_kernel()) {
s_spi1_key = irq_lock();
} else {
k_mutex_lock(&s_spi1_flash_mutex, K_FOREVER);
}
#else
//directly disable the cache and interrupts when lock is not used
cache_disable(NULL);
Expand All @@ -100,7 +105,11 @@ static IRAM_ATTR esp_err_t spi1_end(void *arg)
* There are three ways for ESP Flash API lock, see `spi1_start`
*/
#if SPI_FLASH_CACHE_NO_DISABLE
k_mutex_unlock(&s_spi1_flash_mutex);
if (k_is_pre_kernel()) {
irq_unlock(s_spi1_key);
} else {
k_mutex_unlock(&s_spi1_flash_mutex);
}
#else
cache_enable(NULL);
#endif
Expand Down
3 changes: 3 additions & 0 deletions zephyr/esp32s3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ if(CONFIG_SOC_SERIES_ESP32S3)
../../components/esp_psram/${CONFIG_SOC_SERIES}/esp_psram_impl_octal.c
)

zephyr_sources_ifdef(CONFIG_SPIRAM_FETCH_INSTRUCTIONS
../../components/esp_psram/mmu_psram_flash.c
)
endif()

zephyr_sources_ifdef(
Expand Down
35 changes: 35 additions & 0 deletions zephyr/port/include/esp_heap_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,41 @@
#define os_wpa_calloc_func(_nmemb, _size) k_calloc(_nmemb, _size)
#define os_wpa_free_func(_mem) k_free(_mem)

#elif defined(CONFIG_ESP_WIFI_WIFI_SPIRAM)

#define esp_wifi_malloc_func(_size) \
shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _size)
#define esp_wifi_calloc_func(_nmemb, _size) \
{ \
void *p; \
p = shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _nmemb * _size); \
if (p) { \
memset(p, 0, _nmemb * _size); \
} \
return p; \
}
#define esp_wifi_free_func(_mem) shared_multi_heap_free(_mem)

#define os_wpa_malloc_func(_size) shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _size)
#define os_wpa_realloc_func(_ptr, _size) \
{ void *p; \
if (_ptr) { \
shared_multi_heap_free(_ptr); \
} \
p = shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _size); \
return p; \
}
#define os_wpa_calloc_func(_nmemb, _size) \
{ \
void *p; \
p = shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _nmemb * _size); \
if (p) { \
memset(p, 0, _nmemb * _size); \
} \
return p; \
}
#define os_wpa_free_func(_mem) shared_multi_heap_free(_mem)

#else

#define esp_wifi_malloc_func(_size) malloc(_size)
Expand Down