Example #1
0
    def checkPortStatus(self, update_button_state):
        try:
            print(self.port)
            with serial.Serial(self.port[0],
                               115200,
                               timeout=0.2,
                               writeTimeout=2) as ser:
                fpga = TinyFPGAQ(ser)
                if fpga.is_bootloader_active():
                    com_port_status_sv.set(
                        "Connected to QuickFeather. Ready to program.")
                    return True
                else:
                    com_port_status_sv.set(
                        "Unable to communicate with QuickFeather. Reconnect and reset QuickFeather before programming."
                    )
                    return False

        except serial.SerialTimeoutException:
            com_port_status_sv.set(
                "Hmm...try pressing the reset button on QuickFeather again.")
            return False

        except:
            com_port_status_sv.set(
                "Bootloader not active. Press reset button on QuickFeather before programming."
            )
            return False
Example #2
0
    def reset_meta(self,
                   image_index,
                   progress,
                   description="",
                   checkrev=False,
                   update=False):
        global max_progress

        with serial.Serial(self.port[0], 115200, timeout=60,
                           writeTimeout=60) as ser:
            fpga = TinyFPGAQ(ser, progress)
            crc32 = 0xFFFFFFFF
            meta_array = bytearray(crc32.to_bytes(4, 'little'))
            bitstream_size = 0xFFFFFFFF
            meta_array.extend(bitstream_size.to_bytes(4, 'little'))

            meta_addr = image_address[image_index][2]
            meta_bitstream = bytes(meta_array)

            try:
                print("resetting metadata")
                fpga.program_bitstream(meta_addr, meta_bitstream, "metadata")
                #print("Not programming metadata");
            except:
                program_failure = True
                traceback.print_exc()
Example #3
0
    def get_image_info(self, image_index):
        with serial.Serial(self.port[0], 115200, timeout=60,
                           writeTimeout=60) as ser:
            fpga = TinyFPGAQ(ser, progress)

            meta_addr = image_address[image_index][2]
            read_meta = bytearray(fpga.read(meta_addr, 12, False))

            read_image_info = read_meta[-4:]

            return read_image_info
Example #4
0
def change_boot_mode_cmd(*args):
    if (comport == None):
        print('Please specify COM port using the comport command')
        return
    new_mode = int(args[0])
    print('change boot mode command', args, 'new mode=', new_mode)
    with serial.Serial(comport, 115200, timeout=60, writeTimeout=60) as ser:
        addr = 0x1F000 + 8
        if new_mode == 1:
            bitstream = b'\x55' * 4
        else:
            bitstream = b'\xAA' * 4
        print('Setting boot mode to ', new_mode, ':', bitstream.hex())
        fpga = TinyFPGAQ(ser)
        print(fpga)
        ret = fpga.program_bitstream(addr, bitstream, 'boot-mode')
Example #5
0
    def exitBootloader(self):
        with serial.Serial(self.port[0], 115200, timeout=0.2,
                           writeTimeout=2) as ser:
            try:
                TinyFPGAQ(ser).boot()
                print("boot sent")

            except serial.SerialTimeoutException:
                com_port_status_sv.set(
                    "Hmm...try pressing the reset button on QuickFeather again."
                )
Example #6
0
    def set_image_info(self,
                       image_index,
                       image_info,
                       progress,
                       description="",
                       checkrev=False,
                       update=False):
        with serial.Serial(self.port[0], 115200, timeout=60,
                           writeTimeout=60) as ser:
            fpga = TinyFPGAQ(ser, progress)
            #convert image_info to bytearray
            image_info_bytearray = bytearray(image_info)

            # rmw needed, read metadata first
            meta_addr = image_address[image_index][2]
            read_meta = bytearray(fpga.read(meta_addr, 12, False))

            # check the last 4 bytes (image_info) in the metadata
            read_image_info = read_meta[-4:]

            # if they are already the same as what we want to write, nothing to do
            if (image_info_bytearray == read_image_info):
                print("image_info is already set correctly, not writing again")
            else:
                # set image_info into metadata, replace last 4 bytes with new image_info
                read_meta[-4:] = image_info

                # write metadata
                meta_bitstream = bytes(read_meta)
                try:
                    print("writing new image_info to metadata")
                    fpga.program_bitstream(meta_addr, meta_bitstream,
                                           "metadata")
                    #print("Not programming metadata");
                except:
                    program_failure = True
                    traceback.print_exc()
Example #7
0
    def printCRCs(self):
        with serial.Serial(self.port[0], 115200, timeout=10,
                           writeTimeout=10) as ser:
            fpga = TinyFPGAQ(ser, progress)

            crc = fpga.read(image_address[0][2], 8, False)
            print("bootloader:", binascii.hexlify(crc))
            crc = fpga.read(image_address[1][2], 8, False)
            print("boot fpga :", binascii.hexlify(crc))
            crc = fpga.read(image_address[4][2], 8, False)
            print("M4 app    :", binascii.hexlify(crc))
            crc = fpga.read(image_address[2][2], 8, False)
            print("app fpga  :", binascii.hexlify(crc))
Example #8
0
    def program(self,
                filename,
                progress,
                description="",
                checkrev=False,
                update=False):
        global max_progress

        with serial.Serial(self.port[0], 115200, timeout=60,
                           writeTimeout=60) as ser:
            fpga = TinyFPGAQ(ser, progress)

            (addr, bitstream) = fpga.slurp(filename)
            #print("Address = ", hex(addr), len(bitstream))
            #crc32 = binascii.crc32(bitstream, 0xFFFFFFFF)
            #print("Crc32 =", hex(crc32))

            qcrc32 = get_crc32_from_string(bitstream)
            #print("QCrc32 =", hex(qcrc32))
            crc32 = qcrc32

            meta_array = bytearray(crc32.to_bytes(4, 'little'))
            bitstream_size = len(bitstream)
            meta_array.extend(bitstream_size.to_bytes(4, 'little'))
            #meta_array.extend(bytes(b"\0"*(4096-8)))
            #print("META = ", bytes(meta_array))

            #get the image type selection and look-up the address, size and metadata address
            if image_index == -1:
                index = image_options.index(imagename_sv.get())
            else:
                index = image_index
            addr = image_address[index][0]
            max_size = image_address[index][1]
            meta_addr = image_address[index][2]
            meta_bitstream = bytes(meta_array)

            if (bitstream_size > max_size):
                print("Error: The file size", bitstream_size,
                      "exceeds max size", max_size, "for the selected image")
                return

            try:
                actual_crc = fpga.read(meta_addr, 8, False)
            except:
                program_failure = True
                traceback.print_exc()
                return ()

            # If just wants to check the revision, print match/mismatch and return
            if checkrev:
                if meta_bitstream == actual_crc:
                    print("is  up-to-date:", filename)
                    return ()
                else:
                    print("not up-to-date:", filename)
                    return ()

            # If specified update, then return if CRC matches, otherwise program
            if update and (meta_bitstream == actual_crc):
                print("Skipping programming because CRC matches for ",
                      filename)
                return ()

            # Need to program
            print(description, filename)

            #print("Address = ", hex(addr), hex(max_size), hex(meta_addr))

            max_progress = len(bitstream) * 3

            try:
                fpga.program_bitstream(addr, bitstream, "binary")
                #print("Not programming ");
            except:
                program_failure = True
                traceback.print_exc()

            #bootloader does not have metatdata
            #if(meta_addr > 0x20000):
            #    return

            try:
                print("Writing metadata")
                fpga.program_bitstream(meta_addr, meta_bitstream, "metadata")
                #print("Not programming metadata");
            except:
                program_failure = True
                traceback.print_exc()