Link Search Menu Expand Document

machine.FPGA – Functions to control the FPGA

The machine.FPGA class contains all of the functions to control the iCE40 FPGA. Import it using

from machine import FPGA

To see what’s contained inside the class you can use the help() command



  • Brings the FPGA out of reset, and loads any binary stored in the flash

      PMIC.fpga_power(True) # Ensure the FPGA is powered on, in case you disabled it before
  • Ensure a valid FPGA binary is stored within the flash, otherwise the FPGA won’t configure


  • Resets the FPGA


  • Gets the current status of the FPGA. Will return one of the following strings

    FPGA_RESETThe FPGA is currently held in reset
    FPGA_CONFIGURINGThe FPGA is configuring and loading the binary from the flash
    FPGA_RUNNINGThe FPGA is running


  • Once the FPGA is configured and running, the CDONE pin which tells us the state of the FPGA, can now be used as a user interrupt

  • Similar to Pin.irq() it can be configured to execute a callback whenever the CDONE pin goes low (always a falling edge)

      # First set up a callback
      def myCallback():
          print("Do stuff")


  • Disables the FPGA interrupt

  • Reads data from the FPGA over the internal SPI bus

      rx = bytearray(10) # Create a 10 byte buffer to read into # Reads 10 bytes over the SPI bus
      # The buffer can be printed, showing what was received
      # Will print out


  • Writes data to the FPGA over the internal SPI bus

      tx = [1, 2, 3, 4, 5] # Create an array of 5 bytes to send
      tx = "\x01\x02\x03\x04\x05" # The buffer can also be created as a string
      FPGA.write(tx) # Sends the 5 bytes from the tx buffer

FPGA.read_write(rxBuffer, txBuffer)

  • Simultaneously reads and writes data

      # rx and tx are the same as before
      FPGA.read_write(rx, tx) # Read 10 bytes, and write 5 bytes