Browse Source

Add CircuitPython ECP5Prog

master
Konrad Beckmann 2 years ago
parent
commit
398ab87911
2 changed files with 44 additions and 0 deletions
  1. +14
    -0
      python/code.py
  2. +30
    -0
      python/ecp5prog.py

+ 14
- 0
python/code.py View File

@ -0,0 +1,14 @@
import board
import busio
import time
from ecp5prog import ECP5Prog
fpga_spi = busio.SPI(board.D1, board.D0)
prog = ECP5Prog(fpga_spi)
start = time.monotonic()
prog.write_file('gateware.bit')
end = time.monotonic()
print('programming took %fms' % ((end - start) * 1000))

+ 30
- 0
python/ecp5prog.py View File

@ -0,0 +1,30 @@
import digitalio
import time
class ECP5Prog(object):
def __init__(self, spi, baudrate=24000000):
self._spi = spi
self._spi.try_lock()
self._spi.configure(baudrate=baudrate)
self._spi.unlock()
def write_file(self, file_name):
self._spi.try_lock()
for i in range(32):
self._spi.write(b'\xFF')
self._spi.write(b'\xBA\xB3')
print("writing " + file_name)
with open(file_name, 'rb') as f:
while True:
data = f.read(1024 * 4)
if not data:
break
self._spi.write(data)
self._spi.unlock()

Loading…
Cancel
Save