Skip to content

Commit 833e139

Browse files
committed
Fix PSRAM support
1 parent 8c5f8d6 commit 833e139

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

cores/esp32/Esp.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,36 @@ uint32_t EspClass::getMaxAllocHeap(void)
133133

134134
uint32_t EspClass::getPsramSize(void)
135135
{
136-
multi_heap_info_t info;
137-
heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
138-
return info.total_free_bytes + info.total_allocated_bytes;
136+
if(psramFound()){
137+
multi_heap_info_t info;
138+
heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
139+
return info.total_free_bytes + info.total_allocated_bytes;
140+
}
141+
return 0;
139142
}
140143

141144
uint32_t EspClass::getFreePsram(void)
142145
{
143-
return heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
146+
if(psramFound()){
147+
return heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
148+
}
149+
return 0;
144150
}
145151

146152
uint32_t EspClass::getMinFreePsram(void)
147153
{
148-
return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM);
154+
if(psramFound()){
155+
return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM);
156+
}
157+
return 0;
149158
}
150159

151160
uint32_t EspClass::getMaxAllocPsram(void)
152161
{
153-
return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM);
162+
if(psramFound()){
163+
return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM);
164+
}
165+
return 0;
154166
}
155167

156168
static uint32_t sketchSize(sketchSize_t response) {

cores/esp32/esp32-hal-misc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void initArduino()
210210
#ifdef F_CPU
211211
setCpuFrequencyMhz(F_CPU/1000000);
212212
#endif
213-
#if CONFIG_SPIRAM_SUPPORT
213+
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
214214
psramInit();
215215
#endif
216216
esp_log_level_set("*", CONFIG_LOG_DEFAULT_LEVEL);

cores/esp32/esp32-hal-psram.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414

1515
#include "esp32-hal.h"
1616

17-
#if CONFIG_SPIRAM_SUPPORT
17+
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
1818
#include "soc/efuse_reg.h"
1919
#include "esp_heap_caps.h"
2020

2121
#include "esp_system.h"
2222
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
2323
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
2424
#include "esp32/spiram.h"
25+
#elif CONFIG_IDF_TARGET_ESP32S2
26+
#include "esp32s2/spiram.h"
27+
#include "esp32s2/rom/cache.h"
2528
#else
2629
#error Target CONFIG_IDF_TARGET is not supported
2730
#endif
@@ -40,6 +43,7 @@ bool psramInit(){
4043
if (spiramFailed) {
4144
return false;
4245
}
46+
#if CONFIG_IDF_TARGET_ESP32
4347
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
4448
uint32_t pkg_ver = chip_ver & 0x7;
4549
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) {
@@ -48,13 +52,21 @@ bool psramInit(){
4852
return false;
4953
}
5054
esp_spiram_init_cache();
55+
#elif CONFIG_IDF_TARGET_ESP32S2
56+
extern void esp_config_data_cache_mode(void);
57+
esp_config_data_cache_mode();
58+
Cache_Enable_DCache(0);
59+
#endif
5160
if (esp_spiram_init() != ESP_OK) {
5261
spiramFailed = true;
5362
log_w("PSRAM init failed!");
63+
#if CONFIG_IDF_TARGET_ESP32
5464
pinMatrixOutDetach(16, false, false);
5565
pinMatrixOutDetach(17, false, false);
66+
#endif
5667
return false;
5768
}
69+
esp_spiram_init_cache();
5870
if (!esp_spiram_test()) {
5971
spiramFailed = true;
6072
log_e("PSRAM test failed!");

0 commit comments

Comments
 (0)