Skip to content
เข้าสู่ระบบ

Embedded Systems

เบื่อหน้าจอคอมแล้วใช่ไหม? อยากให้ไฟ LED กระพริบเล่น? Rust บน Embedded กำลังมาแรงมากครับ เพราะมันให้ High-level Abstraction แต่ได้ Low-level Control

ลองนึกภาพว่าเราเขียน code ที่รันบน chip ตัวเล็กๆ ไม่มี OS เลย ทุกอย่างเราคุม 100%!

บนชิปตัวเล็กๆ เราไม่มี OS = ไม่มี filesystem, ไม่มี threads, ไม่มี heap ดังนั้นเราใช้ Standard Library (std) ไม่ได้ ต้องใช้แค่ Core Library (core)

// ============================================
// #![no_std] = ไม่ใช้ Standard Library
// เพราะ embedded ไม่มี OS!
// ============================================
#![no_std]
// ============================================
// #![no_main] = ไม่มี main มาตรฐาน
// เพราะเรากำหนด entry point เอง
// ============================================
#![no_main]
// ============================================
// Panic handler - บอกว่าจะทำอะไรเมื่อ panic
// panic_halt = หยุดทำงาน (infinite loop)
// ============================================
use panic_halt as _;
// ============================================
// #[cortex_m_rt::entry] = entry point
// ! = never returns (embedded รันตลอดไป)
// ============================================
#[cortex_m_rt::entry]
fn main() -> ! {
// Initialize hardware...
loop {
// Main loop - รันตลอดไป!
// do work...
}
}

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด