1. 程式人生 > >樂鑫esp32-lyrat開發板初體驗

樂鑫esp32-lyrat開發板初體驗

一.開發板使用前的準備

1.硬體準備

lyrat開發板要工作起來需要用一根microusb線接到供電口,而下載或者除錯裝置需要另一根microusb線接到串列埠端。另外要將電源鍵撥到ON的位置。該開發板的定位是智慧音箱,所以要測試音訊需要接一個3.5英寸介面的耳機/音箱。在燒錄程式之前還需要摁著boot按鍵再撥開電源鍵,這樣開發板才會進入燒錄模式。

2.開發環境的準備

(1)下載開發板的sdk

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

(2)安裝依賴庫

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

(3)編譯鏈、IDF和ADF的安裝和配置

編譯鏈的下載地址如下:

使用wget命令就可以下載

mkdir -p ~/esp
cd ~/esp
wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz 
tar -xzf /xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz

接下來配置編譯鏈、idf、adf的路徑,使用命令“vim ~/.profile”在profile檔案新增以下內容

export PATH="$PATH:$HOME/esp/xtensa-esp32-elf/bin"
alias get_esp32='export PATH="$PATH:$HOME/esp/xtensa-esp32-elf/bin"'
export IDF_PATH=~/workspace/esp32/esp-adf/esp-idf
export ADF_PATH=~/workspace/esp32/esp-adf

重啟電腦後使用命令驗證是否新增成功

$ printenv PATH
/home/user-name/bin:/home/user-name/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/user-name/esp/xtensa-esp32-elf/bin

二、編譯、下載、執行並除錯lyrat開發板

1.編譯的方法

編譯專案有時候需要配置wifi的帳號和密碼,在make menuconfig選單裡配置就行了。

cd ~/esp-adf/examples/get-started/play_mp3
make menuconfig
make -j4

2.下載的方法

執行‘make flash’命令,需要長摁著boot鍵,再短按一下reset鍵。啟動開發板,還有需要注意串列埠許可權的問題。

make  flash 

3.執行並除錯開發板

執行開發板之前需要摁reset鍵

make monitor

三、開發板使用的時候經常遇到的問題以及解決方法

1.開發板無法進入燒錄模式下載程式

因為esp32晶片進入燒錄模式的條件是啟動的時候會檢測boot引腳,所以需要摁著boot鍵啟動才能下載程式。

2.開發板下載程式的時候老是提示串列埠許可權不足

linux下面串列埠裝置的使用者一般是root,所以臨時使用串列埠需要賦予程式root許可權或者修改dev目錄下串列埠的許可權。如果想串列埠支援一般使用者,那麼就需要把當前使用者新增到撥號組,新增辦法如下面命令所示:

sudo usermod -a -G dialout $USER

3.使用make monitor提示出錯

1.錯誤資訊如下

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/opt/esp-adf/esp-idf/tools/idf_monitor.py", line 120, in _run_outer
    self.run()
  File "/opt/esp-adf/esp-idf/tools/idf_monitor.py", line 155, in run
    c = self.console.getkey()
  File "/opt/esp-adf/esp-idf/tools/idf_monitor.py", line 235, in getkey_patched
    c = self.enc_stdin.read(1)
AttributeError: 'Console' object has no attribute 'enc_stdin'

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/opt/esp-adf/esp-idf/tools/idf_monitor.py", line 120, in _run_outer
    self.run()
  File "/opt/esp-adf/esp-idf/tools/idf_monitor.py", line 193, in run
    if not self.serial.is_open:
AttributeError: 'Serial' object has no attribute 'is_open'

出現錯誤的原因應該是串列埠工具pyserial版本太低所致,那麼解決辦法就是升級pyserial工具

sudo -H pip install pyserial --upgrade

如果使用這個方法也會出錯,提示超時,那麼恭喜你了,網路被牆了!解決方法就是自備梯子再下載。

2.提示components要更新

[email protected]:~/workspace/esp32/esp-adf/examples/player/pipeline_http_mp3$ make
WARNING: esp-idf git submodule components/esp32/lib may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
WARNING: esp-idf git submodule components/micro-ecc/micro-ecc may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
WARNING: esp-idf git submodule components/esptool_py/esptool may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
WARNING: esp-idf git submodule components/esp32/lib may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
WARNING: esp-idf git submodule components/micro-ecc/micro-ecc may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
WARNING: esp-idf git submodule components/esptool_py/esptool may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
WARNING: esp-idf git submodule components/micro-ecc/micro-ecc may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
WARNING: esp-idf git submodule components/esptool_py/esptool may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
WARNING: esp-idf git submodule components/esp32/lib may be out of date. Run 'git submodule update' in IDF_PATH dir to update.

 解決方法是進IDF的目錄執行'git submodule update'

2.

編譯例程的時候出現這個錯誤:
/home/esp8266/Desktop/esp/esp-adf/components/audio_stream/./fatfs_stream.c:39:22: fatal error: wav_head.h: No such file or directory
compilation terminated.
make[1]: *** [fatfs_stream.o] Error 1
make: *** [component-audio_stream-build] Error 2

解決方法:

獲取所有子模組,輸入命令:

git submodule update --init

3.應用程式過大

esp_image: Image length 1390176 doesn't fit in partition length 1048576�[0m
�[0;31mE (516) boot: Factory app partition is not bootable�[0m

解決方法:

修改分割槽表,使應用程式可以大於2M

$IDF_PATH/components/partition_table/partitions_singleapp.csv

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 2M,

四、參考資料