Skip to content

Commit ed291db

Browse files
author
Marek Matej
committed
zephyr, components: esp32s3: SPIRAM update
* support Wi-Fi SPIRAM heap * add sources * Fix locking of SPI1 to work in strtup conditions. * Update verbose message. Signed-off-by: Marek Matej <[email protected]>
1 parent e66a0ad commit ed291db

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

components/esp_psram/mmu_psram_flash.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ esp_err_t mmu_config_psram_text_segment(uint32_t start_page, uint32_t psram_size
7878
#elif CONFIG_IDF_TARGET_ESP32S3
7979
page_id = Cache_Flash_To_SPIRAM_Copy(CACHE_IBUS, IRAM0_CACHE_ADDRESS_LOW, page_id, &page0_page);
8080
#endif
81-
ESP_EARLY_LOGV(TAG, "after copy instruction, page_id is %d", page_id);
81+
ESP_EARLY_LOGI(TAG, "after copy instruction, page_id is %d", page_id);
8282
ESP_EARLY_LOGI(TAG, "Instructions copied and mapped to SPIRAM");
8383

8484
*out_page = page_id - start_page;
@@ -172,7 +172,8 @@ void instruction_flash_page_info_init(uint32_t psram_start_physical_page)
172172
instr_end_page = instr_start_page + instr_page_cnt - 1;
173173
instr_flash2spiram_offs = instr_start_page - psram_start_physical_page;
174174
instruction_in_spiram = 1;
175-
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);
175+
ESP_DRAM_LOGV("mmu_psram", "Instructions in flash pages %d..%d copy to SPIRAM page %d, Offset: %d",
176+
instr_start_page, instr_end_page, psram_start_physical_page, instr_flash2spiram_offs);
176177
}
177178

178179
uint32_t esp_spiram_instruction_access_enabled(void)

components/spi_flash/spi_flash_os_func_app.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static const char TAG[] = "spi_flash";
2727

2828
#if SPI_FLASH_CACHE_NO_DISABLE
2929
K_MUTEX_DEFINE(s_spi1_flash_mutex);
30+
static unsigned int s_spi1_key;
3031
#endif // #if SPI_FLASH_CACHE_NO_DISABLE
3132

3233
/*
@@ -83,7 +84,11 @@ static IRAM_ATTR esp_err_t spi1_start(void *arg)
8384
* From 1 to 3, the lock efficiency decreases.
8485
*/
8586
#if SPI_FLASH_CACHE_NO_DISABLE
86-
k_mutex_lock(&s_spi1_flash_mutex, K_FOREVER);
87+
if (k_is_pre_kernel()) {
88+
s_spi1_key = irq_lock();
89+
} else {
90+
k_mutex_lock(&s_spi1_flash_mutex, K_FOREVER);
91+
}
8792
#else
8893
//directly disable the cache and interrupts when lock is not used
8994
cache_disable(NULL);
@@ -100,7 +105,11 @@ static IRAM_ATTR esp_err_t spi1_end(void *arg)
100105
* There are three ways for ESP Flash API lock, see `spi1_start`
101106
*/
102107
#if SPI_FLASH_CACHE_NO_DISABLE
103-
k_mutex_unlock(&s_spi1_flash_mutex);
108+
if (k_is_pre_kernel()) {
109+
irq_unlock(s_spi1_key);
110+
} else {
111+
k_mutex_unlock(&s_spi1_flash_mutex);
112+
}
104113
#else
105114
cache_enable(NULL);
106115
#endif

zephyr/esp32s3/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ if(CONFIG_SOC_SERIES_ESP32S3)
241241
../../components/esp_psram/${CONFIG_SOC_SERIES}/esp_psram_impl_octal.c
242242
)
243243

244+
zephyr_sources_ifdef(CONFIG_SPIRAM_FETCH_INSTRUCTIONS
245+
../../components/esp_psram/mmu_psram_flash.c
246+
)
244247
endif()
245248

246249
zephyr_sources_ifdef(

zephyr/port/include/esp_heap_adapter.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,41 @@
2020
#define os_wpa_calloc_func(_nmemb, _size) k_calloc(_nmemb, _size)
2121
#define os_wpa_free_func(_mem) k_free(_mem)
2222

23+
#elif defined(CONFIG_ESP_WIFI_WIFI_SPIRAM)
24+
25+
#define esp_wifi_malloc_func(_size) \
26+
shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _size)
27+
#define esp_wifi_calloc_func(_nmemb, _size) \
28+
{ \
29+
void *p; \
30+
p = shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _nmemb * _size); \
31+
if (p) { \
32+
memset(p, 0, _nmemb * _size); \
33+
} \
34+
return p; \
35+
}
36+
#define esp_wifi_free_func(_mem) shared_multi_heap_free(_mem)
37+
38+
#define os_wpa_malloc_func(_size) shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _size)
39+
#define os_wpa_realloc_func(_ptr, _size) \
40+
{ void *p; \
41+
if (_ptr) { \
42+
shared_multi_heap_free(_ptr); \
43+
} \
44+
p = shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _size); \
45+
return p; \
46+
}
47+
#define os_wpa_calloc_func(_nmemb, _size) \
48+
{ \
49+
void *p; \
50+
p = shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _nmemb * _size); \
51+
if (p) { \
52+
memset(p, 0, _nmemb * _size); \
53+
} \
54+
return p; \
55+
}
56+
#define os_wpa_free_func(_mem) shared_multi_heap_free(_mem)
57+
2358
#else
2459

2560
#define esp_wifi_malloc_func(_size) malloc(_size)
@@ -39,6 +74,11 @@
3974
#define esp_bt_malloc_func(_size) k_malloc(_size)
4075
#define esp_bt_free_func(_mem) k_free(_mem)
4176

77+
#elif defined(CONFIG_ESP_BT_HEAP_SPIRAM)
78+
79+
#define esp_bt_malloc_func(_size) shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, _size)
80+
#define esp_bt_free_func(_mem) shared_multi_heap_free(_mem)
81+
4282
#else
4383

4484
#define esp_bt_malloc_func(_size) malloc(_size)

0 commit comments

Comments
 (0)