ESP32开发 -- 试玩ESP32
前文要測試網絡調試助手,手頭正好有個ESP32一直沒有試過。這次正好拿來試玩一下。
一、ESP32官網查看
官網:ESP32官網
這款最小系統開發板搭載了樂鑫最新的系統級芯片 ESP32, 支持 Wi-Fi 和藍牙功能,具有豐富的外設,能夠讓開發者盡情發揮想象力進行二次開發!
二、Ubuntu系統下ESP32開發環境的搭建
參看:Ubuntu系統下ESP32開發環境的搭建
1、安裝交叉編譯工具鏈依賴的環境:
sudo apt-get install git make gcc libncurses5-dev flex bison gperf python-serial
2、創建ESP32專用的工作目錄:
sudo mkdir /esp32
3、設置文件夾的歸屬為當前用戶:
sudo chown user:user /esp32
4、創建三個文件夾:
crossTools、demos、sources分別保存交叉編譯工具鏈、樣例和SDK源碼:
cd /esp32
mkdir crossTools demos sources
5、進入crossTools文件夾,下載官方的交叉編譯工具:
注意,需要查看你的linux是32位還是64位的。
在linux終端輸入 getconf LONG_BIT 命令
如果是32位機器,則結果為32
[root@localhost ~]# getconf LONG_BIT
32
如果是64位機器,則結果為64
[root@localhost ~]# getconf LONG_BIT
64
Linux(x32):wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-59.tar.gz
Linux(x64):wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-59.tar.gz
6、 解壓文件到當前目錄下:
tar -xzvf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
三、修改環境變量
1、將解壓后的交叉編譯工具連添加到系統的PATH環境變量中
sudo vim /etc/profile
2、在最后面添加交叉編譯工具鏈bin文件夾的目錄
export PATH=$PATH:/esp32/crossTools/xtensa-esp32-elf/bin
3、然后更新一下profile文件,使之生效
source /etc/profile
4、檢查是否安裝成功
xtensa-esp32-elf-gcc -v
如果看到有版本信息顯示,說明已經安裝成功
5、可以看到使用的gcc版本為4.8.5
針對的目標機器格式為xtensa-esp32-elf,支持編譯的源文件有C和C++,支持的線程模式是單線程single,整套的交叉編譯工具鏈是使用crosstool-NG工具制作,如果不怕折騰,用戶也可以自己制作一個新的
$ xtensa-esp32-elf-gcc -v Using built-in specs. COLLECT_GCC=xtensa-esp32-elf-gcc COLLECT_LTO_WRAPPER=/esp32/crossTools/xtensa-esp32-elf/bin/../libexec/gcc/xtensa-esp32-elf/4.8.5/lto-wrapper Target: xtensa-esp32-elf Configured with: /home/vagrant/crosstool-NG/.build/src/gcc-4.8.5/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=xtensa-esp32-elf --prefix=/home/vagrant/crosstool-NG/builds/xtensa-esp32-elf --with-local-prefix=/home/vagrant/crosstool-NG/builds/xtensa-esp32-elf/xtensa-esp32-elf/sysroot --with-sysroot=/home/vagrant/crosstool-NG/builds/xtensa-esp32-elf/xtensa-esp32-elf/sysroot --with-newlib --enable-threads=no --disable-shared --with-pkgversion='crosstool-NG crosstool-ng-1.22.0-59-g8d95cad' --disable-__cxa_atexit --enable-cxx-flags='-fno-exceptions -fno-rtti' --with-gmp=/home/vagrant/crosstool-NG/.build/xtensa-esp32-elf/buildtools --with-mpfr=/home/vagrant/crosstool-NG/.build/xtensa-esp32-elf/buildtools --with-mpc=/home/vagrant/crosstool-NG/.build/xtensa-esp32-elf/buildtools --with-isl=/home/vagrant/crosstool-NG/.build/xtensa-esp32-elf/buildtools --with-cloog=/home/vagrant/crosstool-NG/.build/xtensa-esp32-elf/buildtools --with-libelf=/home/vagrant/crosstool-NG/.build/xtensa-esp32-elf/buildtools --enable-lto --enable-target-optspace --without-long-double-128 --disable-libgomp --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-nls --disable-multilib --enable-languages=c,c++ Thread model: single gcc version 4.8.5 (crosstool-NG crosstool-ng-1.22.0-59-g8d95cad)四、從Github上獲取ESP-IDF
可以直接通過gitclone的方式獲取ESP-IDF:
git clone –recursive https://github.com/espressif/esp-idf.git
ESP-IDF的目錄結構如下:
components:ESP-IDF的核心組件
examples:ESP-IDF提供的實例程序
make:ESP-IDF工程管理目錄
tools:ESP-IDF提供的工具集
docs:ESP-IDF相關文檔
將esp-idf拷貝到 /esp32/sources
1、將ESP-IDF目錄下examples中的hello_world樣例拷貝到我們之前新建的demo文件夾中
cp /esp32/sources/esp-idf/examples/get-started/hello_world/ /esp32/demos/ -rf
打開Makefile,發現里面需要一個IDF_PATH的變量
在/etc/profile中添加這樣一個環境變量:
export IDF_PATH=/esp32/sources/esp-idf
source /etc/profile
2、配置項目工程,在工程的根目錄下使用make menuconfig
Component config是對ESP-IDF的內核進行的更加詳細的配置
退出make menuconfig的配置界面,保存剛才的配置,將會在工程根目錄下新生成一個build文件夾和sdkconfig文件
3、安裝gcc-5.2.0
因為gcc版本應該為gcc-5.2.0,而我的為gcc-4.8.5。所以編譯出現警告。
WARNING: Compiler version is not supported: 4.8.5
Expected to see version(s): 5.2.0
參看:編譯安裝GCC 5.2.0
相關軟件下載:
gmp 6.0、mpfr 3.1.3、mpc 1.0.3、gcc-5.2.0
安裝gmp 6.0
tar xvf gmp-6.0.0a.tar.bz2
cd gmp-6.0.0
./configure
make -j4
make check
make install
安裝mpfr 3.1.3
mpfr依賴于gmp。
tar xvf mpfr-3.1.3.tar.bz2
cd mpfr-3.1.3
./configure –with-gmp-include=/usr/local/include \
–with-gmp-lib=/usr/local/lib
make -j4
make install
安裝mpc 1.0.3
mpc依賴于gmp和mpfr。
tar xvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure –with-mpfr-include=/usr/local/include \
–with-mpfr-lib=/usr/local/lib \
–with-gmp-include=/usr/local/include \
–with-gmp-lib=/usr/local/lib
make -j4
make check
make install
安裝GCC
tar xvf gcc-5.2.0.tar.bz2
cd gcc-5.2.0
先unset若干個系統變量,以免出現某些宏找不到的情況。
unset CPLUS_INCLUDE_PATH LIBRARY_PATH
配置環境變量:
vi /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
source /etc/profile
配置GCC
./configure \
–with-gmp-include=/usr/local/include \
–with-gmp-lib=/usr/local/lib \
–with-mpfr-include=/usr/local/include \
–with-mpfr-lib=/usr/local/lib \
–with-mpc-include=/usr/local/include \
–with-mpc-lib=/usr/local/lib \
–enable-languages=c,c++ \
–enable-threads=posix \
–disable-multilib
詳細的配置項說明可參考安裝文檔,這里只編譯c和c++的編譯器。
然后make -j8,啟用多線程編譯。(時間有點長)
安裝
如果編譯順利通過,make install即可。
gcc和g++默認被安裝到/usr/local/bin目錄下,libgcc和libstdc++默認被安裝到/usr/local/lib64(x64)。
記得更下下動態庫緩存。
ldconfig
總結
以上是生活随笔為你收集整理的ESP32开发 -- 试玩ESP32的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Elasticsearch 基础入门(二
- 下一篇: STM32开发 -- CRC校验码