Windows
To get started with ESP32, read through their documentation considering that the devkit I chose uses the WROVER-E chip. The Get Started page is the best place to start. They have Visual Studio Code and Eclipse plugins, but as I use emacs, I opted to install the components separately. If you're using windows, you can follow their Toolchain from Scratch guide and install the following:
- CMake 3.21.4
- ESP-IDF v4.3.1
- Ninja Build v1.10.2 (add to
PATH
) - Python 3.10.0 (install
pyserial
usingpip
) - xtense-esp32-elf toolchain (add
bin/
toPATH
)
The guide also requests installation of other tools. Once again, I went the "from scratch" route to better understand the pieces in case they fall apart later. The guide mentions "ESP-IDF build system expects that all the necessary tools are installed somewhere, and made available in the PATH." Here's the list of required tools and their download links. Below is what I needed.
- esp32ulp-elf
- openocd-esp32 v0.10.0
- idf-exe
- ccache v4.5
- dfu-util v0.11
Then set IDF_PATH
environment variable to the path of esp-idf-v4.0.4
directory.
To install the python dependencies for idf.py
, use the requirements.txt
file under the esp-idf-v4.0.4
directory. Make sure to fix any warning like "pyserial not in path" as idf needs those tools to do its job.
Once all the tools are downloaded and added to PATH
, we can compile and run a sample project.
Linux
I prefer to work on Linux and so the setup was a bit easier. On linux I opted to use the master branch of their git repository rather than a release version.
Install the required packages, download crosscompiling toolchain, binutils for esp32, openocd for esp32, and ESP-IDF (clone recursively).
Add their respective paths to
PATH
. I added the following snippet in my$HOME/.profile
.for d in $(find /home/armin/pkgs/esp32 -name bin -type d); do PATH="$d:$PATH"; done IDF_PATH="$HOME/pkgs/esp32/esp-idf" IDF_TOOLS_PATH="${IDF_PATH}/components/esptool_py/esptool" IDF_TOOLS_PATH="${IDF_TOOLS_PATH}:${IDF_PATH}/components/espcoredump" IDF_TOOLS_PATH="${IDF_TOOLS_PATH}:${IDF_PATH}/components/partition_table" IDF_TOOLS_PATH="${IDF_TOOLS_PATH}:${IDF_PATH}/tools" PATH="${IDF_TOOLS_PATH}:$PATH"
If you're using ubuntu, also install
python-is-python3
to squash the error about missing python.Install python packages from esp-idf's
requirements.txt
.idf.py menuconfig
also requireslibncurses
header files (libncurses-dev
in ubuntu).
Once all the tools are downloaded and added to PATH
, we can compile and run a sample project. Make sure to add your user to group dialout
if required. Check permissions on /dev/ttyUSB#
and see what permissions are required to write into it.
To use the serial port on WSL, look into device manager and make a note of the COM port. The serial port on my setup is noted as Silicon Labs CP210x USB to UART Bridge
which is the chipset used on the ESP32 kit I'm using (DevKitC-VE v4). Then within WSL, you can use /dev/ttyS#
where #
is the COM port number.
It seems WSL has issues with accessing serial ports. I tried many times and was not able to consistently flash the esp32. I encountered odd errors and the device kept resetting in the middle of flashing.
Next steps
Now you can configure Emacs and lsp for ESP32 development. Don't forget to configure esp32 for jtag debugging. I initially opted to use ESP-Prog board to debug the ESP32-DevKitC board I had, but I eventually upgraded to a WROVER-Kit as you can't program the ESP32-DevKitC board with the programming interface available on the esp-prog board. Jtag could be used to program the board through esp-prog (or any other ft2232 kit), but WROVER kit made things simpler to setup.