gf_002/flash_atiny13.ps1

55 lines
1.5 KiB
PowerShell

# PowerShell script to flash a precompiled HEX file via avrdude.exe with a USBasp programmer
# Path to avrdude.exe
# $AvrdudePath = "C:\path\to\avrdude.exe"
$AvrdudePath = "avrdude.exe"
# Path to the USBasp configuration file (avrdude.conf)
$AvrdudeConf = "avrdude.conf"
# Path to the HEX file to be flashed
$HexFile = "pre_built\atiny13_4-8.hex"
# USBasp programmer options
$ProgrammerOptions = "-c usbasp"
# Microcontroller options (replace with the appropriate values for your microcontroller)
$MCU = "-p attiny13"
$BaudRate = "-B 10"
# Check if avrdude.exe exists
if (-not (Test-Path $AvrdudePath -PathType Leaf)) {
Write-Error "Error: avrdude.exe not found. Please set AvrdudePath in the script."
exit 1
}
# Check if the avrdude configuration file exists
if (-not (Test-Path $AvrdudeConf -PathType Leaf)) {
Write-Error "Error: avrdude.conf not found. Please set AvrdudeConf in the script."
exit 1
}
# Check if the HEX file exists
if (-not (Test-Path $HexFile -PathType Leaf)) {
Write-Error "Error: HEX file not found. Please set HexFile in the script."
exit 1
}
# Build avrdude command
$AvrdudeCommand = "$AvrdudePath -C $AvrdudeConf $ProgrammerOptions $MCU $BaudRate -U flash:w:$HexFile"
# Run avrdude command
Write-Host "Flashing HEX file..."
Invoke-Expression $AvrdudeCommand
# Check avrdude exit code
if ($LASTEXITCODE -eq 0) {
Write-Host "Flashing completed successfully."
} else {
Write-Host "Flashing failed. Check avrdude output for details."
}
# Exit with avrdude exit code
exit $LASTEXITCODE