上周muselab的吴同学寄来一片nanoesp32-c3–一块带有esplink(base daplink)的esp32-c3开发板。
正好最近支持esp32-c3的pr已经merge进入zephyr main,就拿来试跑一下。
想要在esp32-c3上尝鲜的同学请注意,目前esp32-c3刚刚把soc移植进去,对驱动支援有限,要实际使用可能还有比较长的一段路要走。
zephyr esp32c3编译和下载
编译环境的搭建和esp32差别不大,参考文章zephyr esp32环境搭建即可,主要差别是toolchain的位置,修改环境变量即可
1
export espressif_toolchain_path=“${home}/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf”
使用esp32c3_devkitm编译出来的sample可以直接在nanoesp32-c3上跑起来:
1
west build -b esp32c3_devkitm samples/hello_world
烧写方式和esp32一致
1
west flash --esp-device /dev/ttys5
跑起来的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
esp-rom:esp32c3-api1-20210207
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引导起来的,今年开发者大会乐鑫的ppt上提到今年4季会引入mcuboot,也许到时候stage1不再是黑盒子
调试
编译openocd
nanoesp32-c3上面带有daplink可以搭配openocd对esp32-c3进行jtag调试。由于我主力使用windows,需要windwos版本的,但官方提供编译好的windows openocd不支持daplink,因此需要自己编译。按官方的步骤编译有一些依赖问题,这里记录一下我的编译步骤:
1. 安装msys2
注意一定要安装msys2带有32位支持,执行的时候用mingw32.exe
2. 安装依赖软件
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是手动指定的,但在configure的时候会提示找不到。libhidapi是cmsis-dap的依赖
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/是因为在configure检查的时候遇到找不到libz的情况。
以上步骤做完后 openocd就编译并安装到out下了
启用esp32-c3 jtag
esp32-c3默认没有开启jtag支持,需要使用esp-idf下的工具重写fuse, 脚本在components/esptool_py/esptool/下,执行
1
。/espefuse.py -p /dev/ttys5 burn_efuse jtag_sel_enable
按照提示输入burn,看到下面的信息说明已经烧成功
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
否则会提示error: cmsis-dap command cmd_dap_swj_clock failed.而退出openocd
执行
1
2
cd out/mingw32/bin/
。/openocd.exe -f 。。/share/openocd/scripts/interface/cmsis-dap.cfg -f 。。/share/openocd/scripts/target/esp32c3.cfg
将会看到
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中执行
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
开启gdb后执行
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执行
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进行debug即可,当然也可以通过vscode调用gdb进行图像化的调试操作
参考
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
鲲云科技采用芯华章穹瀚GalaxFV 加速AI芯片设计
微软 GitHub 网页出黑暗模式、自动合并拉取请求、讨论等新功能
骨传导耳机什么牌子的好用、骨传导耳机排名推荐
Protect LED driver in backlit displays
HOLTEK新推出HT45FH3T Tinypower 3D眼镜MCU
基于nanoESP32-C3开发板用ESP32-c3下试跑Zephyr
微雪电子CP2102(type A)USB转USART简介
win8怎么恢复出厂设置_win8开机黑屏
汽车充电桩主板的构成及7kw交流桩的优势阐述
FLY-BY拓扑结构:阻抗不连续到了什么程度呢
2019年面板业恐面临更严苛的挑战
为什么我用高带宽探头测试出来的信号幅度“不准”?
华为5G的想法颠覆以往认知,物联网谁来驱动?
刀具RFID电子标签应用解析
全新的5G+AI时代下 营销行业主要产生了以下几点变化
Gartner解读云计算与数据中心基础设施市场发展
“十四五”期间我国汽车出口有望继续稳中向好
五大主流元器件的分析预测
物联网漏洞报告仍然很少
为什么DD马达的价格高