linux-setup.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. Step 0: Prerequisites
  2. =====================
  3. Install some packages
  4. ---------------------
  5. To compile with ESP-IDF you need to get the following packages:
  6. - Ubuntu and Debian::
  7. sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial
  8. - Arch::
  9. sudo pacman -S --needed gcc git make ncurses flex bison gperf python2-pyserial
  10. Step 1: Download binary toolchain for the ESP32
  11. ==================================================
  12. ESP32 toolchain for Linux is available for download from Espressif website:
  13. - for 64-bit Linux::
  14. https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-59.tar.gz
  15. - for 32-bit Linux::
  16. https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-59.tar.gz
  17. Download this file, then extract it to the location you prefer, for example::
  18. mkdir -p ~/esp
  19. cd ~/esp
  20. tar -xzf ~/Downloads/xtensa-esp32-elf-linux64-1.22.0-59.tar.gz
  21. The toolchain will be extracted into ``~/esp/xtensa-esp32-elf/`` directory.
  22. To use it, you will need to update your ``PATH`` environment variable in ``~/.bash_profile`` file. To make ``xtensa-esp32-elf`` available for all terminal sessions, add the following line to your ``~/.bash_profile`` file::
  23. export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin
  24. Alternatively, you may create an alias for the above command. This way you can get the toolchain only when you need it. To do this, add different line to your ``~/.bash_profile`` file::
  25. alias get_esp32="export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin"
  26. Then when you need the toolchain you can type ``get_esp32`` on the command line and the toolchain will be added to your ``PATH``.
  27. Alternative Step 1: Compile the toolchain from source using crosstool-NG
  28. ========================================================================
  29. Instead of downloading binary toolchain from Espressif website (Step 1 above) you may build the toolchain yourself.
  30. If you can't think of a reason why you need to build it yourself, then probably it's better to stick with the binary version. However, here are some of the reasons why you might want to compile it from source:
  31. - if you want to customize toolchain build configuration
  32. - if you want to hack gcc or newlib or libstdc++
  33. - if you are curious and/or have time to spare
  34. - if you don't trust binaries downloaded from the Internet
  35. In any case, here are the steps to compile the toolchain yourself.
  36. - Install dependencies:
  37. - Ubuntu::
  38. sudo apt-get install gawk gperf grep gettext ncurses python python-dev automake bison flex texinfo help2man libtool
  39. - Debian::
  40. TODO
  41. - Arch::
  42. TODO
  43. Download ``crosstool-NG`` and build it::
  44. cd ~/esp
  45. git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
  46. cd crosstool-NG
  47. ./bootstrap && ./configure --prefix=$PWD && make install
  48. Build the toolchain::
  49. ./ct-ng xtensa-esp32-elf
  50. ./ct-ng build
  51. chmod -R u+w builds/xtensa-esp32-elf
  52. Toolchain will be built in ``~/esp/crosstool-NG/builds/xtensa-esp32-elf``. Follow instructions given in the previous section to add the toolchain to your ``PATH``.
  53. Step 2: Getting ESP-IDF from github
  54. ===================================
  55. Open terminal, navigate to the directory you want to clone ESP-IDF and clone it using ``git clone`` command::
  56. cd ~/esp
  57. git clone --recursive https://github.com/espressif/esp-idf.git
  58. ESP-IDF will be downloaded into ``~/esp/esp-idf``.
  59. Note the ``--recursive`` option! If you have already cloned ESP-IDF without this option, run another command to get all the submodules::
  60. cd ~/esp/esp-idf
  61. git submodule update --init
  62. **IMPORTANT:** The esp-idf build system does not support spaces in paths to esp-idf or to projects.
  63. Step 3: Starting a project
  64. ==========================
  65. ESP-IDF by itself does not build a binary to run on the ESP32. The binary "app" comes from a project in a different directory. Multiple projects can share the same ESP-IDF directory.
  66. The easiest way to start a project is to download the template project from GitHub::
  67. cd ~/esp
  68. git clone https://github.com/espressif/esp-idf-template.git myapp
  69. This will download ``esp-idf-template`` project into ``~/esp/myapp`` directory.
  70. Step 4: Building and flashing the application
  71. =============================================
  72. In terminal, go to the application directory which was obtained on the previous step::
  73. cd ~/esp/myapp
  74. Type a command like this to set the path to ESP-IDF directory::
  75. export IDF_PATH=~/esp/esp-idf
  76. At this point you may configure the serial port to be used for uploading. Run::
  77. make menuconfig
  78. Then navigate to "Serial flasher config" submenu and change value of "Default serial port" to match the serial port you will use. Also take a moment to explore other options which are configurable in ``menuconfig``.
  79. Special note for Arch Linux users: navigate to "SDK tool configuration" and change the name of "Python 2 interpreter" from ``python`` to ``python2``.
  80. Now you can build and flash the application. Run::
  81. make flash
  82. This will compile the application and all the ESP-IDF components, generate bootloader, partition table, and application binaries, and flash these binaries to your development board.
  83. Further reading
  84. ===============
  85. If you'd like to use the Eclipse IDE instead of running ``make``, check out the Eclipse setup guide in this directory.