Flashing now working successfully (Ta! Wolfgang!)

master
kaqu 2 years ago
parent 6dd830daa5
commit 1d9a0460ec
  1. BIN
      helpers/__pycache__/bit_to_flash.cpython-38.pyc
  2. BIN
      helpers/__pycache__/load_to_flash.cpython-38.pyc
  3. 58
      helpers/bit_to_flash.py
  4. 19
      helpers/remotetest.py
  5. 10
      neopixelar.py

@ -10,9 +10,9 @@
import os
import sys
import textwrap
import datetime
flash_page_size = 256
erase_block_size = 64*1024
# Very basic bitstream to SVF converter, tested with the ULX3S WiFi interface
def bitreverse(x):
y = 0
@ -21,8 +21,8 @@ def bitreverse(x):
y |= (1 << i)
return y
def bit2svf(bitfilename, svffilename):
with open(bitfilename, 'rb') as bitf:
def convertBitToFlashFile(bitFile, FlashFile, flash_page_size = 256, address = 0, erase_block_size = 64*1024):
with open(bitFile, 'rb') as bitf:
bs = bitf.read()
# Autodetect IDCODE from bitstream
idcode_cmd = bytes([0xE2, 0x00, 0x00, 0x00])
@ -40,11 +40,11 @@ def bit2svf(bitfilename, svffilename):
print("IDCODE in bitstream is 0x%08x" % idcode)
bitf.seek(0)
address = 0
last_page = -1
with open(svffilename, 'w') as svf:
print("""
with open(FlashFile, 'w') as svf:
now = datetime.datetime.now()
print(f"""// generated {now:%Y-%m-%d %H:%M}
STATE RESET;
HDR 0;
HIR 0;
@ -53,17 +53,17 @@ TIR 0;
ENDDR DRPAUSE;
ENDIR IRPAUSE;
STATE IDLE;
""", file=svf)
""", file=svf)
print("""
SIR 8 TDI (E0);
SDR 32 TDI (00000000)
TDO ({:08X})
MASK (FFFFFFFF);
""".format(idcode), file=svf)
""".format(idcode), file=svf)
print("""
SIR 8 TDI (1C);
SDR 510 TDI (3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
// Enter Programming mode
SIR 8 TDI (C6);
@ -92,54 +92,48 @@ RUNTEST 32 TCK;
RUNTEST 2.00E-2 SEC;
// Enter SPI mode
SIR 8 TDI (3A);
SDR 16 TDI (68FE);
STATE IDLE;
RUNTEST 32 TCK;
RUNTEST 2.00E-2 SEC;
// SPI IO
// SPI IO (CMD 0xAB release Power Down???)
SDR 8 TDI (D5);
RUNTEST 2.00E-0 SEC;
// CONFIRM FLASH ID
!SDR 32 TDI (000000F9)
! TDO (68FFFFFF)
! MASK (FF000000);
!SDR 8 TDI(60);
!SDR 16 TDI(0080);
!RUNTEST 1.00E-0 SEC;
// CONFIRM FLASH ID (CMD 0x9f JEDEC Flash Id -> Size must be 0x16)
SDR 32 TDI (000000F9)
TDO (68FFFFFF)
MASK (FF000000);
// CMD 0x06 Write Enable + 0x01 Write 0x00 to Status Register
SDR 8 TDI(60);
SDR 16 TDI(0080);
RUNTEST 1.00E-0 SEC;
""", file=svf)
while True:
if((address // 0x10000) != last_page):
last_page = (address // 0x10000)
print("""SDR 8 TDI (60);
""", file=svf)
print(f"// CMD 0x06 Write Enable + 0xd8 Erase 64K at 0x{address:x}", file=svf)
print("SDR 8 TDI (60);", file=svf)
address_flipped = [bitreverse(x) for x in [0xd8,int(address // 0x10000),0x00,0x00]]
hex_address= ["{:02X}".format(x) for x in reversed(address_flipped)]
print("\n".join(textwrap.wrap("SDR {} TDI ({});".format(8*len(hex_address), "".join(hex_address)), 100)), file=svf)
print("""RUNTEST 3.00 SEC;
""", file=svf)
print("RUNTEST 3.00 SEC;\n", file=svf)
chunk = bitf.read(flash_page_size)
if not chunk:
break
# Convert chunk to bit-reversed hex
print(f"// CMD 0x06 Write Enable + 0x02 Write Chunk to 0x{address:x}", file=svf)
br_chunk = [bitreverse(x) for x in bytes([0x02, int(address / 0x10000 % 0x100),int(address / 0x100 % 0x100),int(address % 0x100)]) + chunk]
address += len(chunk)
hex_chunk = ["{:02X}".format(x) for x in reversed(br_chunk)]
print("""
SDR 8 TDI (60);
""", file=svf)
print("SDR 8 TDI (60);", file=svf)
print("\n".join(textwrap.wrap("SDR {} TDI ({});".format(8*len(br_chunk), "".join(hex_chunk)), 100)), file=svf)
print("""
RUNTEST 2.50E-2 SEC;
""", file=svf)
print("RUNTEST 2.50E-2 SEC;\n", file=svf)
print("""
// BYPASS
@ -163,4 +157,4 @@ if __name__ == "__main__":
relpath = "."
filename = relpath + "/build/colorlight_5a_75b/gateware/colorlight_5a_75b"
print(f"Translating {filename}.bit to {filename}.svf.flash")
bit2svf(filename + ".bit", filename + ".svf.flash")
convertBitToFlashFile(filename + ".bit", filename + ".svf.flash")

@ -2,7 +2,8 @@
#
# remotetest.py
# Test remote access to NeoPixelar
# Test remote access to NeoPixelar (start from project root)
# Requires litex server running (~/fpga/bin/lxserver --udp --udp-ip=192.168.1.20)
#
# History:
# --------
@ -18,7 +19,7 @@ def test(csr_csv):
wb.open() # to remote client
print("NeoPixel on & off test: ")
for i in range(10):
for i in range(30):
print(".",end="")
#You may add manually: ~/fpga/litex/litex/litex/tools/remote/csr_builder.py
# def writearray(self, value): #21.09.20/KQ
@ -26,12 +27,14 @@ def test(csr_csv):
# raise KeyError(self.name + "register not writable")
# self.writefn(self.addr, value)
# From build/csr.csv we know:
#csr_register,npe_b24Data2Load,0x82004000,3,rw
#csr_register,npe_b8LoadOffset,0x8200400c,1,rw
#csr_register,npe_b8Len,0x82004010,1,rw
#csr_register,npe_bEnable,0x82004014,1,rw
for j in range(0,27,3):
# From build/csr.csv we know:
# csr_register,npe_b24Data2Load,0x82004000,3,rw
# csr_register,npe_b8LoadOffset,0x8200400c,1,rw
# csr_register,npe_b4LoadTable,0x82004010,1,rw
# csr_register,npe_b8Len,0x82004014,1,rw
# csr_register,npe_bEnable,0x82004018,1,rw
wb.regs.npe_b4LoadTable.write(0) # Preselect 1st strip
for j in range(0,27,3):
wb.regs.npe_b8LoadOffset.write(j) # @Offset 0
wb.regs.npe_b24Data2Load.write(0x100000) # G
wb.regs.npe_b8LoadOffset.write(j+1) # @Offset 0

@ -376,6 +376,12 @@ def main():
sdram_rate = args.sdram_rate,
**soc_core_argdict(args))
# 32MBit SPIFlash ---------------------------------------------------------------------------------
soc.mem_map["spiflash"] = 0xc0000000
# Boot at +1MB
soc.add_constant("FLASH_BOOT_ADDRESS", soc.mem_map["spiflash"] + 1024*1024)
soc.add_spi_flash(name="spiflash", mode="1x", dummy_cycles=8, clk_freq=5e6)
builder = Builder(soc, **builder_argdict(args))
builder.build(**trellis_argdict(args), run=args.build) # Written here to (local) build tree
@ -392,8 +398,8 @@ def main():
if args.flash: # Convert Bit File to Jtag Write Flash command
name = os.path.join(builder.gateware_dir, soc.build_name)
print(f"Executing ./bit_to_flash.py {name}.bit {name}.svf.flash")
from helpers.bit_to_flash import bit2svf
bit2svf(name + ".bit", name + ".svf.flash")
from helpers.bit_to_flash import convertBitToFlashFile
convertBitToFlashFile(name + ".bit", name + ".svf.flash")
from helpers.load_to_flash import load2flash
load2flash(name + ".svf.flash")
return

Loading…
Cancel
Save