最近在翻看zephyr master的驱动代码时,很惊喜的发现esp32的wifi驱动和蓝牙驱动都已经支持。遥想当年选择自用的zephyr硬件平台时,几次打算用esp32都放弃了,最后选择了nrf52。时隔3年esp终于将esp32最重要的驱动提交到zephyr了,价格10元出头的esp32既有wifi又有蓝牙当然比35的nrf52832模块香,果断拿出吃灰的esp32小板环境来跑一跑。
2018年的时候已经在esp32上面跑过zephyr,时隔久远,编译调试的环境已经有变化,本文记录Zephyr v2.6.0下如何搭建esp32的编译调试环境。
本文的所有操作都基于WSL ubuntu-20.04发行版
基础环境
基础环境搭建搭建完后就有完整的Zephyr编译环境和代码,参考Zephyr编译环境切换到Windows,这篇文章说明了要编译Zephyr需要的所有安装步骤,只有toolchain需要使用更新的,操作方法如下
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.12.4/zephyr-sdk-0.12.4-x86_64-linux-setup.run
chmod +x zephyr-sdk-0.12.4-x86_64-linux-setup.run
。/zephyr-sdk-0.12.4-x86_64-linux-setup.run -- -d ~/zephyr-sdk-0.12.4
按照链接文章安装完成后,zephyr的所有代码就已经放在~/zephyrproject/内了
ESP32环境
ESP32的编译依赖ESP32 Toolchain,方法如下
cd ~/zephyrproject/
west espressif install
安装完成后将下面内容写入到文件~/.zephyrrc
export ZEPHYR_TOOLCHAIN_VARIANT=“espressif”
export ESPRESSIF_TOOLCHAIN_PATH=“${HOME}/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf”
export PATH=$PATH:$ESPRESSIF_TOOLCHAIN_PATH/bin
重新开启终端或者执行source ~/.zephyrrc让环境变量生效
编译和下载
我用的硬件是ESP32-DevKitC,这里只是用hello_world示例测试编译出的镜像是否能正常执行,因此无需另外建立zephyr board,用zephyr自带的esp32 board编译即可
west build -b esp32 zephyrproject/zephyr/samples/hello_world/
编译完后将ESP32-DevKitC用USB线连接到电脑,由于west flash默认使用/dev/ttyUSB0, 而我用的是WSL,直接下载会失败。处理方法:查看ESP32-DevKitC在Windows上USB转串口的端口为COM11,对应到WSL下为/dev/ttyS11, 使用下面方法指定下载用的串口
west flash --esp-device /dev/ttyS11
执行后能看下载信息
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner esp32
-- runners.esp32: Flashing ESP32 on /dev/ttyS11 (921600bps)
esptool.py v3.0
Serial port /dev/ttyS11
Connecting.。..。
Chip is ESP32-D0WD-V3 (revision 3)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: c457f8:dc
Uploading stub.。.
Running stub.。.
Stub running.。.
Changing baud rate to 921600
Changed.
Configuring flash size.。.
Auto-detected Flash size: 4MB
Flash params set to 0x0220
Wrote 32768 bytes at 0x00001000 in 0.4 seconds (596.3 kbit/s)。..
Hash of data verified.
Wrote 16384 bytes at 0x00008000 in 0.2 seconds (697.3 kbit/s)。..
Hash of data verified.
Wrote 81920 bytes at 0x00010000 in 1.1 seconds (597.8 kbit/s)。..
Hash of data verified.
Leaving.。.
Hard resetting via RTS pin.。.
下载完成后另外打开串口可以看到启动log, 可以看到zephyr其实是作为app被ESP32的loader引导起来的
ets Jul 29 2019 1246
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4
load:0x3fff0034,len:7264
ho 0 tail 12 room 4
load:0x40078000,len:13212
load:0x40080400,len:4568
entry 0x400806f4
I (31) boot: ESP-IDF 086d30520 2nd stage bootloader
I (31) boot: compile time 2245
I (31) boot: chip revision: 3
I (34) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (42) boot.esp32: SPI Speed : 40MHz
I (46) boot.esp32: SPI Mode : DIO
I (50) boot.esp32: SPI Flash Size : 4MB
I (55) boot: Enabling RNG early entropy source.。.
I (60) boot: Partition Table:
I (64) boot: ## Label Usage Type ST Offset Length
I (71) boot: 0 nvs WiFi data 01 02 00002000 00006000
I (79) boot: 1 phy_init RF data 01 01 00008000 00001000
I (86) boot: 2 factory factory app 00 00 00010000 00100000
I (94) boot: End of partition table
I (98) boot_comm: chip revision: 3, min. application chip revision: 0
I (105) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x0037c ( 892) map
I (114) esp_image: segment 1: paddr=0x000103a4 vaddr=0x3ffb0000 size=0x000a8 ( 168) load
I (123) esp_image: segment 2: paddr=0x00010454 vaddr=0x3ffb00a8 size=0x00170 ( 368) load
I (132) esp_image: segment 3: paddr=0x000105cc vaddr=0x3ffb0218 size=0x00048 ( 72) load
I (141) esp_image: segment 4: paddr=0x0001061c vaddr=0x3ffb0260 size=0x00100 ( 256) load
I (150) esp_image: segment 5: paddr=0x00010724 vaddr=0x3ffb0360 size=0x0003c ( 60) load
I (159) esp_image: segment 6: paddr=0x00010768 vaddr=0x40080000 size=0x00400 ( 1024) load
I (168) esp_image: segment 7: paddr=0x00010b70 vaddr=0x40080400 size=0x02500 ( 9472) load
I (181) esp_image: segment 8: paddr=0x00013078 vaddr=0x00000000 size=0x0cfa0 ( 53152)
I (205) esp_image: segment 9: paddr=0x00020020 vaddr=0x400d0020 size=0x0166c ( 5740) map
I (209) boot: Loaded app from partition at offset 0x10000
▒▒*** Booting Zephyr OS build v2.6.0-rc1-300-g6ce0f2ee6606 ***
Hello World! esp32
原文标题:Zephyr ESP32环境搭建
文章出处:【微信公众号:ZephyrProject】欢迎添加关注!文章转载请注明出处。
责任编辑:haq
全部0条评论
快来发表一下你的评论吧 !