Toggle Navigation
Hatchery
Eggs
ICE40
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
from machine import Pin, SPI # Find the directory this app resides in try: directory = '/'.join(__file__.split('/')[:-1]) except: directory = '/' # Pins pin_reset = Pin(16, Pin.OUT) pin_done = Pin(21) pin_miso = Pin(5) pin_mosi = Pin(17, Pin.OUT) pin_sck = Pin(19, Pin.OUT) pin_ss = Pin(18, Pin.OUT) # SPI bus spi = SPI(1, baudrate=1000000, sck=pin_sck, mosi=pin_mosi, miso=pin_miso) # Open bitstream file f = open(directory+"/blink.bin", "rb") # Reset the ICE40 into SPI slave download mode pin_reset.value(0) # FPGA into RESET pin_ss.value(0) # Hold down SS pin pin_reset.value(1) # Take FPGA out of RESET print("Writing...") while True: data = f.read(128) if len(data) < 1: break spi.write(data) print("Sending dummy bytes...") spi.write(bytes([0]*100)) print("Done.")