This page presents a workaround that allows working with ESP32 devices with current Arduino port. It was presented on the FreeBSD Forum by Raffeale. Hopefully it will get into the upstream one day and provide out of the box experience on FreeBSD :-)

NOTE: THIS IS A DIRTY UGLY HACK! NEVER WORK LIKE THIS ON FreeBSD! YOU CAN BREAK YOUR SYSTEM!

Intructions

Perform these steps as root (yuck!):

1. Install arduino18 from ports devel/arduino18.

2. Install "ESP32 for Arduino" package into the Arduino's local hardware database (as root).

cd  /usr/local/arduino/hardware
mkdir -p espressif
cd  /usr/local/arduino/hardware/espressif
git clone https://github.com/espressif/arduino-esp32.git esp32
cd esp32
git submodule update --init --recursive

3. Modify scripts to fetch Linux 64-bit version of the toolchain, or use evel/xtensa-esp32-elf toolchain that is already present in the port tree (second way preferred and presented here):

pkg install xtensa-esp32-elf
cd  /usr/local/arduino/hardware/espressif/esp32/tools
ln -s /usr/local/xtensa-esp32-elf  .

4. Update esptool that is used to convert ELF to BIN for ESP32:

cd /usr/local/arduino/hardware/espressif/esp32/tools
git clone https://github.com/espressif/esptool.git esptool

5. Create a wrapper script that will launch esptool from Arduino build system:

cd /usr/local/arduino/hardware/espressif/esp32/tools/esptool
printf '#\!/bin/sh\n/usr/bin/env python /usr/local/arduino/hardware/espressif/esp32/tools/esptool.py $@' > esptool
chmod +x esptool

6. Create a patch for devel/arduino-builder - just place a a text file in /usr/ports/devel/arduino-builder/files:

--- src/arduino.cc/builder/utils/utils.go.orig    2021-01-13 22:48:24.097459000 +0800
+++ src/arduino.cc/builder/utils/utils.go    2021-01-13 22:49:18.264758000 +0800
@@ -404,7 +404,7 @@ func NULLFile() string {
     if runtime.GOOS == "windows" {
         return "nul"
     }
-    return "/dev/null"
+    return "/tmp/null"
}

func MD5Sum(data []byte) string {

7. Rebuild and Reinstall a patch for devel/arduino-builder:

cd /usr/ports/devel/arduino-builder
make clean reinstall

8. For use serial port to download program to esp board , you need add serial port driver into kernel put these into /boot/loader.conf:

uftdi_load="YES"
uchcom_load="YES"
uslcom_load="YES"
uarduno_load="YES"

9. Install python serial library

pkg install py37-pyserial

Now the part as normal user that will use Arduino. Because most of the scripts are written for Linux we need to provide default python executable in the path:

mkdir -p $HOME/.local/bin
ln -s /usr/local/bin/python3.7 $HOME/.local/bin/python
echo "PATH=$HOME/.local/bin/:$PATH" >> $HOME/.profile

Reboot you machine, login as user, run arduino, you will see new ESP32 in the Tools / Board menu, run Verify to build the example empty template, if no problems are found that means you have installed the toolchain and utilities successfully! :-)

In case you need help ask at the Forum Thread.

Notes

1. There are some Arduino libraries which conflict with the esp32 library. You have to move /usr/local/arduino/libraries/Wifi and SD modules to /usr/local/arduino/hardware/arduino/avr/libraries

2. upload is ok , bug program is not running correctly (1) choose incorrectly partition scheme, choose the first scheme is okay for standard esp32s board (2) esptools version is too old. Use the latest esptools (esptools is upload tools for esp32, you can find it in /usr/local/arduino/hardware/espressif/esp32/tools) 3.esptools download link https://github.com/espressif/esptool

Arduino/esp32 (last edited 2023-03-31T00:14:37+0000 by cederom)