macos-setup.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. Set up of Toolchain for Mac OS
  2. ******************************
  3. Step 0: Prerequisites
  4. =====================
  5. - install pip::
  6. sudo easy_install pip
  7. - install pyserial
  8. sudo pip install pyserial
  9. Step 1: Download binary toolchain for the ESP32
  10. ==================================================
  11. ESP32 toolchain for macOS is available for download from Espressif website:
  12. https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-61-gab8375a-5.2.0.tar.gz
  13. Download this file, then extract it to the location you prefer, for example::
  14. mkdir -p ~/esp
  15. cd ~/esp
  16. tar -xzf ~/Downloads/xtensa-esp32-elf-osx-1.22.0-61-gab8375a-5.2.0.tar.gz
  17. The toolchain will be extracted into ``~/esp/xtensa-esp32-elf/`` directory.
  18. To use it, you will need to update your ``PATH`` environment variable in ``~/.profile`` file. To make ``xtensa-esp32-elf`` available for all terminal sessions, add the following line to your ``~/.profile`` file::
  19. export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin
  20. 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 ``~/.profile`` file::
  21. alias get_esp32="export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin"
  22. Then when you need the toolchain you can type ``get_esp32`` on the command line and the toolchain will be added to your ``PATH``.
  23. Alternative Step 1: Compile the toolchain from source using crosstool-NG
  24. ========================================================================
  25. Instead of downloading binary toolchain from Espressif website (Step 1 above) you may build the toolchain yourself.
  26. 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:
  27. - if you want to customize toolchain build configuration
  28. - if you want to use a different GCC version (such as 4.8.5)
  29. - if you want to hack gcc or newlib or libstdc++
  30. - if you are curious and/or have time to spare
  31. - if you don't trust binaries downloaded from the Internet
  32. In any case, here are the steps to compile the toolchain yourself.
  33. - Install dependencies:
  34. - Install either MacPorts_ or homebrew_ package manager. MacPorts needs a full XCode installation, while homebrew only needs XCode command line tools.
  35. .. _homebrew: http://brew.sh/
  36. .. _MacPorts: https://www.macports.org/install.php
  37. - with MacPorts::
  38. sudo port install gsed gawk binutils gperf grep gettext wget libtool autoconf automake
  39. - with homebrew::
  40. brew install gnu-sed gawk binutils gperftools gettext wget help2man libtool autoconf automake
  41. Create a case-sensitive filesystem image::
  42. hdiutil create ~/esp/crosstool.dmg -volname "ctng" -size 10g -fs "Case-sensitive HFS+"
  43. Mount it::
  44. hdiutil mount ~/esp/crosstool.dmg
  45. Create a symlink to your work directory::
  46. cd ~/esp
  47. ln -s /Volumes/ctng crosstool-NG
  48. Download ``crosstool-NG`` and build it::
  49. cd ~/esp
  50. git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
  51. cd crosstool-NG
  52. ./bootstrap && ./configure --enable-local && make install
  53. Build the toolchain::
  54. ./ct-ng xtensa-esp32-elf
  55. ./ct-ng build
  56. chmod -R u+w builds/xtensa-esp32-elf
  57. 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``.
  58. Step 2: Getting ESP-IDF from github
  59. ===================================
  60. Open Terminal.app, navigate to the directory you want to clone ESP-IDF and clone it using ``git clone`` command::
  61. cd ~/esp
  62. git clone --recursive https://github.com/espressif/esp-idf.git
  63. ESP-IDF will be downloaded into ``~/esp/esp-idf``.
  64. Note the ``--recursive`` option! If you have already cloned ESP-IDF without this option, run another command to get all the submodules::
  65. cd ~/esp/esp-idf
  66. git submodule update --init
  67. Step 3: Starting a project
  68. ==========================
  69. 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.
  70. The easiest way to start a project is to download the template project from GitHub::
  71. cd ~/esp
  72. git clone https://github.com/espressif/esp-idf-template.git myapp
  73. This will download ``esp-idf-template`` project into ``~/esp/myapp`` directory.
  74. **IMPORTANT:** The esp-idf build system does not support spaces in paths to esp-idf or to projects.
  75. You can also find a range of example projects under the "examples" directory in IDF. These example project directories can be copied to outside IDF in order to begin your own projects.
  76. Step 4: Building and flashing the application
  77. =============================================
  78. In Terminal.app, go to the application directory which was obtained on the previous step::
  79. cd ~/esp/myapp
  80. Type a command like this to set the path to ESP-IDF directory::
  81. export IDF_PATH=~/esp/esp-idf
  82. At this point you may configure the serial port to be used for uploading. Run::
  83. make menuconfig
  84. 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``.
  85. If you don't know device name for the serial port of your development board, run this command two times, first with the board unplugged, then with the board plugged in. The port which appears the second time is the one you need::
  86. ls /dev/tty.*
  87. Now you can build and flash the application. Run::
  88. make flash
  89. 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.
  90. Further reading
  91. ===============
  92. If you'd like to use the Eclipse IDE instead of running ``make``, check out the Eclipse setup guide in this directory.