# 建立esp32 debugger開發環境
## 購買ESP-PROG硬體
[購買鏈結](https://www.mouser.tw/ProductDetail/Espressif-Systems/ESP-PROG?qs=0lSvoLzn4L9lCAjJ8r9cdg%3D%3D)
## ESP-PROG和ESP32-WROOM模組接線
| ESP32 WROOM | Column 2 |
| -------- | -------- |
| GPIO12 | TDI |
| GPIO13 | TCK |
| GPIO14 | TMS |
| GPIO15 | TDO |
| GND | GND |
## 安裝RS232 driver
1. 使用zadig安裝。操作步驟如下:
1.1. 按下選單"Options->List All Devices"
2.1. 選擇DualRS232-HS(Interface 0)

1.3 然後就會看到ESP32、FT2232H和FT2232 JTAG的驅動

## 在範例專案blink裡面使用Openocd
為了使用Openocd修正launch.json
```jsonld=launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "ESP32 OpenOCD",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder}/build",
"program": "${workspaceFolder}/build/blink.elf",
"miDebuggerPath": "${command:espIdf.getXtensaGdb}",
"setupCommands": [
{ "text": "target remote :3333" },
{ "text": "set remote hardware-watchpoint-limit 2"},
{ "text": "mon reset halt" },
{ "text": "thb app_main" },
{ "text": "flushregs" }
],
"externalConsole": false,
"logging": {
"engineLogging": true
}
}
]
}
```
先在esp idf terminal用以下指令開啟Openocd server
```bash=
openocd -f board/esp32-wrover-kit-3.3v.cfg
```
之後再visual studio codee按下Run and Debug

如果失敗可以多試幾次,成功後的畫面最終畫面如下:

## 使用ESP-PROG燒錄 ESP32
之後待做
[參考資料1,影片](https://www.youtube.com/watch?v=uq93H7T7cOQ)
[參考資料2](https://github.com/espressif/esp-dev-kits/blob/master/docs/en/other/esp-prog/user_guide.rst)
[參考資料3](https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/DEBUGGING.md