65 lines
2.5 KiB
PowerShell
65 lines
2.5 KiB
PowerShell
|
|
#Requires -Version 5.1
|
||
|
|
<#
|
||
|
|
.SYNOPSIS
|
||
|
|
Build (optional) and flash YNGJ-GT1-M app via IAR cspybat + J-Link.
|
||
|
|
Auto-selects Cortex-M4 and suppresses J-Link device-selection dialogs.
|
||
|
|
#>
|
||
|
|
param(
|
||
|
|
[switch]$NoBuild
|
||
|
|
)
|
||
|
|
|
||
|
|
$ErrorActionPreference = "Stop"
|
||
|
|
$Root = Split-Path -Parent $PSScriptRoot
|
||
|
|
$Ewp = Join-Path $Root "project\IAR_V7.4\YNGJ-GT1-M.ewp"
|
||
|
|
$ExeDir = Join-Path $Root "project\IAR_V7.4\YNGJ-GT1-M\Exe"
|
||
|
|
$Out = Join-Path $ExeDir "YNGJ-GT1-M.out"
|
||
|
|
$Bin = Join-Path $ExeDir "YNGJ-GT1-M.bin"
|
||
|
|
$ToolsDir = Join-Path $Root "tools"
|
||
|
|
$SettingsSrc = Join-Path $ToolsDir "JLinkSettings.ini"
|
||
|
|
$JlinkScript = Join-Path $ToolsDir "jlink_hidedevid.jlink"
|
||
|
|
$GeneralXcl = Join-Path $Root "project\IAR_V7.4\settings\YNGJ-GT1-M.YNGJ-GT1-M.general.xcl"
|
||
|
|
$DriverXcl = Join-Path $Root "project\IAR_V7.4\settings\YNGJ-GT1-M.YNGJ-GT1-M.driver.xcl"
|
||
|
|
$IarBuild = "C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.3\common\bin\IarBuild.exe"
|
||
|
|
$CspyBat = "C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.3\common\bin\cspybat.exe"
|
||
|
|
$TempFlash = "C:\Temp\k1flash"
|
||
|
|
|
||
|
|
# Suppress J-Link unknown-device popup (cwd / AppData / ASCII path for script).
|
||
|
|
New-Item -ItemType Directory -Force -Path $ExeDir, $TempFlash | Out-Null
|
||
|
|
Copy-Item -Force $SettingsSrc (Join-Path $ExeDir "JLinkSettings.ini")
|
||
|
|
Copy-Item -Force $SettingsSrc (Join-Path $TempFlash "JLinkSettings.ini")
|
||
|
|
Copy-Item -Force $JlinkScript (Join-Path $TempFlash "jlink_hidedevid.jlink")
|
||
|
|
$Roaming = Join-Path $env:APPDATA "SEGGER"
|
||
|
|
New-Item -ItemType Directory -Force -Path $Roaming | Out-Null
|
||
|
|
Copy-Item -Force $SettingsSrc (Join-Path $Roaming "JLinkSettings.ini")
|
||
|
|
|
||
|
|
# Stop leftover debug servers that hold the probe.
|
||
|
|
Get-Process -Name CSpyBat, JLinkGUIServer, JLink -ErrorAction SilentlyContinue |
|
||
|
|
Where-Object { $_.ProcessName -match 'CSpyBat|JLinkGUIServer' } |
|
||
|
|
Stop-Process -Force -ErrorAction SilentlyContinue
|
||
|
|
|
||
|
|
if (-not $NoBuild) {
|
||
|
|
Write-Host "Building..."
|
||
|
|
& $IarBuild $Ewp -make YNGJ-GT1-M
|
||
|
|
if ($LASTEXITCODE -ne 0) { throw "IarBuild failed: $LASTEXITCODE" }
|
||
|
|
}
|
||
|
|
|
||
|
|
if (-not (Test-Path $Out)) { throw "Missing $Out" }
|
||
|
|
|
||
|
|
if (Test-Path $Bin) {
|
||
|
|
Copy-Item -Force $Bin (Join-Path $TempFlash "YNGJ-GT1-M.bin")
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Host "Flashing (Cortex-M4, no device dialog)..."
|
||
|
|
Push-Location $ExeDir
|
||
|
|
try {
|
||
|
|
# HideDeviceSelection comes from JLinkSettings.ini + driver.xcl jlink script.
|
||
|
|
& $CspyBat -f $GeneralXcl --download_only --silent --backend -f $DriverXcl
|
||
|
|
$code = $LASTEXITCODE
|
||
|
|
} finally {
|
||
|
|
Pop-Location
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($code -ne 0) { throw "Flash failed: $code" }
|
||
|
|
Write-Host "Flash OK"
|
||
|
|
exit 0
|