Skip to content

Commit 4a279b4

Browse files
donghengqazxiaoxiang781216
authored andcommitted
xtensa/esp32s3: Support 32MB PSRAM
1 parent 78006f9 commit 4a279b4

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

arch/xtensa/src/esp32s3/esp32s3_spiram.c

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,38 @@ extern int cache_dbus_mmu_set(uint32_t ext_ram, uint32_t vaddr,
9797
uint32_t paddr, uint32_t psize,
9898
uint32_t num, uint32_t fixed);
9999

100+
/****************************************************************************
101+
* Private Functions
102+
****************************************************************************/
103+
104+
/****************************************************************************
105+
* Name: mmu_valid_space
106+
*
107+
* Description:
108+
* Calculate MMU valid space.
109+
*
110+
* Input Parameters:
111+
* start_address - Pointer to store MMU mapped start address
112+
*
113+
* Returned Value:
114+
* MMU valid space size by bytes.
115+
*
116+
****************************************************************************/
117+
118+
static inline uint32_t mmu_valid_space(uint32_t *start_address)
119+
{
120+
for (int i = 0; i < FLASH_MMU_TABLE_SIZE; i++)
121+
{
122+
if (FLASH_MMU_TABLE[i] & MMU_INVALID)
123+
{
124+
*start_address = DRAM0_CACHE_ADDRESS_LOW + i * MMU_PAGE_SIZE;
125+
return (FLASH_MMU_TABLE_SIZE - i) * MMU_PAGE_SIZE;
126+
}
127+
}
128+
129+
return 0;
130+
}
131+
100132
/****************************************************************************
101133
* Public Functions
102134
****************************************************************************/
@@ -109,24 +141,32 @@ extern int cache_dbus_mmu_set(uint32_t ext_ram, uint32_t vaddr,
109141
void IRAM_ATTR esp_spiram_init_cache(void)
110142
{
111143
uint32_t regval;
112-
int ret = psram_get_available_size(&g_mapped_size);
144+
uint32_t psram_size;
145+
uint32_t mapped_vaddr_size;
113146

147+
int ret = psram_get_available_size(&psram_size);
114148
if (ret != OK)
115149
{
116150
abort();
117151
}
118152

119-
merr("Mapped size = %d\n", g_mapped_size);
153+
minfo("PSRAM available size = %d\n", psram_size);
120154

121-
if ((SOC_EXTRAM_DATA_HIGH - SOC_EXTRAM_DATA_LOW) < g_mapped_size)
155+
mapped_vaddr_size = mmu_valid_space(&g_mapped_vaddr_start);
156+
minfo("Virtual address size = %d\n", mapped_vaddr_size);
157+
158+
if (mapped_vaddr_size < psram_size)
122159
{
123160
/* Decide these logics when there's a real PSRAM with larger size */
124161

125-
merr("Virtual address not enough for PSRAM!");
126-
abort();
162+
g_mapped_size = mapped_vaddr_size;
163+
mwarn("Virtual address not enough for PSRAM, only %d size is mapped!",
164+
g_mapped_size);
165+
}
166+
else
167+
{
168+
g_mapped_size = psram_size;
127169
}
128-
129-
g_mapped_vaddr_start = SOC_EXTRAM_DATA_HIGH - g_mapped_size;
130170

131171
/* Suspend DRAM Case during configuration */
132172

@@ -150,7 +190,7 @@ void IRAM_ATTR esp_spiram_init_cache(void)
150190
/* Currently no non-heap stuff on ESP32S3 */
151191

152192
g_allocable_vaddr_start = g_mapped_vaddr_start;
153-
g_allocable_vaddr_end = SOC_EXTRAM_DATA_HIGH;
193+
g_allocable_vaddr_end = g_mapped_vaddr_start + g_mapped_size;
154194
}
155195

156196
/* Simple RAM test. Writes a word every 32 bytes. Takes about a second

0 commit comments

Comments
 (0)