I often will pop into a commandline to quickly tweek an ESP32 project instead of bringing up the Arduino IDE 2.x so I created a Makefile to compile some of my projects and because of the SPIFFS /LITTLEFS issue of the missing IDE 2.x GUI tool I added the capability to the Makefile. You will have to tweak you device port and some of the paths to where you put things but here's a semi-generic Makefile I copy to each of my ESP32 project directories. If on Windows you'll need to run it from a Linux container or something since I use make, grep, cat, cut, xargs, printf and maybe some other standard *nix tools to figure out flash filesystem settings based on chips used.
I compile using: make build
I compile and flash using: make build flash
I create my SPIFFS or LittleFS image using: make filesystem.bin
I upload my filesystem image using: make flash-fs
Code: Select all
#
# Usage: make build | flash | filesystem.bin | flash-fs | clean
#
CHIP := esp32
sketch := YOUR_SKETCH_HERE.ino
CORE :=esp32:esp32
# Flashing on an "ESP32 Dev Module" board
boardconfig :="${CORE}:${CHIP}"
ARDUINO_PATH=~/Projects/Arduino/arduino-ide_nightly-20230206_Linux_64bit/resources/app/node_modules/arduino-ide-extension/build/
ESP32_PATH=~/.arduino15/packages/esp32/hardware/esp32/2.0.7/
ARDUINO_CLI ?= $(ARDUINO_PATH)/arduino-cli
TOOL_PATH=~/.arduino15/packages/esp32/tools/
MKSPIFFS ?= ~/.arduino15/packages/esp32/tools/mkspiffs/0.2.3/mkspiffs
MKLITTLEFS ?= ~/.arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933/mklittlefs
# Partition table configuration options:
# default default_ffat ffat huge_app large_spiffs_16MB max_app_8MB
# minimal min_spiffs noota_3g
# app3M_fat9M_16MB bare_minimum_2MB default_16MB default_8MB
# noota_3gffat no_ota noota_ffat
# rainmaker
PARTITIONTYPE := default
#PARTITIONTYPE := min_spiffs
PARTITIONSIZE := "${PARTITIONTYPE}.csv"
PARTITIONMAX := `cat $(ESP32_PATH)/tools/partitions/${PARTITIONSIZE} | grep app0 | cut -f5 -d',' | xargs printf "%d" | cut -f1 -d'('`
PARTITION_TABLE=$(ESP32_PATH)/tools/partitions/${PARTITIONSIZE}
partitioncmd := --build-property build.partitions=${PARTITIONTYPE} --build-property upload.maximum_size=${PARTITIONMAX}
DEVICE :=/dev/ttyUSB0
#DEVICE :=/dev/ttyACM0
.PHONY: build
build:
$(ARDUINO_CLI) compile --verbose --fqbn $(boardconfig) $(sketch) $(partitioncmd)
.PHONY: flash
flash:
$(ARDUINO_CLI) upload --verbose -p ${DEVICE} --fqbn ${boardconfig} ${sketch} $(partitioncmd)
.PHONY: filesystem.bin
.ONESHELL:
filesystem.bin:
PROPS=$$($(ARDUINO_CLI) compile --fqbn $(boardconfig) --show-properties)
BUILD_FS_BLOCKSIZE=4096
BUILD_FS_PAGESIZE=256
BUILD_FS_START_HEX=$$(cat ${PARTITION_TABLE} | grep "^spiffs"|cut -d"," -f4 | xargs)
#echo "BUILD_FS_START_HEX = $${BUILD_FS_START_HEX}"
BUILD_FS_START=`printf "%d" $${BUILD_FS_START_HEX}`
BUILD_FS_SIZE_HEX=$$(cat ${PARTITION_TABLE} | grep "^spiffs"|cut -d, -f5 | xargs)
BUILD_FS_SIZE=`printf "%d" $${BUILD_FS_SIZE_HEX}`
$(MKSPIFFS) -c data --page $$BUILD_FS_PAGESIZE --block $$BUILD_FS_BLOCKSIZE --size $$BUILD_FS_SIZE $@
#$(MKLITTLEFS) -c data --page $$BUILD_FS_PAGESIZE --block $$BUILD_FS_BLOCKSIZE --size $$BUILD_FS_SIZE $@
.PHONY: flash-fs
.ONESHELL:
flash-fs: filesystem.bin
BUILD_FS_START_HEX=$$(cat ${PARTITION_TABLE} | grep "^spiffs"|cut -d, -f4 | xargs)
python ~/.arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool.py --chip ${CHIP} \
--port ${DEVICE} \
--baud 460800 \
--before default_reset \
--after hard_reset \
write_flash $${BUILD_FS_START_HEX} filesystem.bin
.PHONY: clean
clean:
rm -rf build
rm -f filesystem.bin