# Basic MCU Interfacing

## พื้นฐาน GPIO และ C Programming สำหรับ PSoC Edge

***

### โครงสร้างการเรียนรู้

| หัวข้อ                       | รายละเอียด                      |
| ---------------------------- | ------------------------------- |
| ภาพรวม PSoC Edge E84         | PSoC Edge, Project codes        |
| Basic Embedded C Programming | Data Types, Macros              |
| Lab 1: Hello World           | ทำความเข้าใจโปรเจกต์, LED Blink |
| Lab 2: User Switch           | อ่านค่าปุ่มกด, Debounce         |
| Lab 3: Potentiometer (ADC)   | อ่านค่า Analog จาก POT          |
| Lab 4: รวมทุกอย่าง           | POT ควบคุม LED Blink Rate       |
| Quiz และสรุป                 | ทบทวนความรู้                    |

***

## ส่วนที่ 1: ภาพรวม PSoC Edge E84

### 1.1 สถาปัตยกรรม Dual-Core

<figure><img src="/files/blj265lJQ26otbzv58ra" alt=""><figcaption></figcaption></figure>

**เปรียบเทียบเพื่อความเข้าใจ:**

* **M33** = หัวหน้าทีม - จัดการงานทั่วไป, ควบคุม GPIO, สื่อสาร
* **M55** = ผู้เชี่ยวชาญ - งานหนักอย่างประมวลผลเสียง/ภาพ
* **Ethos-U55** = AI Specialist - รัน Neural Network เร็วมาก

***

### 1.2 โครงสร้างสามโปรเจกต์

```
mtb-example-psoc-edge-hello-world/
├── proj_cm33_s/      ← Secure Boot (อย่าแก้ไข!)
├── proj_cm33_ns/     ← Main Application (เขียนโค้ดที่นี่!)
└── proj_cm55/        ← ML Core (ถ้าต้องการ)
```

| โปรเจกต์           | วัตถุประสงค์                   | แก้ไข?       |
| ------------------ | ------------------------------ | ------------ |
| proj\_cm33\_s      | Secure boot, เริ่มต้น hardware | ❌ ไม่        |
| **proj\_cm33\_ns** | **โค้ดหลักของเรา**             | ✅ ใช่        |
| proj\_cm55         | ประมวลผล ML/DSP                | ⚪ ถ้าต้องการ |

#### **ลำดับการ Boot**

<figure><img src="/files/Vq9GLh41nMwdTBzgGjN7" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**ข้อควรระวัง!**

* **ห้ามลบหรือแก้ไข proj\_cm33\_s** โดยไม่จำเป็น - ถ้าพัง MCU จะไม่ boot
* **โค้ดหลักของเราอยู่ใน proj\_cm33\_ns** - นี่คือที่ที่เราจะเขียนโปรแกรม
* **proj\_cm55 เป็น optional** - ถ้าไม่ใช้ ML ก็ปล่อยว่างได้
  {% endhint %}

***

### 1.3 HAL vs PDL

| HAL (High-Level)         | PDL (Low-Level)          |
| ------------------------ | ------------------------ |
| `cyhal_gpio_toggle(pin)` | `Cy_GPIO_Inv(port, pin)` |
| ใช้ง่าย, portable        | ควบคุมละเอียด, เร็วกว่า  |
| Prefix: `cyhal_*`        | Prefix: `Cy_*`           |

**แนะนำ:** *เริ่มต้นด้วย HAL ก่อน* เมื่อต้องการ performance สูงค่อยใช้ PDL


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/interfacing-with-infineon-psoc-tm-edge/basic-mcu-interfacing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
