Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test PSRAM by using stdlib new operator. works. #358

Open
wants to merge 2 commits into
base: fiona/PSRAM
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions firmware/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ build_flags =
-DENABLE_FPS
-g
-frtti
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-nostdlib
; -DBOARD_HAS_PSRAM
; -mfix-esp32-psram-cache-issue
; -nostdlib
#-DENABLE_CRASHDUMP
#-DENABLE_PERFMON
# use this while debugging
Expand Down
60 changes: 30 additions & 30 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
#include "tasks/taskRegistry.hpp"
#include "utils/serial.hpp"

#include <cstdlib>
#include <new>
// #include <cstdlib>
// #include <new>

void *operator new(size_t size) noexcept { return ps_malloc(size); }
void operator delete(void *p) noexcept { free(p); }
void *operator new[](size_t size) noexcept { return operator new(size); }
void operator delete[](void *p) noexcept { operator delete(p); }
void *operator new(size_t size, std::nothrow_t) noexcept { return operator new(size); }
void operator delete(void *p, std::nothrow_t) noexcept { operator delete(p); }
void *operator new[](size_t size, std::nothrow_t) noexcept { return operator new(size); }
void operator delete[](void *p, std::nothrow_t) noexcept { operator delete(p); }
// void *operator new(size_t size) noexcept { return ps_malloc(size); }
// void operator delete(void *p) noexcept { free(p); }
// void *operator new[](size_t size) noexcept { return operator new(size); }
// void operator delete[](void *p) noexcept { operator delete(p); }
// void *operator new(size_t size, std::nothrow_t) noexcept { return operator new(size); }
// void operator delete(void *p, std::nothrow_t) noexcept { operator delete(p); }
// void *operator new[](size_t size, std::nothrow_t) noexcept { return operator new(size); }
// void operator delete[](void *p, std::nothrow_t) noexcept { operator delete(p); }


void setup()
Expand All @@ -24,29 +24,29 @@ void setup()
Serial.begin(115200);
bool ramFound = psramInit();
log_d("Ram found %d", ramFound);
DPSerial::init();
DPSerial::sendInstantDebugLog("========== START ==========");
Tasks.emplace(
std::piecewise_construct,
std::forward_as_tuple("I/O"),
std::forward_as_tuple(&ioSetup, &ioLoop, "I/O", 0));
Tasks.at("I/O").run();
Tasks.at("I/O").setLogFps();
Tasks.emplace(
std::piecewise_construct,
std::forward_as_tuple("Physics"),
std::forward_as_tuple(&physicsSetup, &physicsLoop, "Physics", 1));
Tasks.at("Physics").run();
// DPSerial::init();
// DPSerial::sendInstantDebugLog("========== START ==========");
// Tasks.emplace(
// std::piecewise_construct,
// std::forward_as_tuple("I/O"),
// std::forward_as_tuple(&ioSetup, &ioLoop, "I/O", 0));
// Tasks.at("I/O").run();
// Tasks.at("I/O").setLogFps();
// Tasks.emplace(
// std::piecewise_construct,
// std::forward_as_tuple("Physics"),
// std::forward_as_tuple(&physicsSetup, &physicsLoop, "Physics", 1));
// Tasks.at("Physics").run();

TaskHandle_t defaultTask = xTaskGetCurrentTaskHandle();
DPSerial::sendInstantDebugLog("default task handle is %i", defaultTask);
vTaskSuspend(NULL);
taskYIELD();
DPSerial::sendInstantDebugLog("setup - this should not be printed");
// TaskHandle_t defaultTask = xTaskGetCurrentTaskHandle();
// DPSerial::sendInstantDebugLog("default task handle is %i", defaultTask);
// vTaskSuspend(NULL);
// taskYIELD();
// DPSerial::sendInstantDebugLog("setup - this should not be printed");
}

void loop()
{
DPSerial::sendInstantDebugLog("loop - this should not be printed");
delay(1000);
// DPSerial::sendInstantDebugLog("loop - this should not be printed");
// delay(1000);
}
15 changes: 15 additions & 0 deletions firmware/src/utils/spiramallocator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "esp_heap_caps.h"

struct SpiRamAllocator {
void* allocate(size_t size) {
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
}

void deallocate(void* pointer) {
heap_caps_free(pointer);
}

void* reallocate(void* ptr, size_t new_size) {
return heap_caps_realloc(ptr, new_size, MALLOC_CAP_SPIRAM);
}
};