上周MuseLab的吳同學(xué)寄來(lái)一片nanoESP32-C3–一塊帶有ESPLink(base DAPlink)的ESP32-C3開(kāi)發(fā)板。
正好最近支持esp32-c3的pr已經(jīng)merge進(jìn)入zephyr main,就拿來(lái)試跑一下。
想要在esp32-c3上嘗鮮的同學(xué)請(qǐng)注意,目前esp32-c3剛剛把soc移植進(jìn)去,對(duì)驅(qū)動(dòng)支援有限,要實(shí)際使用可能還有比較長(zhǎng)的一段路要走。
Zephyr esp32c3編譯和下載
編譯環(huán)境的搭建和esp32差別不大,參考文章Zephyr ESP32環(huán)境搭建即可,主要差別是toolchain的位置,修改環(huán)境變量即可
1
export ESPRESSIF_TOOLCHAIN_PATH=“${HOME}/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf”
使用esp32c3_devkitm編譯出來(lái)的sample可以直接在nanoESP32-C3上跑起來(lái):
1
west build -b esp32c3_devkitm samples/hello_world
燒寫(xiě)方式和esp32一致
1
west flash --esp-device /dev/ttyS5
跑起來(lái)的log如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Build:Feb 7 2021
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fcd6100,len:0x17f4
load:0x403ce000,len:0x8c8
load:0x403d0000,len:0x2c04
SHA-256 comparison failed:
Calculated: 0f38ba975edd6cdf3fa47a8186ed194cb3bf731b54225a98c8467c9b601ce1a8
Expected: 6b0078e7157b7406a271378332f5b65ceec18db5ee861bd4c76427a90993a786
Attempting to boot anyway.。。
entry 0x403ce000
I (49) boot: ESP-IDF c21d252a2 2nd stage bootloader
I (49) boot: compile time 1411
I (49) boot: chip revision: 3
I (51) boot_comm: chip revision: 3, min. bootloader chip revision: 2
I (59) boot.esp32c3: SPI Speed : 40MHz
I (63) boot.esp32c3: SPI Mode : DIO
I (68) boot.esp32c3: SPI Flash Size : 4MB
I (73) boot: Enabling RNG early entropy source.。。
I (78) boot: Partition Table:
I (82) boot: ## Label Usage Type ST Offset Length
I (89) boot: 0 nvs WiFi data 01 02 00002000 00006000
I (96) boot: 1 phy_init RF data 01 01 00008000 00001000
I (104) boot: 2 factory factory app 00 00 00010000 00100000
I (111) boot: End of partition table
I (116) boot_comm: chip revision: 3, min. application chip revision: 0
I (123) esp_image: segment 0: paddr=00010020 vaddr=3c010020 size=00254h ( 596) map
I (132) esp_image: segment 1: paddr=0001027c vaddr=3fc82488 size=00068h ( 104) load
I (140) esp_image: segment 2: paddr=000102ec vaddr=40380000 size=02488h ( 9352) load
I (151) esp_image: segment 3: paddr=0001277c vaddr=00000000 size=0d89ch ( 55452)
I (168) esp_image: segment 4: paddr=00020020 vaddr=42000020 size=003ech ( 1004) map
I (170) boot: Loaded app from partition at offset 0x10000
I (172) boot: Disabling RNG early entropy source.。。
*** Booting Zephyr OS build zephyr-v2.6.0-1514-g718c77a4cdc4 ***
Hello World! esp32c3
和esp32一樣zephyr是作為app被ESP32C3的loader引導(dǎo)起來(lái)的,今年開(kāi)發(fā)者大會(huì)樂(lè)鑫的ppt上提到今年4季會(huì)引入MCUBoot,也許到時(shí)候stage1不再是黑盒子
調(diào)試
編譯openocd
nanoESP32-C3上面帶有daplink可以搭配openocd對(duì)esp32-c3進(jìn)行jtag調(diào)試。由于我主力使用windows,需要windwos版本的,但官方提供編譯好的windows openocd不支持daplink,因此需要自己編譯。按官方的步驟編譯有一些依賴(lài)問(wèn)題,這里記錄一下我的編譯步驟:
1. 安裝MSYS2
注意一定要安裝MSYS2帶有32位支持,執(zhí)行的時(shí)候用mingw32.exe
2. 安裝依賴(lài)軟件
1
pacman -S --noconfirm --needed autoconf automake git make mingw-w64-i686-gcc mingw-w64-i686-toolchain mingw-w64-i686-libtool mingw-w64-i686-pkg-config mingw-w64-cross-winpthreads-git p7zip
安裝libusb和libhidapi, 官方文檔的libusb是手動(dòng)指定的,但在configure的時(shí)候會(huì)提示找不到。libhidapi是cmsis-dap的依賴(lài)
1
2
pacman -S mingw-w64-i686-libusb
pacman -S mingw-w64-i686-hidapi
3. 編譯
1
2
3
4
5
6
7
8
9
10
11
12
export LDFLAGS=“$LDFLAGS -L/mingw32/bin/”
export CPPFLAGS=“$CPPFLAGS -D__USE_MINGW_ANSI_STDIO=1 -Wno-error”; export CFLAGS=“$CFLAGS -Wno-error”
git clone --recursive https://github.com/espressif/openocd-esp32.git
cd openocd-esp32/
。/bootstrap
。/configure --disable-doxygen-pdf --enable-ftdi --enable-jlink --enable-ulink --enable-cmsis-dap --build=i686-w64-mingw32 --host=i686-w64-mingw32
make
mkdir out
export DESTDIR=“$PWD/out”
make install
cp /mingw32/bin/libusb-1.0.dll $DESTDIR/mingw32/bin
cp /mingw32/bin/libhidapi-0.dll $DESTDIR/mingw32/bin
指定-L/mingw32/bin/是因?yàn)樵赾onfigure檢查的時(shí)候遇到找不到libz的情況。
以上步驟做完后 openocd就編譯并安裝到out下了
啟用esp32-c3 jtag
esp32-c3默認(rèn)沒(méi)有開(kāi)啟jtag支持,需要使用esp-idf下的工具重寫(xiě)fuse, 腳本在components/esptool_py/esptool/下,執(zhí)行
1
。/espefuse.py -p /dev/ttyS5 burn_efuse JTAG_SEL_ENABLE
按照提示輸入BURN,看到下面的信息說(shuō)明已經(jīng)燒成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Connecting.。。。
Detecting chip type.。。 ESP32-C3
espefuse.py v3.1-dev
The efuses to burn:
from BLOCK0
- JTAG_SEL_ENABLE
Burning efuses:
- ‘JTAG_SEL_ENABLE’ (Set this bit to enable selection between usb_to_jtag and pad_to_jtag through strapping gpio10 when both reg_dis_usb_jtag and reg_dis_pad_jtag are equal to 0.) 0b0 -》 0b1
Check all blocks for burn.。。
idx, BLOCK_NAME, Conclusion
[00] BLOCK0 is empty, will burn the new value
。
This is an irreversible operation!
Type ‘BURN’ (all capitals) to continue.
BURN
BURN BLOCK0 - OK (write block == read block)
Reading updated efuses.。。
Checking efuses.。。
Successful
`
使用
在share/openocd/scripts/interface/cmsis-dap.cfg中添加
1
adapter_khz 5000
否則會(huì)提示Error: CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed.而退出openocd
執(zhí)行
1
2
cd out/mingw32/bin/
。/openocd.exe -f 。。/share/openocd/scripts/interface/cmsis-dap.cfg -f 。。/share/openocd/scripts/target/esp32c3.cfg
將會(huì)看到
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Open On-Chip Debugger v0.10.0-esp32-20210721 (2021-07-28-17:08)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 5000 kHz
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 0255
Info : CMSIS-DAP: Serial# = 0800000100540055430000094e504332a5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (JTAG)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : cmsis-dap JTAG TLR_RESET
Info : cmsis-dap JTAG TLR_RESET
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : datacount=2 progbufsize=16
Info : Examined RISC-V core; found 1 harts
Info : hart 0: XLEN=32, misa=0x40101104
Info : Listening on port 3333 for gdb connections
在WSL中執(zhí)行
1
~/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gdb build/zephyr/zephyr.elf
開(kāi)啟gdb后執(zhí)行
1
2
3
4
5
6
target remote 127.0.0.1:3333
set remote hardware-watchpoint-limit 2
mon reset halt
flushregs
thb main
c
就可以跳到main執(zhí)行
1
2
Temporary breakpoint 1, main () at /mnt/d/code/zephyrproject/zephyr/samples/hello_world/src/main.c:12
12 printk(“Hello World! %s
”, CONFIG_BOARD);
之后用gdb進(jìn)行debug即可,當(dāng)然也可以通過(guò)vscode調(diào)用gdb進(jìn)行圖像化的調(diào)試操作
參考
https://github.com/wuxx/nanoESP32-C3https://docs.zephyrproject.org/latest/boards/riscv/esp32c3_devkitm/doc/index.html
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/jtag-debugging/building-openocd-windows.html
編輯:jq
-
soc
+關(guān)注
關(guān)注
38文章
4161瀏覽量
218157 -
開(kāi)發(fā)板
+關(guān)注
關(guān)注
25文章
5032瀏覽量
97371 -
ESP32
+關(guān)注
關(guān)注
18文章
971瀏覽量
17201
原文標(biāo)題:ESP32-c3下試跑Zephyr--基于nanoESP32-C3開(kāi)發(fā)板
文章出處:【微信號(hào):智芯原動(dòng)ICETech,微信公眾號(hào):智芯原動(dòng)ICETech】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論