基於Ubuntu的ESP32平台搭建


 

提要:針對於Ubuntu下的ESP32搭建,網上有很多博文,樂鑫官網也有指導手冊,對於到家都知道的部分我就一帶而過,我主要描述搭建過程中遇到的問題和細節。

 

1.創建一個ESP的目錄

   I)切換到root用戶

   II)在root目錄下創建個esp文件夾

  mkdir  ~/esp

   III)切換到ESP目錄下

     cd ~/esp

 

2.工具鏈設置

    I)先下載python支持庫

   sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial

 

II)下載工具鏈

for 64-bit Linux:

https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-75-gbaf03c2-5.2.0.tar.gz

 

for 32-bit Linux:

https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-75-gbaf03c2-5.2.0.tar.gz

 

我的用的是64bitLinux,下載以后的文件是這樣的

 

 

III)將工具鏈解壓到esp文件目錄下

 tar -xzf  ~/Downloads/xtensa-esp32-elf-linux64-1.22.0-75-gbaf03c2-5.2.0.tar.gz    ~/esp

IV)esp工具鏈寫入環境變量PATH中。

~/.bashrc文件中寫入:

export PATH="$PATH:$HOME/esp/xtensa-esp32-elf/bin"

V)重新讀取PATH環境變量

    source  ~/.bashrc

    printenv PATH  

若是可以看到esp工具鏈的目錄,則表示工具鏈設置成功了!

 

3.下載ESP-IDF(也就是樂鑫提供的SDK

I)下載SDK

git clone --recursive https://github.com/espressif/esp-idf.git

 

II)添加IDF_PATH環境變量

~/.bashrc文件添加:

export IDF_PATH=~/esp/esp-idf

     加載~/.bashrc文件:

          Source ~/.bashrc

     檢查IDF_PATH

printenv IDF_PATH

如果打印出IDF_PATH的目錄的話,則表示添加成功

 

4)開始一個工程

   I)SDK中拷貝一個Demoesp文件夾下

cp -r $IDF_PATH/examples/get-started/hello_world .

II)設置參數

執行 make menuconfig,會出現以下界面:(置於具體參數的含義,請自行了解)

 

III)編譯與運行

在確保硬件連接無誤的情況下,執行 make flash,程序將要編譯,若編譯沒有錯誤,將直接下載到Flash中,出現以下界面,表示程序已經正常運行。

 

 

note:提供一些make 指令集,可供開發使用

Welcome to Espressif IDF build system. Some useful make targets:

 

make menuconfig - Configure IDF project

make defconfig - Set defaults for all new configuration options

 

make all - Build app, bootloader, partition table

make flash - Flash app, bootloader, partition table to a chip

make clean - Remove all build output

make size - Display the static memory footprint of the app

make size-components, size-files - Finer-grained memory footprints

make erase_flash - Erase entire flash contents

make monitor - Run idf_monitor tool to monitor serial output from app

make simple_monitor - Monitor serial output on terminal console

make list-components - List all components in the project

 

make app - Build just the app

make app-flash - Flash just the app

make app-clean - Clean just the app

make print_flash_cmd - Print the arguments for esptool when flash

 

See also 'make bootloader', 'make bootloader-flash', 'make bootloader-clean',

'make partition_table', etc, etc.ls

 

* 5)更新ESP-IDF這階段本人並未實踐,以下內容來自樂鑫官網

 

After some time of using ESP-IDF, you may want to update it to take advantage of new features or bug fixes. The simplest way to do so is by deleting existing esp-idffolder and cloning it again, exactly as when doing initial installation described in sections Get ESP-IDF.

Another solution is to update only what has changed. This method is useful if you have slow connection to the GiHub. To do the update run the following commands:

 

cd ~/esp/esp-idf

git pull

git submodule update --init --recursive

The git pull command is fetching and merging changes from ESP-IDF repository on GitHub. Then git submodule update --init --recursive is updating existing submodules or getting a fresh copy of new ones. On GitHub the submodules are represented as links to other repositories and require this additional command to get them onto your PC.

If you would like to use specific release of ESP-IDF, e.g. v2.1, run:

cd ~/esp

git clone https://github.com/espressif/esp-idf.git esp-idf-v2.1

cd esp-idf-v2.1/

git checkout v2.1

git submodule update --init --recursive

After that remember to Add IDF_PATH to User Profile, so the toolchain scripts know where to find the ESP-IDF in it’s release specific location.

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM