本文へ移動
cccskills
無料GitHub で公開

memory-freertos

Memory management and FreeRTOS context for the Megahub ESP32 project. Use when dealing with heap allocation, stack size, task creation, inter-task communication, semaphores, queues, or any ESP32 memory constraints.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md3.2 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Memory Management & FreeRTOS — Megahub ESP32

Memory Budget (real device measurements)

Point in startupFree heap
After IMU init~170 KB
After Lua state creation~140 KB
After LEGO motor init~140 KB
After configuration load~139 KB
After BT stack start~76 KB
After BLE characteristics setup~76 KB
During BLE connection (connected)~63–73 KB

PSRAM: ~4.1 MB available (confirmed present on this board — ESP.getFreePsram()).

BT stack alone consumes ~65 KB of heap. Every BLE connection consumes an additional ~30 KB.


Memory Rules

  • Stack: Never allocate large arrays as local variables. Use static, heap, or PSRAM.
  • Heap: Minimize new/malloc. Every allocation needs a matching delete/free.
  • Strings: Avoid String += loops. Prefer std::string::reserve() or fixed char[] buffers.
  • PSRAM: Available, but don't assume — always check. Use for large buffers if needed.
  • Constants: Use const and PROGMEM for large constant data to keep it in flash.
  • Lua VM: Runs in heap. Large scripts reduce available heap for everything else.

FreeRTOS Task Reference

Known tasks and their stack high-water marks (from real device logs):

TaskPriorityStack HWM (words)Notes
loopTask1272Arduino main loop
BTMsgProcessor22968–7528Processes BLE messages
HIDEventTask51920Classic BT HID events
PortStatus11420LEGO port status reporting
StatusMonitor12452Heap/task monitoring
Device monitor11776Lua thread for device monitoring
BTU_TASK203624–4988BT stack internal
BTC_TASK194328–4364BT stack internal
hciT221516–1544BT HCI layer
btController232088BT controller
esp_timer224048ESP timer service
ipc0/124356/476IPC (highest priority)

⚠ loopTask HWM of 272 words is critically low — avoid adding stack usage to the main loop.


FreeRTOS Rules

  • Mutexes: Always use xSemaphoreTake with a timeout — never block indefinitely
  • Task stacks: Monitor with uxTaskGetStackHighWaterMark(). Stack overflow = silent crash.
  • Inter-task communication: Use queues or semaphores — not global variables without synchronization
  • BLE callbacks: Run in BLE task context — post work to a queue, handle in application task
  • Never block in BLE callbacks, HID callbacks, or ISRs
  • Task priorities: BT stack tasks run at 19–24. Application tasks at 1–5. Don't starve the BT stack.

Monitoring Pattern

// Log heap + PSRAM
INFO("Free heap: %d bytes, Free PSRAM: %d bytes",
     ESP.getFreeHeap(), ESP.getFreePsram());

// Log task stack (for current task)
INFO("Stack HWM: %d words", uxTaskGetStackHighWaterMark(NULL));

// Log all task stacks (use vTaskList for full snapshot)

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

ble

無料

Bluetooth context for the Megahub project. Use when working on BLE GATT server, Classic Bluetooth HID host, Web Bluetooth API integration, btremote library, connection handling, or any Bluetooth-related firmware code.

日本語の概要は準備中です。原文の説明を表示しています。

mirkosertic/Megahub72026年9月29日 更新

blockly

無料

Blockly visual programming context for the Megahub project. Use when adding, modifying, or debugging custom Blockly blocks, the Lua code generator, the toolbox, block colors, or the BLOCKS.md documentation generation script.

日本語の概要は準備中です。原文の説明を表示しています。

mirkosertic/Megahub72026年9月29日 更新

Documentation structure and maintenance rules for the Megahub project. Use whenever making user-facing changes — adding features, changing behavior, fixing hardware compatibility, or modifying configuration. Describes which files to update, the README structure, and writing style.

日本語の概要は準備中です。原文の説明を表示しています。

mirkosertic/Megahub72026年9月29日 更新

Core firmware context for the Megahub ESP32 project. Use when working on PlatformIO configuration, build scripts, library structure, main.cpp, or general ESP32 firmware development. Covers build system, project structure, common pitfalls, and debugging.

日本語の概要は準備中です。原文の説明を表示しています。

mirkosertic/Megahub72026年9月29日 更新

frontend

無料

Frontend development context for the Megahub project. Use when working on the web-based IDE, Vite build system, Blockly visual programming, Web Bluetooth API integration, JavaScript frontend code, CSS/styles, UI components, or anything in the /frontend/ directory.

日本語の概要は準備中です。原文の説明を表示しています。

mirkosertic/Megahub72026年9月29日 更新

LEGO Powered Up protocol context for the Megahub project. Use when working on LEGO device communication, lpfuart library, UART parsing, motor control, sensor modes, device initialization, or debugging UART noise/corruption issues.

日本語の概要は準備中です。原文の説明を表示しています。

mirkosertic/Megahub72026年9月29日 更新

mirkosertic のスキルをすべて見る

このスキルの問題を報告する