Skip to content

Commit 661b5cf

Browse files
Glauber Maroto Ferreiranashif
authored andcommitted
soc: xtensa: esp32s2: add data cache initialization
during esp32s2 boot. Signed-off-by: Glauber Maroto Ferreira <[email protected]>
1 parent 779ef06 commit 661b5cf

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

soc/xtensa/esp32s2/Kconfig.soc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ choice
5858

5959
endchoice
6060

61+
choice
62+
prompt "Data cache line size"
63+
default ESP32S2_DATA_CACHE_LINE_32B
64+
65+
config ESP32S2_DATA_CACHE_LINE_16B
66+
bool "16 Bytes"
67+
68+
config ESP32S2_DATA_CACHE_LINE_32B
69+
bool "32 Bytes"
70+
71+
endchoice
72+
6173
config ESP32S2_INSTRUCTION_CACHE_SIZE
6274
hex
6375
default 0x4000 if ESP32S2_INSTRUCTION_CACHE_16KB

soc/xtensa/esp32s2/soc.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,45 @@ void __attribute__((section(".iram1"))) __start(void)
8080
esp_rom_Cache_Invalidate_ICache_All();
8181
esp_rom_Cache_Resume_ICache(0);
8282

83+
/*
84+
* If we need use SPIRAM, we should use data cache, or if we want to
85+
* access rodata, we also should use data cache.
86+
* Configure the mode of data : cache size, cache associated ways, cache
87+
* line size.
88+
* Enable data cache, so if we don't use SPIRAM, it just works.
89+
*/
90+
#if CONFIG_ESP32S2_INSTRUCTION_CACHE_8KB
91+
#if CONFIG_ESP32S2_DATA_CACHE_8KB
92+
esp_rom_Cache_Allocate_SRAM(CACHE_MEMORY_ICACHE_LOW, CACHE_MEMORY_DCACHE_LOW,
93+
CACHE_MEMORY_INVALID, CACHE_MEMORY_INVALID);
94+
cache_size = CACHE_SIZE_8KB;
95+
#else
96+
esp_rom_Cache_Allocate_SRAM(CACHE_MEMORY_ICACHE_LOW, CACHE_MEMORY_DCACHE_LOW,
97+
CACHE_MEMORY_DCACHE_HIGH, CACHE_MEMORY_INVALID);
98+
cache_size = CACHE_SIZE_16KB;
99+
#endif
100+
#else
101+
#if CONFIG_ESP32S2_DATA_CACHE_8KB
102+
esp_rom_Cache_Allocate_SRAM(CACHE_MEMORY_ICACHE_LOW, CACHE_MEMORY_ICACHE_HIGH,
103+
CACHE_MEMORY_DCACHE_LOW, CACHE_MEMORY_INVALID);
104+
cache_size = CACHE_SIZE_8KB;
105+
#else
106+
esp_rom_Cache_Allocate_SRAM(CACHE_MEMORY_ICACHE_LOW, CACHE_MEMORY_ICACHE_HIGH,
107+
CACHE_MEMORY_DCACHE_LOW, CACHE_MEMORY_DCACHE_HIGH);
108+
cache_size = CACHE_SIZE_16KB;
109+
#endif
110+
#endif
111+
112+
cache_ways = CACHE_4WAYS_ASSOC;
113+
#if CONFIG_ESP32S2_DATA_CACHE_LINE_16B
114+
cache_line_size = CACHE_LINE_SIZE_16B;
115+
#else
116+
cache_line_size = CACHE_LINE_SIZE_32B;
117+
#endif
118+
esp_rom_Cache_Set_DCache_Mode(cache_size, cache_ways, cache_line_size);
119+
esp_rom_Cache_Invalidate_DCache_All();
120+
esp_rom_Cache_Enable_DCache(0);
121+
83122
#if !CONFIG_BOOTLOADER_ESP_IDF
84123
/* The watchdog timer is enabled in the 1st stage (ROM) bootloader.
85124
* We're done booting, so disable it.

soc/xtensa/esp32s2/soc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ extern void esp_rom_Cache_Invalidate_ICache_All(void);
4545
extern void esp_rom_Cache_Resume_ICache(uint32_t autoload);
4646
extern int esp_rom_Cache_Invalidate_Addr(uint32_t addr, uint32_t size);
4747

48+
/* data-cache related rom functions */
49+
extern void esp_rom_Cache_Set_DCache_Mode(cache_size_t cache_size, cache_ways_t ways,
50+
cache_line_size_t cache_line_size);
51+
52+
extern void esp_rom_Cache_Invalidate_DCache_All(void);
53+
extern void esp_rom_Cache_Enable_DCache(uint32_t autoload);
54+
55+
extern void esp_rom_Cache_Set_DCache_Mode(cache_size_t cache_size, cache_ways_t ways,
56+
cache_line_size_t cache_line_size);
57+
4858
/* ROM information related to SPI Flash chip timing and device */
4959
extern esp_rom_spiflash_chip_t g_rom_flashchip;
5060
extern uint8_t g_rom_spiflash_dummy_len_plus[];

0 commit comments

Comments
 (0)