Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
with:
path: .tools/arduino
key: ${{ runner.os }}-protected-arduino-1.1.1-${{ matrix.core }}-${{ hashFiles('Build-PulseShift.ps1') }}
restore-keys: |
${{ runner.os }}-protected-arduino-1.1.1-${{ matrix.core }}-

- name: Compile - production firmware (default)
run: pwsh -NoProfile -File ./Build-PulseShift.ps1 -ArduinoCli arduino-cli -CoreVersion '${{ matrix.core }}' -BuildDirectory "$RUNNER_TEMP/build-production"
Expand Down
13 changes: 9 additions & 4 deletions Build-PulseShift.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ param(
[string]$BuildDirectory,
[string]$CacheDirectory,
[string]$ArduinoCli,
[string]$SketchDirectory
[string]$SketchDirectory,
[switch]$Wokwi
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
if ($Wokwi -and $Headless) { throw 'The Wokwi build needs serial diagnostics.' }
$CacheDirectory = if ($CacheDirectory) { $CacheDirectory } else { Join-Path $PSScriptRoot '.tools/arduino' }
$SketchDirectory = if ($SketchDirectory) { $SketchDirectory } else { Join-Path $PSScriptRoot 'PulseShift' }
$cliVersion = '1.1.1'
Expand All @@ -26,7 +28,7 @@ $data = Join-Path $coreCache 'data'
$sketchbook = Join-Path $coreCache 'sketchbook'
$index = 'https://espressif.github.io/arduino-esp32/package_esp32_index.json'
if (!$BuildDirectory) {
$variant = if ($Headless) { 'headless' } else { 'production' }
$variant = if ($Wokwi) { 'wokwi' } elseif ($Headless) { 'headless' } else { 'production' }
$BuildDirectory = Join-Path $PSScriptRoot "build/esp32-$CoreVersion/$variant"
}
$build = [IO.Path]::GetFullPath($BuildDirectory)
Expand Down Expand Up @@ -114,6 +116,7 @@ if (!(Test-Path -LiteralPath $library) -or !(Select-String -LiteralPath $library

$defines = '-DPULSESHIFT_PROTECTED_BUILD=1'
if ($Headless) { $defines += ' -DPULSESHIFT_SERIAL_DIAGNOSTICS=0' }
if ($Wokwi) { $defines += ' -DPULSESHIFT_BLE_ENABLED=0 -DPULSESHIFT_OTA_ENABLED=0' }
$compile = @('compile', '--fqbn', 'esp32:esp32:esp32doit-devkit-v1', '--build-path', $build,
'--build-property', "compiler.cpp.extra_flags=$defines",
'--build-property', 'compiler.c.elf.extra_flags=-Wl,--wrap=nvs_flash_init')
Expand Down Expand Up @@ -154,7 +157,7 @@ if ($bytes.Length -lt 65536 -or $bytes.Length + 76 -gt 0x140000 -or
throw 'The build did not produce a classic ESP32 application that fits the signed OTA slot.'
}

[ordered]@{
$verification = [ordered]@{
arduinoCli = $cliVersion
esp32Core = $CoreVersion
nimble = $nimble
Expand All @@ -168,5 +171,7 @@ if ($bytes.Length -lt 65536 -or $bytes.Length + 76 -gt 0x140000 -or
applicationBytes = $bytes.Length
signedPackageBytes = $bytes.Length + 76
slotBytes = 0x140000
} | ConvertTo-Json | Set-Content -LiteralPath $reportPath -Encoding UTF8
}
if ($Wokwi) { $verification['wokwi'] = $true }
$verification | ConvertTo-Json | Set-Content -LiteralPath $reportPath -Encoding UTF8
Write-Host "Build and protection checks passed. Application: $app"
29 changes: 29 additions & 0 deletions PulseShift.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@
},
"group": { "kind": "build", "isDefault": true },
"problemMatcher": "$gcc"
},
{
"label": "PulseShift: Build Wokwi simulator",
"type": "process",
"command": "pwsh",
"args": [
"-NoProfile",
"-File",
"${workspaceFolder:PulseShift Firmware}/Build-PulseShift.ps1",
"-ArduinoCli",
"arduino-cli",
"-Wokwi"
],
"windows": {
"command": "powershell.exe",
"args": [
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-File",
"${workspaceFolder:PulseShift Firmware}/Build-PulseShift.ps1",
"-Wokwi"
]
},
"options": {
"cwd": "${workspaceFolder:PulseShift Firmware}"
},
"group": "build",
"problemMatcher": "$gcc"
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions PulseShift/src/ble_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ bool BleManager::isConfigSnapshotSubscribed() const {
#endif
}

bool BleManager::isEnabled() const {
return config::bleEnabled && initialized_;
}

bool BleManager::isAdvertising() const {
#if defined(ARDUINO) && defined(PULSESHIFT_BLE_ENABLED) && (PULSESHIFT_BLE_ENABLED == 1)
if (!initialized_) return false;
Expand Down
2 changes: 1 addition & 1 deletion PulseShift/src/ble_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BleManager {
bool isLogsSubscribed() const;
bool isConfigResultSubscribed() const;
bool isConfigSnapshotSubscribed() const;
bool isEnabled() const { return initialized_; }
bool isEnabled() const;
bool isAdvertising() const;

// Called by Application::tick() on the same loop task after poll(). A BLE
Expand Down
7 changes: 4 additions & 3 deletions docs/WINDOWS-BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ Arduino IDE can edit the sketch and monitor a supported diagnostic build at 1152
## VS Code and Wokwi

1. Open [PulseShift.code-workspace](../PulseShift.code-workspace) in VS Code. Run **Tasks: Run Task** and select **PulseShift: Protected ESP32 build**. On Windows, **ESP-IDF: Execute Custom Task** is an alternative that runs the same build with the installed Espressif extension.
2. Run **Wokwi: Start Simulator**. [wokwi.toml](../wokwi.toml) selects the merged 4 MiB image and matching ELF in `build/esp32-3.3.12/production`. The simulator boots the project partition table and uses the same GPIO27 output and six WS2812B pixels as the default hardware configuration. [Wokwi full-image configuration](https://docs.wokwi.com/vscode/project-config#esp32-application-image-vs-full-image)
3. Enter `STATUS` or `LED STATUS` in the simulator serial monitor to inspect watchdog, flash, CAN and LED state. Use `RPM TEST 6000` to exercise the built-in serial LED bench mode. For device-side OTA or live CAN and BLE verification, use the [hardware bench plan](OTA-BENCH-TEST-PLAN.md).
2. Select **PulseShift: Build Wokwi simulator**, or run `./Build-PulseShift.cmd -Wokwi` on Windows. The profile keeps the protected build, serial console, GPIO27, six default WS2812B pixels and project partition table. It disables BLE and OTA because Wokwi does not emulate Bluetooth. Its outputs in `build/esp32-3.3.12/wokwi` are for simulation. Use the production build for hardware and OTA. [Wokwi ESP32 simulation features](https://docs.wokwi.com/guides/esp32#simulation-features)
3. Run **Wokwi: Start Simulator**. [wokwi.toml](../wokwi.toml) selects the merged 4 MiB flash image and matching ELF from the Wokwi build. The extension may require an active [Wokwi license](https://docs.wokwi.com/vscode/getting-started#installation).
4. Enter `STATUS` or `LED STATUS` in the simulator serial monitor. Use `RPM TEST 6000` to exercise the built-in serial LED bench mode. The diagram leaves the CAN pins disconnected, and a blank simulator flash may report that LittleFS needs provisioning. For device-side OTA or live CAN and BLE verification, use the [hardware bench plan](OTA-BENCH-TEST-PLAN.md).

The firmware is an Arduino CLI sketch. Use the protected task for compilation, including when the ESP-IDF extension is installed. The ESP-IDF CMake build and flash actions target native ESP-IDF projects. Wokwi may require a [local extension license](https://docs.wokwi.com/vscode/getting-started#installation). The diagram leaves GPIO16 and GPIO17 disconnected from an external CAN node.
The firmware is an Arduino CLI sketch. Use the protected task for compilation, including when the ESP-IDF extension is installed. The ESP-IDF CMake build and flash actions target native ESP-IDF projects.

## First-time USB install on a new board

Expand Down
6 changes: 6 additions & 0 deletions test/test_ota_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def test_tag_layout_and_key_must_match(self):
with self.assertRaisesRegex(ValueError, "partition table"):
self.prepare()

def test_rejects_simulator_builds_before_signing(self):
self.app.with_name("build-verification.json").write_text('{"wokwi": true}', encoding="utf-8-sig")
with self.assertRaisesRegex(ValueError, "Wokwi simulator firmware"):
self.prepare()
self.assertFalse(self.output.exists())

def test_rejects_non_application_artifacts(self):
self.app.write_bytes(b"PK\x03\x04" + bytes(65536))
with self.assertRaisesRegex(ValueError, "application-only"):
Expand Down
5 changes: 5 additions & 0 deletions tools/ota_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def prepare(app, partitions, notes, tag, source, private_key, output):
version = source_version()
if not valid_version(version) or tag != f"v{version}" or not re.fullmatch(r"[0-9a-f]{40}", source):
raise ValueError("Tag must match the stable firmware source version and include its commit SHA")
report = app.with_name("build-verification.json")
if report.is_file():
metadata = json.loads(report.read_text(encoding="utf-8-sig"))
if isinstance(metadata, dict) and metadata.get("wokwi") is True:
raise ValueError("Wokwi simulator firmware cannot be packaged for OTA")
check_layout(partitions)
check_app(app.read_bytes())
release_notes = notes.read_text(encoding="utf-8").strip()
Expand Down
4 changes: 2 additions & 2 deletions wokwi.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[wokwi]
version = 1
firmware = 'build/esp32-3.3.12/production/PulseShift.ino.merged.bin'
elf = 'build/esp32-3.3.12/production/PulseShift.ino.elf'
firmware = 'build/esp32-3.3.12/wokwi/PulseShift.ino.merged.bin'
elf = 'build/esp32-3.3.12/wokwi/PulseShift.ino.elf'
Loading