Skip to content

Part 8: Embedded Programming Hardware

Lập trình nhúng — nơi code của bạn chạy trên vi điều khiển với tài nguyên cực kỳ hạn chế.

Embedded là gì?

┌─────────────────────────────────────────────────────────────────┐
│                    EMBEDDED vs DESKTOP                           │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   DESKTOP PC                      EMBEDDED (MCU)                │
│   ──────────                      ──────────────                │
│   RAM: 16 GB                      RAM: 2 KB - 512 KB            │
│   Storage: 1 TB SSD               Flash: 16 KB - 2 MB           │
│   CPU: 3+ GHz                     CPU: 16-200 MHz               │
│   OS: Windows/Linux               OS: None (bare-metal)         │
│   Power: Wall outlet              Power: Battery/Low power      │
│                                                                 │
│   💡 Embedded = Constraints Everywhere!                         │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Tại sao học Embedded C++?

Real-world Applications

┌─────────────────────────────────────────────────────────────────┐
│                    EMBEDDED EVERYWHERE                           │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   🚗 AUTOMOTIVE              🏥 MEDICAL DEVICES                 │
│   ─────────────              ─────────────────                  │
│   ECU, ADAS, Infotainment    Pacemakers, Monitors              │
│                                                                 │
│   📱 IoT & WEARABLES         🎮 GAME CONTROLLERS                │
│   ──────────────────         ───────────────────                │
│   Smartwatches, Sensors      Xbox, PlayStation                  │
│                                                                 │
│   🏭 INDUSTRIAL              ✈️ AEROSPACE                       │
│   ──────────────             ──────────                         │
│   PLCs, Robotics             Drones, Satellites                 │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Embedded Programming Mindset

Desktop MindsetEmbedded Mindset
RAM is cheapEvery byte counts
Use new/delete freelyAvoid heap allocation
STL containers everywhereStatic arrays, no STL
Exceptions for errorsNo exceptions (overhead)
OS handles timingYou control everything

Module Structure

TopicDescription
Memory ConstraintsCoding cho low RAM/ROM
Bit ManipulationControl hardware registers
volatile KeywordHardware mapping
Smart Pointersunique_ptr vs raw
InterruptsISR basics

Prerequisites

📋 YÊU CẦU

  • C++ Basics — Variables, functions, pointers
  • OOP — Classes, inheritance
  • 🔸 Basic electronics (recommended)

Learning Path

  1. 💾 Memory Constraints — Sống trong không gian nhỏ
  2. 🔢 Bit Manipulation — Control từng bit
  3. 🔒 volatile — Hardware access
  4. 🎯 Smart Pointers — Khi nào dùng gì
  5. Interrupts — Phản hồi hardware events