個人資料
歸檔
正文

ESP32與Zephyr/FreeRTOS/Arduino IDE/VS code

(2022-04-01 14:42:00) 下一個
 
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.
 
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/ 

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.