> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aic-eec.com/interfacing-with-infineon-psoc-tm-edge/infineon-psoc-tm-edge-troubleshooting.md).

# Infineon PSoC™ Edge Troubleshooting

## การ Flash ชิป PSoC™ 4000T CAPSENSE™

โฟลเดอร์นี้มีไฟล์ `psoc4-csd-button-slider.cyacd2` — เฟิร์มแวร์ CAPSENSE™ (ปุ่ม/สไลเดอร์) สำหรับชิป **PSoC™ 4000T** บน SOM ของ PSoC™ Edge E84 โปรแกรมผ่าน **I2C** ด้วย DFU Host Tool (ไม่ใช่ผ่าน SWD)

> **ไฟล์ `.cyacd2` แถมมาในโฟลเดอร์นี้แล้ว** — ไม่ต้องไปดาวน์โหลด ไฟล์นี้ไม่ใช่ไฟล์เดี่ยว ๆ ให้โหลด แต่**แถมมากับ Infineon code example** ชื่อ *"PSoC Edge: Bluetooth® LE with CAPSENSE™ Button and Slider"* (และ example *wifi-web-server*) ดึงผ่าน ModusToolbox Project Creator หรือ GitHub code-example ของ Infineon — สำเนาในโฟลเดอร์นี้คือ build ที่ยืนยันแล้วว่าใช้กับบอร์ดได้

***

### ทำไม DFU ถึง "fail แบบสุ่ม"

PSoC™ 4000T กับ PSoC™ Edge E84 **ใช้สาย I2C เส้นเดียวกัน (`P8_0` / `P8_1`)** KitProg3 ทำหน้าที่ bridge USB→I2C ไปยัง bootloader ของ 4000T บนบัสเส้นนี้

ถ้า **แอปของ E84 กำลังรันอยู่** (คือเพิ่ง `make program` ไป) มันจะ**ขับบัส I2C เส้นเดียวกันตลอดเวลา**เพื่ออ่านเซนเซอร์บนบอร์ด สัญญาณนี้จะ**ชนกับการโอนข้อมูล DFU** → คำสั่งสั้น ๆ ผ่านได้ แต่ data row พัง แล้วขึ้น error ประมาณนี้:

```
Operation FAILED.
Operation returned unknown value 16639
Error: write operation failed.
[CRITICAL] Error code: -2
Internal error occured. Please enable logging using --debug to get details.
```

อาการนี้ **ไม่ใช่**บอร์ดเสีย สายเสีย หรือไฟล์ผิด แต่เป็น **bus contention** จากแอป E84 ที่รันอยู่ — แก้โดยทำให้ E84 เงียบก่อน

### ลำดับที่ถูกต้อง — ห้ามข้าม / ห้ามสลับ

<table><thead><tr><th width="152.04296875">ขั้น</th><th>ทำอะไร</th><th>จุดประสงค์</th></tr></thead><tbody><tr><td>1</td><td>Erase แอป E84</td><td><strong>ปลดบัส I2C ให้ว่าง</strong></td></tr><tr><td>2</td><td>DFU flash 4000T ที่ <code>0x08</code>, 400 kHz</td><td>วิ่งจนจบเพราะบัสว่าง</td></tr><tr><td>3</td><td>Flash แอป E84 กลับ</td><td>คืนแอป <strong>เป็นขั้นสุดท้าย</strong></td></tr></tbody></table>

ถ้า program E84 **ก่อน** flash 4000T → DFU จะ fail ทุกครั้ง

***

### วิธีที่ 1 — คำสั่งเดียวจบ (script)

**ทุก OS (แนะนำ)** — ต้องมี Python 3:

```bash
python3 flash_capsense.py --program-after
```

**macOS / Linux** — bash:

```bash
./flash_capsense.sh --program-after
```

script จะ auto-detect KitProg3, เลือก DFU tool ที่รองรับ I2C, บังคับ HID mode, แล้วทำ: erase E84 → flash 4000T (มี retry) → program E84

<table><thead><tr><th width="262.17578125">Flag</th><th>ผล</th></tr></thead><tbody><tr><td><em>(ไม่ใส่)</em></td><td>erase E84, flash 4000T, ถามยืนยันก่อน erase</td></tr><tr><td><code>--yes</code></td><td>ข้ามการถามยืนยัน erase</td></tr><tr><td><code>--program-after</code></td><td>รัน program คืนแอป E84 ตอนจบให้ด้วย</td></tr><tr><td><code>--no-erase</code></td><td>flash อย่างเดียว (E84 ว่างอยู่แล้ว)</td></tr><tr><td><code>--dry-run</code></td><td>(python) แค่ตรวจหาเครื่องมือ + แสดงแผน ไม่ flash จริง</td></tr><tr><td><code>--file &#x3C;f.cyacd2></code></td><td>flash ไฟล์ image อื่น</td></tr></tbody></table>

***

### วิธีที่ 2 — ทำมือทั้งหมด (ไม่ต้องใช้ script)

ใช้วิธีนี้ถ้าอยากรันเองทีละขั้น สิ่งที่ต่างกันแต่ละ OS มีแค่ **ตำแหน่งของเครื่องมือ**

#### ตำแหน่งเครื่องมือ

<table><thead><tr><th width="147.515625">เครื่องมือ</th><th>Windows</th><th>macOS</th><th width="192.9375">Linux</th></tr></thead><tbody><tr><td><strong>DFU Host Tool</strong> (GUI/CLI)</td><td><code>C:\Users\&#x3C;you>\ModusToolbox\tools_3.x\dfuh-tool\</code></td><td><code>/Applications/ModusToolbox/tools_3.x/dfuh-tool/</code></td><td><code>~/ModusToolbox/tools_3.x/dfuh-tool/</code></td></tr><tr><td><strong>fw-loader</strong></td><td><code>...\ModusToolboxProgtools-1.x\fw-loader\bin\fw-loader.exe</code></td><td><code>/Applications/ModusToolboxProgtools-1.x/fw-loader/bin/fw-loader</code></td><td><code>~/...Progtools-1.x/fw-loader/bin/fw-loader</code></td></tr></tbody></table>

> แทน `3.x` / `1.x` ด้วยเวอร์ชันที่ติดตั้งจริง บน Windows ตัว CLI ชื่อ `dfuh-cli.exe` บน macOS/Linux ชื่อ `dfuh-cli` — **ใช้รุ่น 2.80** เพราะ **2.120+ ตัด I2C ออก**

#### ขั้น 1 — Erase แอป E84 (ปลดบัส I2C)

เปิด **ModusToolbox terminal** (Quick Panel → *Terminal* หรือ *modus-shell* บน Windows) ที่ project root `AIC-EEC_psoc-e84-e2-lvgl-bill` แล้วรัน:

```bash
make erase
```

(หรือใช้ launch config **Erase** ใน Quick Panel ของ IDE)

#### ขั้น 2 — ตั้ง KitProg3 เป็น HID mode (จำเป็นสำหรับ bridge I2C)

ก่อนอื่นหา serial (ส่วนที่ตามหลัง `KitProg3-`):

```bash
# จากโฟลเดอร์ dfuh-tool
dfuh-cli --display-hw        # มองหาบรรทัด:  I2C: KitProg3-<SERIAL>
```

แล้วจากโฟลเดอร์ fw-loader:

```bash
fw-loader --mode kp3-hid <SERIAL>
```

(โหมด `bulk` bridge I2C ไม่เสถียร)

#### ขั้น 3 — Flash 4000T

**ง่ายสุด ข้าม OS ได้ — ใช้ GUI:**

1. เปิด **Device Firmware Update Host Tool** (จาก Quick Panel หรือรัน `dfuh-tool` จากโฟลเดอร์ข้างบน)
2. **File:** เลือก `firmware/psoc4-csd-button-slider.cyacd2`
3. **Port:** `KitProg3-... - I2C` · **I2C address:** `8` · **Speed:** `400 kHz`
4. กด **Program** (ปิด serial terminal บน KitProg3 ให้หมดก่อน)

**หรือใช้ command line** (จากโฟลเดอร์ `dfuh-tool`):

```bash
dfuh-cli --i2c-address 8 --i2c-speed 400 \
         --hwid "KitProg3-<SERIAL>" \
         --program-device <path>/firmware/psoc4-csd-button-slider.cyacd2
```

ต้องได้ข้อความ: `Operation succeeded.`

#### ขั้น 4 — Flash แอป E84 กลับ (ขั้นสุดท้าย)

```bash
make program
```

***

### ข้อควรระวัง / อ้างอิง

* **ใช้ DFU Host Tool 2.80** (`tools_3.6`) เวอร์ชัน **2.120** (`tools_3.8`) **ตัด I2C-bridge ออกแล้ว** — `dfuh-cli --display-hw` จะไม่มีบรรทัด `I2C:` จึง flash ชิปนี้ไม่ได้ (script เลือกเวอร์ชันที่ใช้ได้ให้อัตโนมัติ)
* **KitProg3 ต้องอยู่ HID mode** (`fw-loader --mode kp3-hid`)
* **I2C address:** `0x08` = bootloader, `0x09` = application
* ถ้า 4000T **รัน application ไปแล้ว** (เคย flash สำเร็จ ยังไม่ reset) bootloader ที่ `0x08` อาจไม่ตอบ ให้ดึงกลับ bootloader ด้วย **Bridge Control Panel** (มากับ PSoC™ Programmer) ส่งคำสั่ง:

  ```
  w 09 01 EA 17 p
  ```
* ปิด serial terminal / โปรแกรมอื่นที่จับ KitProg3 ให้หมดก่อน flash


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
