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