Merge pull request #363 from curliph/master

add Gowin programmer support
This commit is contained in:
enjoy-digital 2022-03-08 17:26:50 +01:00 committed by GitHub
commit 3b74673a93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View file

@ -8,8 +8,10 @@ from migen import *
from litex.build.generic_platform import *
from litex.build.gowin.platform import GowinPlatform
from litex.build.gowin.programmer import GowinProgrammer
from litex.build.openfpgaloader import OpenFPGALoader
# IOs ----------------------------------------------------------------------------------------------
_io = [
@ -78,8 +80,11 @@ class Platform(GowinPlatform):
GowinPlatform.__init__(self, "GW1NR-LV9QN88PC6/I5", _io, _connectors, toolchain=toolchain, devicename="GW1NR-9C")
self.toolchain.options["use_mspi_as_gpio"] = 1
def create_programmer(self):
return OpenFPGALoader(cable="ft2232")
def create_programmer(self, kit="openfpgaloader"):
if kit == "gowin":
return GowinProgrammer(self.devicename)
else:
return OpenFPGALoader(cable="ft2232")
def do_finalize(self, fragment):
GowinPlatform.do_finalize(self, fragment)

View file

@ -115,6 +115,7 @@ def main():
parser.add_argument("--sys-clk-freq",default=27e6, help="System clock frequency.")
parser.add_argument("--bios-flash-offset", default="0x0", help="BIOS offset in SPI Flash.")
parser.add_argument("--with-spi-sdcard", action="store_true", help="Enable SPI-mode SDCard support.")
parser.add_argument("--prog-kit", default="openfpgaloader", help="Programmer select from Gowin/openFPGALoader.")
builder_args(parser)
soc_core_args(parser)
args = parser.parse_args()
@ -132,13 +133,16 @@ def main():
builder.build(run=args.build)
if args.load:
prog = soc.platform.create_programmer()
prog = soc.platform.create_programmer(kit=args.prog_kit)
prog.load_bitstream(os.path.join(builder.gateware_dir, "impl", "pnr", "project.fs"))
if args.flash:
prog = soc.platform.create_programmer()
prog = soc.platform.create_programmer(kit=args.prog_kit)
prog.flash(0, os.path.join(builder.gateware_dir, "impl", "pnr", "project.fs"))
prog.flash(int(args.bios_flash_offset, 0), "build/sipeed_tang_nano_9k/software/bios/bios.bin", external=True)
# external SPI programming not supported by gowin 'programmer_cli' now!
# if needed, use openFPGALoader or Gowin programmer GUI
if args.prog_kit == "openfpgaloader":
prog.flash(int(args.bios_flash_offset, 0), os.path.join(builder.software_dir, "bios", "bios.bin"), external=True)
if __name__ == "__main__":
main()