linux-setup.rst 5.4 KB

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