最近在翻看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
-
ESP
+關注
關注
0文章
183瀏覽量
33924 -
Zephyr
+關注
關注
0文章
21瀏覽量
5963
原文標題:Zephyr ESP32環境搭建
文章出處:【微信號:ZephyrProject,微信公眾號:ZephyrProject】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論