}

ESP32与Zephyr/FreeRTOS/Arduino IDE/VS code

打印 被阅读次数
1. zephyr-rtos-on-esp32
https://www.zephyrproject.org/zephyr-rtos-on-esp32/ 
 
sudo apt update; sudo apt upgrade
 
sudo apt install --no-install-recommends git cmake
ninja-build gperf ccache dfu-util device-tree-compiler wget
python3-dev python3-pip python3-setuptools python3-tk
python3-wheel xz-utils file make gcc gcc-multilib
g++-multilib libsdl2-dev
 
cmake --version
If the version displayed is 3.13.1 or above then skip to the next section "pip3". Otherwise, follow these three steps to update CMake:
 
  wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
  sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
 
  sudo apt update
  sudo apt install cmake
 
pip3 install --user -U west
echo ‘export PATH=~/.local/bin:”$PATH”’ >> ~/.bashrc
source ~/.bashrc
 
west init ~/zephyrproject
cd ~/zephyrproject
west update
west espressif update
 
west zephyr-export
apt-get update && apt-get upgrade #needed or after next failure run this and redo
pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt
 
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.12.2/zephyr-sdk-0.12.2-x86_64-linux-setup.run
Run the installer, this will install the SDK under the ~/zephyr-sdk-0.12.2 folder.
 
chmod +x zephyr-sdk-0.12.2-x86_64-linux-setup.run
./zephyr-sdk-0.12.2-x86_64-linux-setup.run -- -d ~/zephyr-sdk-0.12.2
This is one of the default locations recommended for SDK installation, for other locations check Zephyr’s official documentation.
 
Adding ESP32 toolchain to the project
Before building, we need to tell Zephyr where to find the toolchain for ESP32’s Xtensa architecture. Open your terminal, and type the following commands:
 
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
Alternatively, you can add the above commands to your ~/.bashrc configuration file, making those variables available at any time on your current working session. Finally, install the toolchain:
 
cd ~/zephyrproject
west espressif install
Building the application
Remember I mentioned west takes part in all stages of a Zephyr’s project life-cycle? Well, we’ll see it in action here again. Build the hello_world project for the ESP32 board from the sample code folder.
 
cd ~/zephyrproject/zephyr/samples/hello_world
west build -p auto -b esp32
If the previous build fails with a message indicating missing Python packages, your OS likely uses python2.x by default. If so, make python3 its preferred choice by running the following:
 
sudo update-alternatives --install
/usr/bin/python python /usr/bin/python3 10 && alias pip=pip3
Then, run the build command again.
 
We will need a serial program utility to see the logs, use the one of your preference. Here I use minicom.
 
sudo apt install minicom
To open minicom’s serial settings, type this command:
 
sudo minicom -s #115200 8N1, no sw/hw flow
west flash; minicom  #press BOOT button on ESP32 DevKitC and you will see messages on console!
 
=====Above are outdated on Apr.1.2022, Problems are: =============
1)During "west build -p auto -b esp32" I got:
CMake Error at CMakeLists.txt:3 (cmake_minimum_required):
  CMake 3.20.0 or higher is required.  You are running version 3.16.3
2)Reinstall CMake to 3.23.0 and rerun I got:
$west build -p auto -b esp32
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: ~/zephyrproject/zephyr/samples/hello_world
-- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter 
-- Cache files will be written to: ~/.cache/zephyr
-- Zephyr version: 3.0.99 (~/zephyrproject/zephyr)
-- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
-- Board: esp32
-- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
CMake Error at ~/zephyrproject/zephyr/cmake/toolchain/espressif/generic.cmake:52 (message):
  Unable to find toolchain in
  /home/jodai/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf
实际工具链:~/.espressif/tools/zephyr/xtensa-esp32-elf/xtensa-esp32-elf
4) grep then look .json
grep -Ril "2020r3" ./
gedit ./modules/hal/espressif/tools/zephyr_tools.json 找到并下载2020r3:
mkdir -p ~/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0
cd ~/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0
wget https://github.com/espressif/crosstool-NG/releases/download/esp-2020r3/xtensa-esp32-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
tar xzvf ~/Downloads/xtensa-esp32-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz 

source ~/.bashrc 内容改为:

#export ESPRESSIF_TOOLCHAIN_PATH="~/.espressif/tools/zephyr"
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
export ESPRESSIF_TOOLCHAIN_PATH="${HOME}/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf"  

$ cmake --version
cmake version 3.23.0
$ python3 --version
Python 3.8.10
$ dtc --version
Version: DTC 1.5.0
$ west --version
West version: v0.12.0
~/zephyrproject/zephyr$ west build -p auto -b esp32 samples/basic/blinky

重build得Cmake Error:

Unable to locate toolchain as
  /home/jodai/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elffixed

需要编辑~/zephyrproject/zephyr/cmake/toolchain/zephyr/generic.cmake把第3行开始的"_ifndef"去掉:
#set_ifndef(ESPRESSIF_TOOLCHAIN_PATH "$ENV{ESPRESSIF_TOOLCHAIN_PATH}")
set(ESPRESSIF_TOOLCHAIN_PATH "/home/jodai/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf")
再编译不出红字,最终得:
175/175] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
     mcuboot_hdr:          32 B         32 B    100.00%
        metadata:          28 B         32 B     87.50%
             ROM:          0 GB    4194240 B      0.00%
     iram0_0_seg:       12464 B       128 KB      9.51%
     irom0_0_seg:       13268 B    3342304 B      0.40%
     dram0_0_seg:        1536 B     180736 B      0.85%
     dram0_1_seg:         53 KB     110032 B     49.32%
     drom0_0_seg:        3632 B    4194240 B      0.09%
    rtc_iram_seg:          0 GB         8 KB      0.00%
    rtc_slow_seg:          0 GB         4 KB      0.00%
        IDT_LIST:          0 GB         8 KB      0.00%
esptool.py v3.3-dev
Creating esp32 image...
Merged 6 ELF sections
Successfully created esp32 image.
https://github.com/espressif/crosstool-NG/releases 
 
2. VS code用于ESP32
2.1 VS code
这个多平台编辑器目前排名第一,但我个人看它在变的臃肿。
JSON是JavaScript Object Notation的缩写,即Java脚本对象表示法,是一种用于存储和传输数据的轻量级数据格式,常用于将数据从服务器发送到网页。JSON是“自我描述的”并且易于理解。示例:

{  "employees":[
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
  ]
}
JSON 句法规则:花括号容纳对象,即名称及相应值用冒号分隔的数据,数据用逗号分隔,方括号包含数组。

对于的操作:选中一个词:ctrl + d
搜索或者替换:ctrl + f :搜索,ctrl + alt + f: 替换,ctrl + shift + f:在项目内搜索

2.2 安装与编译

W10装VS code,点左侧extension图标装esp-idf,然后View|Command Palette键入Configure ESP-IDF选Advanced,下载并安装。View|Command Palette选show examples projects,中窗点击blink,右窗点击Create project using example blink,选上一级目录即get-start,这样相关文件会在blink目录下,忽略此步copy错误。按ctrl-E然后B编译,ctrl-E S看尺寸,电源插头按钮设置串口,其右侧是板子设置,闪电钮是烧入,火炬是编译加烧入。有monitor window。虽然我用的板子没有可控LED,但是printf会显示LED开关状态。https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/basic_use.md

2.3 用JTAG调试

ESP-PROG:https://www.youtube.com/watch?v=uq93H7T7cOQ#t=4m 新品ESPlink较廉:https://item.taobao.com/item.htm?id=659813902021  https://github.com/wuxx/ESPLink 

3. Micropython on ESP32

https://micropython.org/download/esp32/ https://docs.micropython.org/en/latest/esp32/tutorial/intro.html 链接下载bin,擦除并写入后,串口连接ESP32板但可显示python提示符。micropython也可装在Linux下作为软件:https://github.com/micropython/micropython 如果在windows下,建议按第一链接安装uPyCraft IDE,便可烧入。 在Arduino下的使用:https://randomnerdtutorials.com/getting-started-micropython-esp32-esp8266/ 

登录后才可评论.