Published on

Syllabus - C++ Firmware Engineering for ESP32 (Foundation → Production)

Authors

📘 Syllabus: C++ Firmware Engineering for ESP32 (Foundation → Production)

Environment: ESP32 + VSCode + Arduino Community Edition Project Base: IndustrialNode/IndustrialNode.ino Use Case: Generic Sensor + Relay Node



🧭 Learning Progression Model

Course ini adalah satu sistem yang berkembang:

Execution Awareness
Concurrency Awareness
Memory Awareness
Ownership & OOP
Layered Architecture
Communication State
Reliability Thinking
Production Discipline

Setiap fase:

  • Mengubah cara berpikir
  • Mengubah struktur kode
  • Mengubah bentuk sistem

📆 Phase 1 — Foundation (Week 1–5)

Fokus:

Memahami realitas sistem (execution, concurrency, memory)


Week 1 — Execution Reality (Article 01)

Concept:

  • loop() = task
  • FreeRTOS berjalan di bawah Arduino
  • ISR preemption
  • Dual-core awareness

Practice:

  • Bandingkan:

    • delay()
    • busy loop
  • Observasi jitter sederhana

System State:

Single loop
No structure
Global state

Week 2 — Concurrency (Article 02)

Concept:

  • Task & scheduler
  • Preemption
  • Race condition
  • Shared state danger

Practice:

  • Simulasi race condition (ISR + loop)

  • Refactor:

    • global → event/flag sederhana

System State:

Masih flat
Mulai sadar concurrency risk

Week 3 — Execution Model Deep Dive (Article 03)

Concept:

  • loopTask internal
  • Core mapping
  • Stack per task
  • Context switch

Practice:

  • Eksperimen stack:

    • buffer besar di loop
  • Observasi behavior aneh

System State:

Masih flat
Mulai sadar constraint system

Week 4 — Memory Model (Article 04)

Concept:

  • Heap vs stack
  • Fragmentasi
  • Object lifetime
  • Hidden allocation

Practice:

  • Stress test:

    • String allocation berulang
  • Observasi heap behavior

System State:

Masih flat
Mulai muncul masalah real

Week 5 — OOP Foundation (Article 05)

Concept:

  • Encapsulation = ownership
  • Constructor & lifecycle
  • Composition
  • Hindari dynamic allocation

Practice:

  • Refactor:

    • relay → class
    • sensor → class

System State:

Object-based
Ownership mulai jelas
Masih tanpa layer

📆 Phase 2 — System Structuring (Week 6–8)

Fokus:

Mengendalikan kompleksitas sistem


Week 6 — 3-Layer Architecture (Article 06)

Concept:

  • app* / svc* / drv_
  • Dependency direction
  • Boundary system

Practice:

  • Refactor full project:

    • pindahkan logic ke svc_
    • isolate hardware ke drv_

System State:

Layered system
Dependency mulai terkendali

Week 7 — Communication & State (Article 07)

Concept:

  • State machine
  • Event-driven
  • Callback hazard
  • Transport vs domain

Practice:

  • Introduce:

    • svc_CommManager
  • Refactor:

    • MQTT callback → event

System State:

Communication isolated
State mulai eksplisit

Week 8 — Reliability Thinking (Article 08)

Concept:

  • Fail-safe vs fail-open
  • Observability
  • Watchdog
  • Error containment

Practice:

  • Tambahkan:

    • fail-safe relay logic
    • basic logging

System State:

System-aware
Mulai stabil
Tetapi belum production-grade

📆 Phase 3 — Production Hardening (Week 9–16)

Fokus:

Mengunci disiplin sistem


Week 9–10 — Dependency Locking

  • Larang:

    • upward dependency
    • cross-layer access
  • Audit include


Week 11–12 — Memory Discipline

  • Minimalkan dynamic allocation

  • Audit:

    • String usage
    • hidden allocation
  • Monitor heap


Week 13 — Communication Hardening

  • Centralize:

    • reconnect logic
  • Tambahkan:

    • backoff strategy
    • retry control

Week 14 — Reliability Formalization

  • Error handling pattern
  • State fallback
  • Watchdog-aware design

Week 15 — System Audit

  • Dependency check
  • Memory check
  • Communication check
  • Failure scenario test

Week 16 — Production Freeze

  • Final structure locked
  • Tidak ada perubahan arsitektur
  • Hanya bug fix

🧪 Learning Mechanics

Setiap minggu terdiri dari:

Concept → Practice → System Change

Bukan:

Concept → selesai

⚠️ Kenapa Production Tidak Bisa Dilewati

Tanpa Production Hardening:

  • Heap akan fragmentasi
  • Race condition akan muncul
  • Reconnect akan chaotic
  • Watchdog reset akan sporadis
  • Dependency akan liar

Production bukan fase tambahan.

Production adalah konsekuensi dari kompleksitas sistem.


🎯 Outcome Akhir

Setelah menyelesaikan course ini:

Engineer mampu:

  • Memahami execution model ESP32
  • Mendesain firmware berbasis layering
  • Mengontrol dependency
  • Mengelola memory dengan disiplin
  • Mengisolasi komunikasi
  • Mendesain sistem fail-safe
  • Menghasilkan firmware yang stabil jangka panjang

🔒 Final Positioning

Course ini bukan tutorial.

Course ini adalah:

Transformasi dari firmware eksperimental menjadi firmware production-grade


Catatan Penyusunan Artikel ini disusun sebagai materi edukasi dan referensi umum berdasarkan berbagai sumber pustaka, praktik lapangan, serta bantuan alat penulisan. Pembaca disarankan untuk melakukan verifikasi lanjutan dan penyesuaian sesuai dengan kondisi serta kebutuhan masing-masing sistem.