diff --git a/firmware/lib/cv/cv.cpp b/firmware/lib/cv/cv.cpp index 7f0be59..d76629a 100644 --- a/firmware/lib/cv/cv.cpp +++ b/firmware/lib/cv/cv.cpp @@ -6,8 +6,15 @@ #include void cv_init(CVState& state) { - state = CVState{}; // value-initialize — calls vector default ctor correctly - state.next_id = 1; + // Initialize members directly — avoid CVState{} temporary which puts 9KB on stack + memset(state.background, 0, sizeof(state.background)); + state.bg_valid = false; + state.last_motion_frame = 0; + state.frame_index = 0; + state.next_id = 1; + state.tracks.clear(); + state.entries = 0; + state.exits = 0; } void cv_reset_counts(CVState& state) { @@ -83,7 +90,7 @@ CVResult cv_process(CVState& state, const uint8_t* frame, uint8_t line_pct) { return result; } - uint8_t fg[CV_PIXELS]; + static uint8_t fg[CV_PIXELS]; // static: avoids 9KB on task stack frame_diff(frame, state.background, fg, CV_PIXELS); int fg_count = 0; diff --git a/firmware/partitions_4mb_ota.csv b/firmware/partitions_4mb_ota.csv new file mode 100644 index 0000000..303701f --- /dev/null +++ b/firmware/partitions_4mb_ota.csv @@ -0,0 +1,6 @@ +# Name, Type, SubType, Offset, Size +nvs, data, nvs, 0x9000, 0x5000 +otadata, data, ota, 0xe000, 0x2000 +app0, app, ota_0, 0x10000, 0x180000 +app1, app, ota_1, 0x190000, 0x180000 +spiffs, data, spiffs, 0x310000, 0xF0000 diff --git a/firmware/platformio.ini b/firmware/platformio.ini index 8ca4235..eca9f14 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -6,15 +6,17 @@ default_envs = timercam platform = espressif32@6.6.0 board = m5stack-timer-cam framework = arduino -board_build.partitions = partitions_8mb_ota.csv +board_build.partitions = partitions_4mb_ota.csv build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -DCORE_DEBUG_LEVEL=3 -DCONFIG_BT_NIMBLE_ENABLED=1 -DCONFIG_SPIRAM_USE_MALLOC=1 + -DCONFIG_ARDUINO_LOOP_STACK_SIZE=16384 monitor_speed = 115200 -upload_speed = 921600 +upload_speed = 115200 +upload_flags = --no-stub lib_deps = tzapu/WiFiManager@^2.0.17 bblanchon/ArduinoJson@^7.0.0 diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index d474d02..689f98d 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -153,7 +153,7 @@ void setup() { s_cv_mutex = xSemaphoreCreateMutex(); - xTaskCreatePinnedToCore(task_camera, "cam", 4096, nullptr, 2, nullptr, 1); + xTaskCreatePinnedToCore(task_camera, "cam", 8192, nullptr, 2, nullptr, 1); xTaskCreatePinnedToCore(task_reporter, "rep", 8192, nullptr, 1, nullptr, 0); }