From db54d05bede53bf0a2f240aef5a6ca14d7a84d4d Mon Sep 17 00:00:00 2001 From: Ryan Malloy Date: Mon, 2 Feb 2026 23:32:07 -0700 Subject: [PATCH] Makefile: use esptool directly, add LittleFS and erase targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PlatformIO's built-in upload breaks on the S2 Mini (1200bps USB touch reset disconnects the native USB port). All flash targets now call esptool directly with the correct S2 partition offsets: bootloader at 0x1000, firmware at 0x10000, LittleFS at 0x290000. Also adds USB.begin() before Serial.begin() in main.cpp — required for ESP32-S2 native USB-CDC to initialize properly. --- firmware/Makefile | 38 +++++++++++++++++++++++++++++++------- firmware/src/main.cpp | 3 ++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/firmware/Makefile b/firmware/Makefile index cf8d380..634716c 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,19 +1,43 @@ -.PHONY: build upload uploadfs monitor clean ota +.PHONY: build buildfs upload uploadfs monitor clean ota flash erase + +# Serial port — override with: make upload PORT=/dev/ttyACM0 +PORT ?= /dev/ttyACM2 +BAUD ?= 921600 +BUILD_DIR = .pio/build/lolin_s2_mini + +# ESP32-S2 bootloader lives at 0x1000 (not 0x0 like S3/C3) +BOOTLOADER_OFFSET = 0x1000 + +# LittleFS partition offset (from partition table) +FS_OFFSET = 0x290000 + +ESPTOOL = ~/.platformio/penv/bin/esptool build: pio run -upload: - pio run -t upload +buildfs: + pio run -t buildfs -uploadfs: - pio run -t uploadfs +upload: build + $(ESPTOOL) --chip esp32s2 --port $(PORT) --baud $(BAUD) \ + write_flash \ + $(BOOTLOADER_OFFSET) $(BUILD_DIR)/bootloader.bin \ + 0x8000 $(BUILD_DIR)/partitions.bin \ + 0x10000 $(BUILD_DIR)/firmware.bin -monitor: - pio device monitor +uploadfs: buildfs + $(ESPTOOL) --chip esp32s2 --port $(PORT) --baud $(BAUD) \ + write_flash $(FS_OFFSET) $(BUILD_DIR)/littlefs.bin flash: upload uploadfs +monitor: + pio device monitor --port $(PORT) + +erase: + $(ESPTOOL) --chip esp32s2 --port $(PORT) erase_flash + clean: pio run -t clean diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index d2c8bc8..ff37788 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -185,8 +185,9 @@ bool isOTAEnabled() { // --- Setup --- void setup() { + USB.begin(); Serial.begin(115200); - delay(1000); // Allow USB CDC to initialize + delay(2000); // Allow USB CDC to enumerate on host Serial.println(); Serial.println("================================");