ESP32-C3 DevKiM 上手体验

Creative Commons
本作品采用知识共享署名

ESP32-C3 DevKiM 上手体验和一些坑

在农历年前收到乐鑫送的ESP32-C3,非常小巧漂亮。感谢乐鑫提供试用机会。


快速Bring-up

主机环境: Windows 10 WSL Ubuntu 18.04
所有按照按照Linux进行既可:

测试步骤

1.安装依赖环境

sudo apt-get install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

pip config是设置阿里源,加速之后pip的安装。

2. 下载安装esp-idf

mkdir ~/esp
cd ~/esp
git clone –recursive https://github.com/espressif/esp-idf.git
cd esp-idf
export IDF_PATH=$(pwd)
./install.sh
. ./export.sh

3. 编译blink示例

cd examples/get-started/blink
idf.py –preview set-target esp32c3
idf.py menuconfig

将Example Configuration->Blink GPIO number配置为8

4. 下载运行

idf.py flash -p /dev/ttyS13 -b 115200 monitor

说明,ESP32-C3 DevKim插入Windows后,对应串口为COM13,在WSL中使用node /dev/ttys13.
idf.py flash会事先检查是否有编译,没有编译会先自动编译,下载前工具会先检查是否有device, 然后再进行下载

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
esptool.py v3.1-dev
Serial port /dev/ttyS13
Connecting....
Chip is ESP32-C3
Features: Wi-Fi
Crystal is 40MHz
MAC: 7c:df:a1:43:10:b8
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 327.9 kbit/s)...
Hash of data verified.
Compressed 19472 bytes to 11676...
Writing at 0x00000000... (100 %)
Wrote 19472 bytes (11676 compressed) at 0x00000000 in 1.4 seconds (effective 113.7 kbit/s)...
Hash of data verified.
Compressed 154736 bytes to 78131...
Writing at 0x00010000... (20 %)
Writing at 0x00019091... (40 %)
Writing at 0x0001fd5a... (60 %)
Writing at 0x00026f38... (80 %)
Writing at 0x0002fc10... (100 %)
Wrote 154736 bytes (78131 compressed) at 0x00010000 in 7.3 seconds (effective 168.9 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

运行后idf.py会开启串口monitor串口输出,log如下,同时会看到LED等闪烁

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x14
load:0x3fcd6114,len:0x1730
load:0x403ce000,len:0x894
load:0x403d0000,len:0x2bd8
entry 0x403ce000
I (56) boot: ESP-IDF v4.3-dev-2940-g6e776946d 2nd stage bootloader
I (57) boot: compile time 20:22:11
I (57) boot: chip revision: 0
I (60) boot.esp32c3: SPI Speed : 80MHz
I (65) boot.esp32c3: SPI Mode : DIO
I (69) boot.esp32c3: SPI Flash Size : 2MB
I (74) boot: Enabling RNG early entropy source...
I (80) boot: Partition Table:
I (83) boot: ## Label Usage Type ST Offset Length
I (90) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (98) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (105) boot: 2 factory factory app 00 00 00010000 00100000
I (113) boot: End of partition table
I (117) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=053d8h ( 21464) map
I (129) esp_image: segment 1: paddr=00015400 vaddr=3fc89e00 size=019d8h ( 6616) load
I (135) esp_image: segment 2: paddr=00016de0 vaddr=40380000 size=09238h ( 37432) load
I (149) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=15230h ( 86576) map
I (164) esp_image: segment 4: paddr=00035258 vaddr=40389238 size=009f0h ( 2544) load
I (168) boot: Loaded app from partition at offset 0x10000
I (168) boot: Disabling RNG early entropy source...
I (184) cpu_start: Pro cpu up.
I (241) cpu_start: Pro cpu start user code
I (241) cpu_start: cpu freq: 160000000
I (241) cpu_start: Application information:
I (244) cpu_start: Project name: blink
I (248) cpu_start: App version: v4.3-dev-2940-g6e776946d
I (255) cpu_start: Compile time: Feb 10 2021 20:30:26
I (261) cpu_start: ELF file SHA256: 00beef0503c4aada...
I (267) cpu_start: ESP-IDF: v4.3-dev-2940-g6e776946d
I (273) heap_init: Initializing. RAM available for dynamic allocation:
I (281) heap_init: At 3FC8C620 len 000339E0 (206 KiB): DRAM
I (287) heap_init: At 3FCC0000 len 0001F260 (124 KiB): STACK/DRAM
I (294) heap_init: At 50000000 len 00002000 (8 KiB): FAKEDRAM
I (300) spi_flash: detected chip: generic
I (305) spi_flash: flash io: dio
W (309) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (322) cpu_start: Starting scheduler.
I (327) gpio: GPIO[8]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
Turning off the LED
Turning on the LED
Turning off the LED
Turning on the LED
Turning off the LED
Turning on the LED

5. 退出monitor

Ctrl+]

踩坑记录

下载运行命令

文档原本给出的是

idf.py flash monitor

idf.py会每个串口查找,最后能在/dev/ttyS13上正常检测到ESP32-C3存在,但下载的时候会提示

1
A fatal error occurred: Timed out waiting for packet header

原因是默认的UART波特率是460800,降低到115200就正常了

LED损坏

最开始跑起来后只能看到Log有输出,LED不闪烁。后来发现LED已经损坏(红框),IO8上接的限流电阻为0欧(黄框),不知道是上件错误还是电阻被烧坏了,在并上一个白光LED后可以看到闪烁(蓝框)

后记

其实手上已经有ESP8266和ESP32,ESP32-S2的板子,申请ESP32-C3主要是因为它使用的risc-v的内核,打算抽时间尝试将Zephyr移植上去试试。不过目前ESP32-C3的参考手册还没有release,没法看到详细的信息。另外从乐鑫目前开源的内容来看都只是希望用户专注在应用,所以即使参考手册有了也不定会有ESP32-C3 RISC-V的详细信息。目前从ESP-IDF能看到一些信息,但还缺中断机制等信息,希望ESP32-C3的参考手册包含有其使用的RISC-V内核详细资料。