ESP32 Setup on a Raspberry Pi

December 1, 2019

Today I decided to see if I could get the Espressif ESP32x Development Toolkit to work on my Raspberry Pi 4.

The Raspberry Pi is running Linux (albeit an Arm Architecture) so naturally the best starting places was to follow the Linux instructions at and hope that it was a dual binary.

Once it had been installed it was quite obvious that it only supported the x86 architecture – which was confirmed using the ‘file’ command on one of the executables in the bin/ directory.

$ file ~/esm/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
xtensa-esp32-elf-gcc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/, for GNU/Linux 2.6.32, BuildID[sha1]=81a0b55c5c0c1bae1bb9d9ef2ffafc0a054bedaf, stripped

I noticed at the bottom of the Linux Setup page a section titled “Related Documents” and that section has a link Setup Linux Toolchain from Scratch.

Install Prerequisites

I noted that the instruction were for Debian 9 but the Raspberry Pi was running Debian 10 however there didn’t seem to be any missing packages.

sudo apt-get install gcc git wget make libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-cryptography python-future python-pyparsing

sudo apt-get install gawk gperf grep gettext libncurses-dev python python-dev automake bison flex texinfo help2man libtool libtool-bin

Building the Toolchain from Source

I followed the instructions and entered the following commands:-

mkdir ~/esp
cd ~/esp
git clone -b xtensa-1.22.x
cd crosstool-NG
./bootstrap && ./configure --enable-local && make install

I expected the last command in the above section to take quite a while since it had a configuration and “make install” commands. I was expecting a coffee break so was a bit concerned when it finished in a matter of seconds.

Anyway it didn’t indicate that there had been any errors so I proceeded with the next section.

./ct-ng xtensa-esp32-elf
./ct-ng build
chmod -R u+w builds/xtensa-esp32-elf

I needn’t have worried about how quick the earlier step had been because the second command ( “./ct-ng build” ) took exactly 66 minutes 30 seconds on a 4GB Raspberry Pi 4.

After that I continued with their instructions and downloaded esp-idf.

cd ~/esp
git clone -b v3.3 --recursive

The last thing to do was to add the paths to the end of ~.profile

export PATH=~/esp/crosstool-NG/builds/xtensa-esp32-elf/bin:${PATH}
export IDF_PATH=~/esp/esp-idf

At this point we must login again so that the paths are picked up from the update .profile file.

Time to Test the Build

I connected the ESP32 to one of the spare USB2 ports on the Raspberry Pi and checked to see if the device had appear “/dev/ttyUSB0”

I then navigated to “~/esp/esp-idf/examples/get-started/hello_world” and then ran the “make” command.

After a brief period a configuration menu appeared and I checked that the Serial Flasher Config was set to the correct serial port (/dev/ttyUSB0).

The build continued without problem, I entered “make flash” and held the boot button down on the ESP32 until it started to download.

Monitoring the output of the ESP32 over the serial port

There is a tool include with the framework that allow you to monitor the output from the ESP32. Simply enter the following command in the directory containing the Makefile.

make simple_monitor

After starting the monitor it proceeded to print a list of information received over the serial port.

Hello world!
 This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
 Restarting in 10 seconds…
 Restarting in 9 seconds…
 Restarting in 8 seconds…

It was not obvious how to exit the monitor and the usual CTRL + C didn’t work. After a bit of research it turned out the CTRL + ] is the option to quit the monitor.

Other Notes

  • If you need to the run configuration menu again then you can do so by entering “make menuconfig”.
  • You can enter “make help” to see what other options are available.

Tags: esp32 pi