Files
BL616-firmware/scripts/flash.ps1
T
Gromov_IA 8bc1583805 Прошивка моста BL616 для Tang Primer 25K и программатор TangProgrammer
- src/: прошивка встроенного отладчика BL616 — составное USB-устройство
  1209:C0CA: DirtyJTAG v3 (WinUSB через MS OS 2.0) + CDC-ACM UART к FPGA
  B3/C3; UART до 20 Мбод на DMA, JTAG до 30 МГц через аппаратный SPI;
- bin/: загрузчик Sipeed (0x0) и штатная прошивка 2025030317 для отката;
- gui/: TangProgrammer.exe (C# WinForms, .NET Framework 4) — загрузка FPGA
  в SRAM и во флеш-память, копия и стирание флеш-памяти FPGA, прошивка
  моста; светлая и тёмная тема;
- scripts/: setup, build, flash, build_gui, make_portable, а также
  make_release и publish_release для релизов Gitea;
- fpga_test/, tests/: тестовые проекты Gowin (loopback, stream) и тесты
  UART на Python;
- tools/openFPGALoader/: openFPGALoader 1.1.1 для Windows x64.
2026-10-02 14:59:10 +03:00

73 lines
2.7 KiB
PowerShell

# Flash the BL616 on the Tang Primer 25K Dock.
#
# .\scripts\flash.ps1 this firmware (Sipeed loader @0x0 + firmware @0x20000)
# .\scripts\flash.ps1 -Restore original Sipeed debugger firmware
#
# The BL616 has to be in its ROM USB bootloader ("Bouffalo CDC DEMO"). The
# script gets it there by itself when this firmware is already running
# (serial port opened at 1234 baud). Otherwise, unplug the board and plug it
# back while either
# - holding the S3 button (this firmware is installed), or
# - shorting the TDO test point to 3V3 (bottom side, always works).
param(
[switch]$Restore,
[string]$Port
)
$ErrorActionPreference = 'Stop'
. (Join-Path $PSScriptRoot 'common.ps1')
$root = Get-ProjectRoot
$sdk = Join-Path $root 'third_party\bouffalo_sdk'
$tool = Join-Path $sdk 'tools\bflb_tools\bouffalo_flash_cube\BLFlashCommand.exe'
$cfg = if ($Restore) { 'restore_prog_cfg.ini' } else { 'flash_prog_cfg.ini' }
if (-not $Restore -and -not (Test-Path (Join-Path $root 'build\build_out\tang25k_debugger_bl616.bin'))) {
throw 'firmware not built yet: run scripts\build.ps1'
}
function Wait-BootromPort([int]$Seconds) {
$deadline = (Get-Date).AddSeconds($Seconds)
do {
$p = @(Find-ComPort $BootromPortId)
if ($p.Count) { return $p[0] }
Start-Sleep -Milliseconds 300
} while ((Get-Date) -lt $deadline)
return $null
}
if (-not $Port) {
$Port = @(Find-ComPort $BootromPortId) | Select-Object -First 1
}
if (-not $Port) {
$fw = @(Find-ComPort $FirmwarePortId) | Select-Object -First 1
if ($fw) {
Write-Host "Firmware found on $fw, rebooting it into the ROM bootloader..."
try {
$sp = New-Object System.IO.Ports.SerialPort $fw, 1234
$sp.Open()
Start-Sleep -Milliseconds 200
$sp.Close()
} catch {
Write-Warning "could not open ${fw}: $_ (is a terminal using it?)"
}
$Port = Wait-BootromPort 15
}
}
if (-not $Port) {
Write-Host 'Waiting for the BL616 ROM bootloader (Bouffalo CDC DEMO)...' -ForegroundColor Yellow
Write-Host ' unplug the board, then plug it back while holding S3'
Write-Host ' (or while shorting the TDO test point to 3V3 on the bottom side)'
$Port = Wait-BootromPort 120
}
if (-not $Port) { throw 'BL616 bootloader port not found' }
Write-Host "Flashing $cfg via $Port" -ForegroundColor Cyan
Push-Location $root
try {
& $tool --interface=uart --baudrate=2000000 --port=$Port --chipname=bl616 --cpu_id= --config=$cfg
if ($LASTEXITCODE) { throw "BLFlashCommand failed ($LASTEXITCODE)" }
} finally {
Pop-Location
}
Write-Host 'Done. Unplug and plug the board back (power cycle) to start the new firmware.' -ForegroundColor Green