- Add setup_framework.bat for classic Windows batch support - Add setup_framework.ps1 for PowerShell with better error handling - Both scripts handle STM32WL LoRaMAC-Node framework conflicts
113 lines
4.1 KiB
PowerShell
113 lines
4.1 KiB
PowerShell
# PowerShell script to setup framework modifications for STM32WL LoRaWAN project
|
|
# Usage: .\setup_framework.ps1
|
|
|
|
Write-Host "Setting up framework modifications for STM32WL LoRaWAN build..." -ForegroundColor Cyan
|
|
|
|
# Find PlatformIO packages directory
|
|
$PIO_PACKAGES = "$env:USERPROFILE\.platformio\packages"
|
|
$FRAMEWORK_ZEPHYR = "$PIO_PACKAGES\framework-zephyr"
|
|
$LORAMAC_NODE = "$FRAMEWORK_ZEPHYR\_pio\modules\lib\loramac-node"
|
|
|
|
Write-Host "PlatformIO packages: $PIO_PACKAGES"
|
|
Write-Host "Framework Zephyr: $FRAMEWORK_ZEPHYR"
|
|
|
|
# Check if framework exists
|
|
if (-not (Test-Path $FRAMEWORK_ZEPHYR)) {
|
|
Write-Host "Error: Zephyr framework not found at $FRAMEWORK_ZEPHYR" -ForegroundColor Red
|
|
Write-Host "Please run 'pio run' first to download the framework" -ForegroundColor Yellow
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
|
|
if (-not (Test-Path $LORAMAC_NODE)) {
|
|
Write-Host "Error: LoRaMAC-Node not found at $LORAMAC_NODE" -ForegroundColor Red
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "✓ Framework directories found" -ForegroundColor Green
|
|
|
|
# 1. Remove conflicting sx126x.c from LoRaMAC-Node
|
|
$CONFLICTING_FILE = "$LORAMAC_NODE\src\radio\sx126x\sx126x.c"
|
|
if (Test-Path $CONFLICTING_FILE) {
|
|
Write-Host "Removing conflicting sx126x.c..."
|
|
Remove-Item $CONFLICTING_FILE -Force
|
|
Write-Host "✓ Removed $CONFLICTING_FILE" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "✓ sx126x.c already removed" -ForegroundColor Green
|
|
}
|
|
|
|
# 2. Create radio_sx126x.c from original sx126x.c
|
|
$RADIO_SX126X = "$LORAMAC_NODE\src\radio\sx126x\radio_sx126x.c"
|
|
if (-not (Test-Path $RADIO_SX126X)) {
|
|
Write-Host "Creating radio_sx126x.c from git repository..."
|
|
Push-Location $LORAMAC_NODE
|
|
try {
|
|
$gitOutput = git show HEAD:src/radio/sx126x/sx126x.c 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
$gitOutput | Out-File -FilePath "src\radio\sx126x\radio_sx126x.c" -Encoding utf8
|
|
Write-Host "✓ Created radio_sx126x.c" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Error: Failed to create radio_sx126x.c from git" -ForegroundColor Red
|
|
Write-Host "Please ensure git is available and LoRaMAC-Node is a git repository" -ForegroundColor Yellow
|
|
Pop-Location
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
} finally {
|
|
Pop-Location
|
|
}
|
|
} else {
|
|
Write-Host "✓ radio_sx126x.c already exists" -ForegroundColor Green
|
|
}
|
|
|
|
# 3. Update CMakeLists.txt
|
|
$CMAKE_FILE = "$FRAMEWORK_ZEPHYR\modules\loramac-node\CMakeLists.txt"
|
|
Write-Host "Updating CMakeLists.txt..."
|
|
|
|
# Create backup
|
|
Copy-Item $CMAKE_FILE "$CMAKE_FILE.backup" -Force
|
|
|
|
try {
|
|
$content = Get-Content $CMAKE_FILE
|
|
$newContent = @()
|
|
$inSection = $false
|
|
|
|
foreach ($line in $content) {
|
|
if ($line -match 'zephyr_library_sources_ifdef\(CONFIG_HAS_SEMTECH_SX126X') {
|
|
$newContent += $line
|
|
$newContent += ' ${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio/sx126x/radio.c'
|
|
$newContent += ' ${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio/sx126x/radio_sx126x.c'
|
|
$inSection = $true
|
|
} elseif ($inSection -and $line -match '^\)') {
|
|
$newContent += $line
|
|
$inSection = $false
|
|
} elseif (-not $inSection) {
|
|
$newContent += $line
|
|
}
|
|
}
|
|
|
|
$newContent | Set-Content $CMAKE_FILE -Encoding utf8
|
|
Write-Host "✓ Updated $CMAKE_FILE" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "Error: Failed to update CMakeLists.txt - $_" -ForegroundColor Red
|
|
Read-Host "Press Enter to exit"
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "🎉 Framework setup complete!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "Summary of changes:"
|
|
Write-Host " - Removed: $CONFLICTING_FILE"
|
|
Write-Host " - Created: $RADIO_SX126X"
|
|
Write-Host " - Updated: $CMAKE_FILE"
|
|
Write-Host ""
|
|
Write-Host "You can now run 'pio run' to build the project." -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "To restore original framework:"
|
|
Write-Host " git restore `"$CONFLICTING_FILE`""
|
|
Write-Host " Remove-Item `"$RADIO_SX126X`""
|
|
Write-Host " Move-Item `"$CMAKE_FILE.backup`" `"$CMAKE_FILE`""
|
|
|
|
Read-Host "Press Enter to exit" |