본문으로 건너뛰기
cccskills
무료GitHub에 공개

firmware-core

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md3.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Firmware Core — Megahub ESP32

Build System

PlatformIO configuration — see platformio.ini:

  • Environment: esp-wrover-kit
  • Framework: Arduino + ESP-IDF hybrid
  • Partition table: custom_4mb_noota.csv (no OTA, maximizes app partition)
  • Pre-build scripts (in order):
    1. gitversion.py — injects git hash into firmware
    2. buildfrontend.py — runs npm run build for the selected frontend mode
    3. embedfiles.py — gzips and embeds frontend files into firmware as C arrays

Serial monitor: 115200 baud. Log level controlled by CORE_DEBUG_LEVEL (currently 2).

Logging macros — always use these, never Serial.print():

INFO("Free heap: %d bytes", ESP.getFreeHeap());
WARN("Something unexpected: %d", value);
ERROR("Critical failure in %s", __func__);

Library Structure

lib/
  btremote/       BLE server (Web Bluetooth API) + Classic BT HID host (gamepads)
  commands/       Command processing system — all device operations use this pattern
  configuration/  WiFi & system configuration persistence
  hubwebserver/   HTTP server using PsychicHttp library
  imu/            MPU6050 IMU — I²C, requires proper init sequence
  lpfuart/        LEGO Powered Up UART protocol implementation
  lua/            Lua 5.4 interpreter (embedded, constrained memory)
  megahub/        Main application — wires all libraries together
  portstatus/     Port status tracking and JSON serialization
  inputdevices/   Gamepad/HID input device abstraction
  statusmonitor/  System health monitoring (heap, tasks)

Key Architecture: Command Pattern

All device operations go through lib/commands/. This provides:

  • Serialization of requests from multiple sources (BLE, Web)
  • Consistent error handling and response formatting
  • Command queuing for rate-limited devices

Common Pitfalls

PitfallFix
BLE race conditionUse proper task synchronization (mutex/queue)
Stack overflowUse uxTaskGetStackHighWaterMark(), move large vars to heap
String heap fragmentationUse std::string::reserve() or fixed buffers
Blocking in BLE callbackPost to a queue, handle in application task
Lua crashWrap ALL Lua execution in lua_pcall()
LEGO device timeoutSend keepalive commands, handle wake-up sequence
IMU init failureAlways include required delays in MPU6050 init sequence
Memory leakEvery new/malloc must have matching delete/free

Debugging

pio device monitor --baud 115200   # Serial monitor
pio test                           # Run unit tests
pio run                            # Build only (no upload)

Crash analysis: Enable ESP32 exception decoder in PlatformIO. Stack traces decode to source lines.

Runtime monitoring:

INFO("Free heap: %d bytes, Free PSRAM: %d bytes",
     ESP.getFreeHeap(), ESP.getFreePsram());
INFO("Task stack HWM: %d words", uxTaskGetStackHighWaterMark(NULL));

Known heap budget (from real device logs):

  • After IMU init: ~170KB free heap
  • After Lua state creation: ~140KB free heap
  • After BT stack start: ~75KB free heap
  • PSRAM: ~4.1MB available (confirmed present on this board)

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

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년 10월 18일 업데이트

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년 10월 18일 업데이트

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년 10월 18일 업데이트

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년 10월 18일 업데이트

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년 10월 18일 업데이트

linting

무료

Code formatting and linting context for the Megahub project. Use when writing or reviewing code in C++ or JavaScript, or when running format/lint checks. Describes tool commands, style conventions, and when to apply them.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

mirkosertic/Megahub72026년 10월 18일 업데이트

mirkosertic의 스킬 모두 보기

이 스킬의 문제 신고