From 3326a59f0ce46422a541eb3a98bc9f4135cdf379 Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Tue, 21 Oct 2025 13:08:46 +1300 Subject: [PATCH 1/6] Initial effort to support espa-v2 boards using ESP32-C6-mini-1 module. --- .github/workflows/build_and_release.yml | 2 +- lib/MultiBlinker/MultiBlinker.h | 7 ++- partitions/espa_v2_partitions.csv | 83 +++++++++++++++++++++++++ platformio.ini | 28 ++++++--- src/main.cpp | 2 +- 5 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 partitions/espa_v2_partitions.csv diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index 6afe03e..b871a51 100644 --- a/.github/workflows/build_and_release.yml +++ b/.github/workflows/build_and_release.yml @@ -29,7 +29,7 @@ jobs: if: needs.pre_job.outputs.concurrent_workflows == 'false' || (needs.pre_job.outputs.concurrent_workflows == 'true' && github.ref_type == 'tag') strategy: matrix: - platform: [esp32dev, spa-control-pcb] + platform: [esp32dev, espa-v1, espa-v2] uses: ./.github/workflows/build_firmware.yml with: platform: ${{ matrix.platform }} diff --git a/lib/MultiBlinker/MultiBlinker.h b/lib/MultiBlinker/MultiBlinker.h index 56710e8..5908d08 100644 --- a/lib/MultiBlinker/MultiBlinker.h +++ b/lib/MultiBlinker/MultiBlinker.h @@ -7,11 +7,16 @@ extern RemoteDebug Debug; // These are the four LEDs on the PCB -#ifdef SPACTRLPCB +#if defined(ESPA_V1) const int PCB_LED1 = 14; const int PCB_LED2 = 41; const int PCB_LED3 = 42; const int PCB_LED4 = 43; +#elif defined(ESPA_V2) + const int PCB_LED1 = 18; + const int PCB_LED2 = 21; + const int PCB_LED3 = 22; + const int PCB_LED4 = 23; #endif // Define error state constants diff --git a/partitions/espa_v2_partitions.csv b/partitions/espa_v2_partitions.csv new file mode 100644 index 0000000..9ae7002 --- /dev/null +++ b/partitions/espa_v2_partitions.csv @@ -0,0 +1,83 @@ +# =================================================================== +# ESP32-C6-MINI-1 Partition Table Explanation (4 MB flash) +# =================================================================== +# +# Partition Layout Overview: +# -------------------------- +# The flash is organized into several partitions. Each partition has: +# - Name: logical name used by the system or your application +# - Type: 'app' or 'data' +# - SubType: specifies role (e.g., ota_0, ota_1, spiffs, nvs) +# - Offset: starting flash address (must be 0x10000-aligned for app partitions) +# - Size: size of the partition in bytes (hex) +# - Flags: optional, can usually be left blank +# +# Partition Definitions: +# ---------------------- +# 1. nvs +# Type: data +# SubType: nvs +# Offset: 0x9000 +# Size: 0x7000 (28 KB) +# Purpose: Non-volatile key-value storage used for: +# - Wi-Fi credentials +# - Preferences API data +# - PHY calibration and system parameters +# +# 2. otadata +# Type: data +# SubType: ota +# Offset: 0x10000 +# Size: 0x2000 (8 KB) +# Purpose: OTA metadata used by the bootloader to track which app partition +# should be booted. Must be present if OTA updates are used. +# +# 3. app0 +# Type: app +# SubType: ota_0 +# Offset: 0x20000 +# Size: 0x180000 (1.5 MB) +# Purpose: Primary firmware slot for OTA updates. This is where the current +# running firmware is stored. +# +# 4. app1 +# Type: app +# SubType: ota_1 +# Offset: 0x1A0000 +# Size: 0x180000 (1.5 MB) +# Purpose: Secondary firmware slot for OTA updates. When performing OTA, +# new firmware is written here, then the bootloader switches to it. +# +# 5. spiffs +# Type: data +# SubType: spiffs +# Offset: 0x340000 +# Size: 0x20000 (128 KB) +# Purpose: SPI Flash File System for storing: +# - Web UI assets (HTML/CSS/JS) +# - Configuration files +# - Other persistent application data +# +# Alignment Notes: +# ---------------- +# - App partitions (app0 and app1) must start at multiples of 0x10000 (64 KB) for proper flash alignment. +# - SPIFFS and data partitions can be less strictly aligned, but staying on 0x10000 boundaries is recommended. +# - NVS must end before the first 0x10000 boundary so that app0 can start properly. +# +# Total Flash Usage: +# ------------------ +# 4 MB total flash: +# - nvs + otadata: 36 KB +# - app0 + app1: 3 MB +# - spiffs: 128 KB +# - Remaining space: bootloader, alignment padding +# +# =================================================================== + + +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x7000, +otadata, data, ota, 0x10000, 0x2000, +app0, app, ota_0, 0x20000, 0x180000, +app1, app, ota_1, 0x1A0000, 0x180000, +spiffs, data, spiffs, 0x340000, 0x20000 diff --git a/platformio.ini b/platformio.ini index 135f6f0..30c25e2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,10 +9,11 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = esp32dev, spa-control-pcb +default_envs = esp32dev, espa-v1, espa-v2 ; data_dir = {$PROJECT_DIR}/data [env:spa-base] +platform = espressif32 framework = arduino monitor_speed = 115200 lib_ldf_mode = deep @@ -21,18 +22,16 @@ lib_deps = https://github.com/ktos/RemoteDebug.git@^3.0.7 tzapu/WiFiManager@^2.0.17 knolleary/PubSubClient@^2.8 - bblanchon/ArduinoJson@^7.1.0 - links2004/WebSockets@^2.3.6 + bblanchon/ArduinoJson@^7.4.2 + ;links2004/WebSockets@^2.7.1 paulstoffregen/Time@^1.6.1 https://github.com/me-no-dev/ESPAsyncWebServer.git extra_scripts = pre:get_version.py post:merge-bin.py - [env:esp32dev] extends = env:spa-base -platform = espressif32 board = esp32dev build_flags = -D RX_PIN=16 @@ -41,15 +40,26 @@ build_flags = -D LED_PIN=2 -D SPA_SERIAL=Serial2 -[env:spa-control-pcb] +[env:espa-v1] extends = env:spa-base -platform = espressif32 board = esp32-s3-devkitc-1 build_flags = -D ARDUINO_USB_CDC_ON_BOOT=1 - -D SPACTRLPCB=1 + -D ESPA_V1=1 -D RX_PIN=16 -D TX_PIN=15 -D EN_PIN=0 - ;-D LED_PIN=14 -D SPA_SERIAL=Serial2 + +[env:espa-v2] +extends = env:spa-base +board = esp32-c6-devkitc-1 +board_build.flash_size = 4MB +board_build.partitions = partitions/espa_v2_partitions.csv +build_flags = +; -D ARDUINO_USB_CDC_ON_BOOT=1 + -D ESPA_V2=1 + -D RX_PIN=19 + -D TX_PIN=20 + -D EN_PIN=9 + -D SPA_SERIAL=Serial2 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1d6ee25..6dc201b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ RemoteDebug Debug; SpaInterface si; Config config; -#if defined(SPACTRLPCB) +#if defined(ESPA_V1) || defined(ESPA_V2) MultiBlinker blinker(PCB_LED1, PCB_LED2, PCB_LED3, PCB_LED4); #elif defined(LED_PIN) MultiBlinker blinker(LED_PIN); From 70bdf661ea34a264d734aecff96e4e2956040faa Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Tue, 21 Oct 2025 13:13:34 +1300 Subject: [PATCH 2/6] Forcing a newer version of the arduino platform for c6 support --- .vscode/extensions.json | 3 +-- platformio.ini | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 080e70d..8057bc7 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,7 +1,6 @@ { - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format "recommendations": [ + "pioarduino.pioarduino-ide", "platformio.platformio-ide" ], "unwantedRecommendations": [ diff --git a/platformio.ini b/platformio.ini index 30c25e2..0b90583 100644 --- a/platformio.ini +++ b/platformio.ini @@ -53,6 +53,7 @@ build_flags = [env:espa-v2] extends = env:spa-base +framework = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip # Forcing a more modern version of the platform board = esp32-c6-devkitc-1 board_build.flash_size = 4MB board_build.partitions = partitions/espa_v2_partitions.csv From 3f74b038e94bbd6a08f31a92636912bc0889336d Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Tue, 21 Oct 2025 13:24:40 +1300 Subject: [PATCH 3/6] Trying to get things building on github actions (and not just my machine) --- .github/workflows/build_firmware.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build_firmware.yml b/.github/workflows/build_firmware.yml index 25f94c6..b834435 100644 --- a/.github/workflows/build_firmware.yml +++ b/.github/workflows/build_firmware.yml @@ -41,6 +41,8 @@ jobs: python-version: "3.x" - name: Install PlatformIO run: pip install platformio + - name: Update PlatformIO + run: pio update - name: Build file system image for ${{ inputs.platform }} run: pio run --target buildfs -e ${{ inputs.platform }} - name: Build for ${{ inputs.platform }} From 36f6629cc7bdd0154721708ba2240ca247f29d90 Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Tue, 21 Oct 2025 13:43:03 +1300 Subject: [PATCH 4/6] another attempt --- platformio.ini | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 0b90583..ccc37d8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -53,8 +53,11 @@ build_flags = [env:espa-v2] extends = env:spa-base -framework = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip # Forcing a more modern version of the platform +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = arduino # Forcing a more modern version of the platform board = esp32-c6-devkitc-1 +; platform_packages = + ; framework-arduinoespressif32 @ https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip board_build.flash_size = 4MB board_build.partitions = partitions/espa_v2_partitions.csv build_flags = From c9fea36c188c62b2f4ebe284410d3c2ef495505d Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Tue, 21 Oct 2025 13:53:20 +1300 Subject: [PATCH 5/6] trying to fix so merge-bin.py succeeds --- partitions/espa_v2_partitions.csv | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/partitions/espa_v2_partitions.csv b/partitions/espa_v2_partitions.csv index 9ae7002..1263780 100644 --- a/partitions/espa_v2_partitions.csv +++ b/partitions/espa_v2_partitions.csv @@ -73,8 +73,7 @@ # - Remaining space: bootloader, alignment padding # # =================================================================== - - +# # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 0x9000, 0x7000, otadata, data, ota, 0x10000, 0x2000, From c0e430943f6131ada6f8dd89eca8b8c5712dceba Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Tue, 21 Oct 2025 13:59:52 +1300 Subject: [PATCH 6/6] tweak merge-bin.py to handle partitions.csv --- merge-bin.py | 23 +++++++++++++++++------ platformio.ini | 6 +++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/merge-bin.py b/merge-bin.py index 3b4e5b2..659ee26 100644 --- a/merge-bin.py +++ b/merge-bin.py @@ -28,12 +28,23 @@ def merge_bin_action(source, target, env): print("fs_image_name: ", fs_image_name) if partition_csv and fs_image_name: - with open(partition_csv, "r") as csvfile: - reader = csv.DictReader(csvfile) - for row in reader: - if row["# Name"] == fs_image_name: - offset = row[" Offset"] - break + # Use skipinitialspace to tolerate fields with leading spaces. + # Be defensive about header names: some CSVs use '# Name' while + # others use 'Name' (and offsets may be 'Offset' or ' Offset'). + try: + with open(partition_csv, "r") as csvfile: + reader = csv.DictReader(csvfile, skipinitialspace=True) + for row in reader: + # Try several possible header names to avoid KeyError + name = (row.get("# Name") or row.get("Name") or row.get("name")) + if name == fs_image_name: + offset = (row.get("Offset") or row.get(" Offset") or row.get("offset") or 0) + if isinstance(offset, str): + offset = offset.strip() + break + except Exception as e: + print("Warning: failed to parse partition CSV:", e) + offset = 0 if offset: flash_images.append(offset) diff --git a/platformio.ini b/platformio.ini index ccc37d8..64538e2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -53,11 +53,11 @@ build_flags = [env:espa-v2] extends = env:spa-base +# Use the pioarduino fork of the espressif32 platform to enable Arduino framework support +# for the ESP32-C6, which is not fully supported in the official PlatformIO 6.12.0 release. platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip -framework = arduino # Forcing a more modern version of the platform +framework = arduino board = esp32-c6-devkitc-1 -; platform_packages = - ; framework-arduinoespressif32 @ https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip board_build.flash_size = 4MB board_build.partitions = partitions/espa_v2_partitions.csv build_flags =