当前位置:网站首页>Esp8266 system environment setup

Esp8266 system environment setup

2022-06-10 19:26:00 Jiangxiaodou

1. Preface

because ESP8266/ESP32 This development environment is full of trouble , I have never seen such a difficult and unclear environment .

Simple development can use Arduino IDE , This platform is very good . Development use Arduino Function library , Very efficient .
But I'm still not used to it , For example, in the example binker demo Of LED_BUILTIN, Can't jump to the definition , Don't like . Now let's seriously build a 8266 Environment . In fact, it's quite simple , I just haven't found the right place .

Find official documents from other bloggers : ESP8266_RTOS_SDK Programming Guide , I am a person with obsessive-compulsive disorder in knowledge retrieval , I don't know where to find this link. I feel uncomfortable , Finally, it can be found on the official website esp8266 Links to getting started under categories .

The specific steps to build a development environment are : Tool chain 、 obtain SDK、 To configure ( If you want to use IDE It should be IDE Configuration of ).

The four steps in the development process are :

  • Configure the project and write code
  • Compile the project and link , To build applications
  • Burn to ESP8266
  • Debugging and monitoring

2. Build the development environment

2.1 Tool chain access

Windows Integrated tool chain and MSYS2 zip file :

https://dl.espressif.com/dl/esp32_win32_msys2_environment_and_toolchain-20181001.zip

I was going to use git bash Self contained mingw Well , result make Stage reminders should use mingw32 Under the msys. As a result, I managed to use the integration tool provided by the official website .

The subsequent orders are in MINGW32.exe Executed under .

2.2 SDK clone

git clone --recursive https://github.com/espressif/ESP8266_RTOS_SDK.git

We must add recursive Loop download sub module , I didn't add , The result will be in make Download other libraries only when , I can't download it yet .

When I add this parameter , I found that the download was very slow , Hanging up the tools is slow , After waiting for a long time, I finally finished downloading . Another option is to use gitee download SDK( no need recursive Download sub module ), Use a tool to download the submodule , Reference resources : Build with Lexin's domestic image ESP8266_RTOS_SDK development environment

I can't imagine that Lexin values the overseas market , How to make the domestic ecology not so good .

2.3 To configure

notes : Tool chains use environment variables IDF_PATH visit SDK Catalog , stay ~/.bash_profile Add... At the end

export IDF_PATH="G:/IOT/ESP8266/ESP8266_RTOS_SDK"

Use source Order it into effect

source ~/.bash_profile

Download other tools

ESP8266 Compiling and burning are based on Python Realization , Need to install python The library of .

$ python -m pip install -r $IDF_PATH/requirements.txt

Come here , Environment configuration is complete . No no no

ESP8266 Proprietary tool chain settings

The integrated environment is for ESP32 Set up ,ESP8266 You also need to download specific tool chains , This official website document or RTOS There is also a link in the description :

v8.4.0

https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-win32.zip

If you are still using an older version SDK(< 3.0), Please use the tool chain v4.8.5, as follows :

https://dl.espressif.com/dl/xtensa-lx106-elf-win32-1.22.0-88-gde0bdc1-4.8.5.tar.gz

After downloading the first , decompression . then .bash_profile Add environment variables to :

export PATH="$PATH:/G/IOT/ESP8266/xtensa-lx106-elf/bin"

If it's not configured here ESP8266 Proprietary tool chain ,make A reminder will appear after configuration :

GENCONFIG
make:xtensa-lx106-elf-gcc: Command not found

3. The development process

Project configuration

take sdk Medium examples/git-startd/hello_world Copy out , use mingw32 Execute to this directory , function

make menuconfig

You will see the following interface : Make some configuration ( A serial port , Baud rate, etc )

burn

Only the port number and are set flash( It was originally 4M, An error is reported during burning , Set to 2M succeed ) after , Then use the compile and burn commands

make flash

Report errors :

 Submodules  'components/json/cJSON'(https://github.com/DaveGamble/cJSON.git) No path  'components/json/cJSON'  register 
 Is cloning to  '/g/IOT/ESP8266/ESP8266_RTOS_SDK/components/json/cJSON'...
fatal: unable to access 'https://github.com/DaveGamble/cJSON.git/': OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
fatal:  Unable to clone  'https://github.com/DaveGamble/cJSON.git'  Path to submodule  '/g/IOT/ESP8266/ESP8266_RTOS_SDK/components/json/cJSON'
 clone  'components/json/cJSON'  Failure . Retry as scheduled 
 Is cloning to  '/g/IOT/ESP8266/ESP8266_RTOS_SDK/components/json/cJSON'...

This is because from github Downloading some modules failed , There are two solutions online . First, manually download and put it into the corresponding directory , The second is to enlarge http.postBuffer Value . I used the first one , Another error is reported during compilation , Then use the second type . I can't find it , Go and find out why it happened , Discover clones SDK I didn't add recursive Parameter cycle download sub module .

After burning successfully .

It can be used make monitor Monitoring serial port :

hello_world, Just print out CPU Check the number , external Flash size 2M.

use make monitor It is normal to look at the data , What you see with other serial port tools is garbled code , It turns out that the default baud rate here is not 115200, yes 74800. Modify baud rate method :

Here, the environment is built . I'll go to the company tomorrow , Arrangement & Record the problem .

Use VSCODE Make a development environment

Terminal and compiler

vscode Right click the workspace → Open at the integration terminal and replace with mingw32. User settings need to be changed , Or the settings of the current workspace ( stay .vscode/settings.json)

    "terminal.integrated.shell.windows":"D:\\Software\\esp32_win32_msys2_environment_and_toolchain-20181001\\msys32\\msys2_shell.cmd",
    "terminal.integrated.shellArgs.windows": ["-defterm", "-mingw32", "-no-start", "-here"]

make menuconfig Random code :

file \msys32\etc\profile.d\esp32_toolchain.sh New language configuration :(zh_Cn) It's OK

export LANG="en_Us"

Then it can be used smoothly under the terminal make 了 .

Library settings

Now? vscode Look at code below , There is no associated library , So neither the function nor the header file can be skipped

Header files fall into two categories , As shown in the figure , One is system library stdio.h etc. , One is that RTOS Library in .

First, add the configuration file ,

stay incluPath Add these two types of libraries to : My configuration is as follows , The first is RTOS library , The last three are systems gcc Library used ( Two asterisks indicate that the directory is searched recursively )

"includePath": [
    "E:/labs/esp8266/ESP8266_RTOS_SDK/components/**",

    "E:/labs/esp8266/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/8.4.0/**",
    "E:/labs/esp8266/xtensa-lx106-elf/xtensa-lx106-elf/sys-include" ,
    "E:/labs/esp8266/xtensa-lx106-elf/xtensa-lx106-elf/include", 
    "${workspaceFolder}/**"
    
],

Want to see gcc Included files , Through the command gcc -v -E -x c++ - , because make They found gcc It uses Toolchain path: /E/labs/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc, So you should use /E/labs/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -v -E -x c++ - View the import library location , What is needed is the Library Directory shown in the red box below

So you can jump .

summary

The environment has been built for a long time . I have to summarize , Give some guidance to others who are confused .

Software and libraries needed :msys2 Tool chain ( You can also install it yourself , However, it is recommended to use the official )、8266 Unique tool chain 、RTOS The library of ( Cloning is troublesome , In fact, the required components can be downloaded one by one and put into the specified directory ). Configuration is to put 8266 and RTOS The path of the library is configured in the environment variable (.bash_profile). Then burn and run . It doesn't seem like much trouble now , But the process is really painful .

Reference resources

原网站

版权声明
本文为[Jiangxiaodou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101824212450.html