Automatically program your ESP32 based boards when they are plugged in via USB with udev, systemd and bash.
- Install esptool and ampy with
pip install esptool adafruit-ampyor withpip install -r requirements.txt. - If you're using MicroPython or CircuitPython and would like to upload your
.pyfiles automatically, copy them to the project directory. - Create the
flash_argsfile based on your programming command. You need to put all the arguments and options forwrite_flashoption inside this file excluding--chipand--port. See flash_args.micropython and flash_args.platformio for examples. - Plug in an ESP32 board into your computer and find the device name. Also copy
vendor ID and product ID. You can use
dmesgcommand to find these information. - Test out the script by running
esp32-program.sh <port>where<port>is the device name you copied in the previous step. If your firmware file(s) get flashed successfully you can continue. You can unplug the device. - If the vendor ID and product ID is not in the 99-esp32-auto-program.rules file, edit it so that all the VIDs and PIDs of your USB-to-UART ICs are present. You can add a new line based on the existing entries or replace them.
- Run
makeormake buildto build the application. This fills the user and path values in the service template file and bash scripts and copy them to thebuildfolder. - Run
sudo make installto install the udev rule and the service template files. - When you plug in a new ESP32 board into your computer, it'll automatically
get programmed and log files will be put into the
logsfolder. You can use them to debug any issues. - If you need to uninstall, you can do so with
sudo make uninstall. You can cleanup thebuilddirectory withmake clean.