Skip to content

Instantly share code, notes, and snippets.

@cyber-murmel
Created February 13, 2020 11:42
Show Gist options
  • Save cyber-murmel/ce846c9cf108cd7196a306e8cc3531ce to your computer and use it in GitHub Desktop.
Save cyber-murmel/ce846c9cf108cd7196a306e8cc3531ce to your computer and use it in GitHub Desktop.
ice40.py
# -*- coding: utf-8 -*-
# Copyright 2020 by https://badge.team/
# This file is released under the "CC0 1.0 Universal" license.
# https://creativecommons.org/publicdomain/zero/1.0/legalcode
from machine import Pin, SPI
# 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("/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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment