Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand All @@ -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
Expand Down
62 changes: 62 additions & 0 deletions tools/set_version.py
Original file line number Diff line number Diff line change
@@ -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})")
5 changes: 4 additions & 1 deletion variants/rak3112/RAK3112Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion variants/rak3112/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading