esp32 idf開發之linux環境搭建以及第一個程序:helloworld

  1. 下載esp32的idf源代碼 ,可以去GitHub網站git也可以去樂鑫官網資源裏下載
    git方法:
    在home/usr下創建一個esp的文件夾,然後
	cd ~/esp
	git clone -b v4.0 --recursive https://github.com/espressif/esp-idf.git

這個方法比較慢
樂鑫官網下載比較快,網址https://www.espressif.com/zh-hans/products/hardware/esp32/resources

在這裏插入圖片描述
2.設置編譯工具鏈,下載網址https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz
下載完成之後解壓在~/esp目錄下,

	cd ~/esp
	tar -xzf ~/Downloads/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz

3.下載軟件

libncurses-dev flex bison gperf python python-click python-pip python-setuptools python-serial python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache libffi-dev libssl-dev

輸入命令:

sudo apt-get install git wget libncurses-dev flex bison gperf python python-click python-pip python-setuptools python-serial python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache libffi-dev libssl-dev

1.設置環境變量
IDF_PATH 應設置爲 ESP-IDF 根目錄的路徑
PATH 應包括同一 IDF_PATH 目錄下的 tools 目錄路徑。
打開~/.bashrc 文件 sudo vi ~/.bashrc
在該文件最後一行添加export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"
在下一行添加IDF_PATH路徑export IDF_ PATH=$HOME/esp/idf的根目錄
保存
關閉當前終端並重新打開終端是環境變量生效
1. 拷貝idf目錄/get-start/helloworld文件夾到自己創建的任意一個文件夾內,進入該文件夾

cd helloworld

然後通過usb串口連接自己的esp32板子
執行make menuconfig
設置串口的號和波特率,默認就行
然後更改串口的權限,執行

sudo chmod 777 /dev/ttyUSB0

接着可以執行make

make -j32

j後面的數字代表同時進行的任務數,越大編譯的越快,這裏有32個make任務併發運行,所以就快一些

編譯完成之後就可以進行燒寫,執行:

make flash

在哪裏查看helloworld?,當然是在串口軟件裏,我們只需要執行

make monitor

就可以打開串口,然後看到自己的helloworld的信息了

...
Hello world!
Restarting in 10 seconds...
I (211) cpu_start: Starting scheduler on APP CPU.
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...

官方例子裏是十秒進行一次軟件復位,現在我們只要打開了第一道門,後面的wifi和藍牙,硬件接口,以及各種網絡協議的應用開發就很方便了,後期給大家繼續跟新esp32的開發教程

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章