def checkPortStatus(self, update_button_state):
        global port_success
        with serial.Serial(self.port[0],
                           12000000,
                           timeout=.5,
                           writeTimeout=0.1) as ser:
            async_serial = tinyfpgaa.SyncSerial(ser)
            pins = tinyfpgaa.JtagTinyFpgaProgrammer(async_serial)
            jtag = tinyfpgaa.Jtag(pins)
            programmer = tinyfpgaa.JtagCustomProgrammer(jtag)
            port_success = False

            def status_callback(status):
                global port_success

                if status == [0x43, 0x80, 0x2B, 0x01]:
                    com_port_status_sv.set(
                        "Connected to TinyFPGA A1. Ready to program.")
                    port_success = True

                elif status == [0x43, 0xA0, 0x2B, 0x01]:
                    com_port_status_sv.set(
                        "Connected to TinyFPGA A2. Ready to program.")
                    port_success = True

                else:
                    com_port_status_sv.set(
                        "Cannot identify FPGA.  Please ensure proper FPGA power and JTAG connection."
                    )
                    port_success = False

            ### read idcode
            programmer.write_ir(8, 0xE0)
            programmer.read_dr(32, status_callback, blocking=True)
            return port_success
Exemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-q", action="store_true", help="Silent mode.")
    parser.add_argument("-p", type=str, help="Manually specify serial device.")
    parser.add_argument("-b",
                        action="store_true",
                        help="Input is bitstream file.")
    parser.add_argument("jed",
                        type=str,
                        help="JEDEC or bitstream file to program.")
    args = parser.parse_args()

    if not args.p:
        for port in comports():
            if "1209:2101" in port[2]:
                a_port = port[0]
                break
        else:
            print("TinyFPGA A not detected! Is it plugged in?")
            sys.exit(1)
    else:
        a_port = args.p

    with serial.Serial(a_port, 12000000, timeout=10, writeTimeout=5) as ser:
        async_serial = tinyfpgaa.SyncSerial(ser)
        pins = tinyfpgaa.JtagTinyFpgaProgrammer(async_serial)
        jtag = tinyfpgaa.Jtag(pins)
        programmer = tinyfpgaa.JtagCustomProgrammer(jtag)

        if not args.q:
            if args.b:
                print("Parsing bitstream file...")
            else:
                print("Parsing JEDEC file...")

        if args.b:
            input_file = tinyfpgaa.BitstreamFile(open(args.jed, 'rb'))
        else:
            input_file = tinyfpgaa.JedecFile(open(args.jed, 'r'))

        try:
            if not args.q:
                print("Programming TinyFPGA A on {}...".format(a_port))
            programmer.program(input_file)
        except:
            print("Programming Failed!")
            traceback.print_exc()
            sys.exit(2)

    print("Programming finished without error.")
Exemplo n.º 3
0
    def program(self, filename, progress):
        global max_progress

        with serial.Serial(self.port[0], 12000000, timeout=10, writeTimeout=5) as ser:            
            async_serial = tinyfpgaa.SyncSerial(ser)
            pins = tinyfpgaa.JtagTinyFpgaProgrammer(async_serial)
            jtag = tinyfpgaa.Jtag(pins)
            programmer = tinyfpgaa.JtagCustomProgrammer(jtag)
           
            progress("Parsing JEDEC file")
            jedec_file = tinyfpgaa.JedecFile(open(filename, 'r'))

            max_progress = jedec_file.numRows() * 3

            try:
                programmer.program(jedec_file, progress)

            except:
                program_failure = True
                self.reset()
                traceback.print_exc()