From fed12bf3c87d2ee83fd7c07a0ddf203bd88919d9 Mon Sep 17 00:00:00 2001 From: Jara Date: Tue, 16 Jun 2026 19:48:18 +0200 Subject: [PATCH] Rak 3v3 Rail ON --- platformio.ini | 10 ++++-- tools/set_version.py | 62 +++++++++++++++++++++++++++++++++ variants/rak3112/RAK3112Board.h | 5 ++- variants/rak3112/platformio.ini | 4 ++- 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 tools/set_version.py diff --git a/platformio.ini b/platformio.ini index 8e415c5e52..82bf289b6d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -68,6 +68,7 @@ extends = arduino_base platform = platformio/espressif32@6.11.0 monitor_filters = esp32_exception_decoder extra_scripts = + pre:tools/set_version.py pre:tools/firmware_target.py merge-bin.py build_flags = ${arduino_base.build_flags} @@ -96,7 +97,9 @@ platform_packages = ; https://github.com/meshcore-dev/MeshCore/pull/1177 ; https://github.com/meshcore-dev/MeshCore/pull/1295 framework-arduinoadafruitnrf52 @ https://github.com/meshcore-dev/Adafruit_nRF52_Arduino#d541301 -extra_scripts = create-uf2.py +extra_scripts = + pre:tools/set_version.py + create-uf2.py build_flags = ${arduino_base.build_flags} -D NRF52_PLATFORM -D LFS_NO_ASSERT=1 @@ -111,6 +114,7 @@ extends = arduino_base upload_protocol = picotool board_build.core = earlephilhower platform = https://github.com/maxgerhardt/platform-raspberrypi.git#4e22a0d ; framework-arduinopico @ 1.50600.0+sha.6a1d13e9 +extra_scripts = pre:tools/set_version.py build_flags = ${arduino_base.build_flags} -D RP2040_PLATFORM lib_ignore = @@ -121,7 +125,9 @@ lib_ignore = [stm32_base] extends = arduino_base platform = ststm32 -extra_scripts = post:arch/stm32/build_hex.py +extra_scripts = + pre:tools/set_version.py + post:arch/stm32/build_hex.py build_flags = ${arduino_base.build_flags} -D STM32_PLATFORM -I src/helpers/stm32 diff --git a/tools/set_version.py b/tools/set_version.py new file mode 100644 index 0000000000..e99474127b --- /dev/null +++ b/tools/set_version.py @@ -0,0 +1,62 @@ +#!/usr/bin/python3 +""" +PlatformIO pre-build script to automatically set firmware version and build date. +Generates version string like "v1.0.12-70f39d3" from git describe + commit hash. +""" + +import subprocess +import datetime +import os + +Import("env") + +def get_git_version(): + """Get version from git tags or fallback to commit hash""" + try: + # Try to get version from git tag (e.g., v1.0.12) + version = subprocess.check_output( + ['git', 'describe', '--tags', '--abbrev=0'], + stderr=subprocess.DEVNULL + ).decode('utf-8').strip() + except (subprocess.CalledProcessError, FileNotFoundError): + # Fallback if no tags exist + version = "v0.0.0" + + return version + +def get_git_commit_hash(): + """Get short commit hash""" + try: + commit_hash = subprocess.check_output( + ['git', 'rev-parse', '--short', 'HEAD'], + stderr=subprocess.DEVNULL + ).decode('utf-8').strip() + except (subprocess.CalledProcessError, FileNotFoundError): + commit_hash = "unknown" + + return commit_hash + +def get_build_date(): + """Get current date in format: 16-Jun-2026""" + return datetime.datetime.now().strftime('%d-%b-%Y') + +# Check if environment variable overrides exist +firmware_version = os.environ.get("FIRMWARE_VERSION") +firmware_build_date = os.environ.get("FIRMWARE_BUILD_DATE") + +# Generate version info if not provided by environment +if not firmware_version: + version = get_git_version() + commit_hash = get_git_commit_hash() + firmware_version = f"{version}-{commit_hash}" + +if not firmware_build_date: + firmware_build_date = get_build_date() + +# Add defines to build +env.Append(CPPDEFINES=[ + ("FIRMWARE_VERSION", f'\\"\\"{firmware_version}\\"\\""'), + ("FIRMWARE_BUILD_DATE", f'\\"\\"{firmware_build_date}\\"\\""') +]) + +print(f"Building with version: {firmware_version} ({firmware_build_date})") diff --git a/variants/rak3112/RAK3112Board.h b/variants/rak3112/RAK3112Board.h index 8ba3197cf6..4d8bd913db 100644 --- a/variants/rak3112/RAK3112Board.h +++ b/variants/rak3112/RAK3112Board.h @@ -25,7 +25,7 @@ class RAK3112Board : public ESP32Board { public: RefCountedDigitalPin periph_power; - RAK3112Board() : periph_power(PIN_VEXT_EN) { } + RAK3112Board() : periph_power(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE) { } void begin() { ESP32Board::begin(); @@ -38,6 +38,9 @@ class RAK3112Board : public ESP32Board { digitalWrite(PIN_ADC_CTRL, !adc_active_state); // Initially inactive periph_power.begin(); +#ifdef ENABLE_PERIPH_POWER_ON_BOOT + periph_power.claim(); // Turn on 3.3V rail for RTC, sensors, and baseboard peripherals +#endif esp_reset_reason_t reason = esp_reset_reason(); if (reason == ESP_RST_DEEPSLEEP) { diff --git a/variants/rak3112/platformio.ini b/variants/rak3112/platformio.ini index 75044941fe..317f7d677c 100644 --- a/variants/rak3112/platformio.ini +++ b/variants/rak3112/platformio.ini @@ -19,9 +19,11 @@ build_flags = -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper -D LORA_TX_POWER=22 - -D P_LORA_TX_LED=46 + -D P_LORA_TX_LED=-1 ; Disable TX LED to save power (can be re-enabled if desired) -D PIN_BOARD_SDA=9 -D PIN_BOARD_SCL=40 + -D PIN_VEXT_EN_ACTIVE=HIGH + -D ENABLE_PERIPH_POWER_ON_BOOT=1 -D PIN_USER_BTN=-1 -D PIN_VEXT_EN=14 -D SX126X_DIO2_AS_RF_SWITCH=true