diff --git a/ESP32/platformio.ini b/ESP32/platformio.ini index 88edc7f..e44c199 100644 --- a/ESP32/platformio.ini +++ b/ESP32/platformio.ini @@ -17,7 +17,7 @@ board_build.filesystem = littlefs lib_deps = greiman/SdFat@^2.1.2 adafruit/Adafruit NeoPixel bblanchon/ArduinoJson@^6.19.4 -build_flags = -std=gnu++2a -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue +build_flags = -std=gnu++2a -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -DCONFIG_SPIRAM_USE_MALLOC build_unflags = -std=gnu++11 -std=gnu++17 extra_scripts = pre:prepare.py @@ -45,8 +45,8 @@ monitor_speed = 115200 upload_speed = 1000000 board_build.filesystem = littlefs lib_deps = greiman/SdFat@^2.1.2 - adafruit/Adafruit NeoPixel - bblanchon/ArduinoJson@^6.19.4 + adafruit/Adafruit NeoPixel + bblanchon/ArduinoJson@^6.19.4 build_flags = -std=gnu++17 -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -DCONFIG_SPIRAM_USE_MALLOC build_unflags = -std=gnu++11 extra_scripts = pre:prepare.py diff --git a/bus.cpp b/bus.cpp index b5e1af8..f2914f2 100644 --- a/bus.cpp +++ b/bus.cpp @@ -637,9 +637,9 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c uint32_t m_offset = a; if (mmu_->is_enabled() || (is_write && (mmu_->getMMR0() & (1 << 8 /* maintenance check */)))) { - const uint8_t apf = a >> 13; // active page field + uint8_t apf = a >> 13; // active page field - bool d = space == d_space && mmu_->get_use_data_space(run_mode) ? space == d_space : false; + bool d = space == d_space && mmu_->get_use_data_space(run_mode) ? space == d_space : false; uint16_t p_offset = a & 8191; // page offset diff --git a/memory.cpp b/memory.cpp index 6a9f1cf..ab3d526 100644 --- a/memory.cpp +++ b/memory.cpp @@ -1,4 +1,4 @@ -// (C) 2018-2023 by Folkert van Heusden +// (C) 2018-2024 by Folkert van Heusden // Released under MIT license #if defined(ESP32) @@ -8,38 +8,30 @@ #include "memory.h" -memory::memory(const uint32_t size) : size(size) +memory::memory(const uint32_t size): size(size) { #if defined(ESP32) Serial.print(F("Memory size (in bytes, decimal): ")); Serial.println(size); - if (size > 12 * 8192) { + if (size > 12 * 8192 && psramFound()) { Serial.println(F("Using PSRAM")); - is_psram = true; m = reinterpret_cast(ps_malloc(size)); reset(); } else { - m = new uint8_t[size](); + m = reinterpret_cast(calloc(1, size)); } #else - m = new uint8_t[size](); + m = reinterpret_cast(calloc(1, size)); #endif } memory::~memory() { -#if defined(ESP32) - if (is_psram) - free(m); - else - delete [] m; -#else - delete [] m; -#endif + free(m); } void memory::reset() diff --git a/memory.h b/memory.h index c7b4ae1..fdf3e3a 100644 --- a/memory.h +++ b/memory.h @@ -13,9 +13,6 @@ class memory private: const uint32_t size { 0 }; uint8_t *m { nullptr }; -#ifdef ESP32 - bool is_psram { false }; -#endif public: memory(const uint32_t size);