Example #1
0
        private void buttonProgramVerify_Click(object sender, EventArgs e)
        {
            listBoxProgramMessages.Items.Clear();

            USB_ATTinyTPI usb       = createInterface();
            List <string> msgs      = new List <string>();
            bool          connected = usb.connect(msgs);

            postMessages(msgs);

            if (!connected)
            {
                postMessage("Target: connection failed");
                return;
            }
            postMessage("Target: connected");

            USB_ATTinyTPI.Processor proc = usb.CPU_identify();
            listBoxProgramMessages.Items.Add("CPU = " + proc.ToString());

            usb.NVM_command(USB_ATTinyTPI.NVMCommand.NO_OPERATION);
            usb.NVM_waitbusy();

            postMessage("Reading HEX file");
            IntelHEXfile hexfile = new IntelHEXfile(textBoxFlashHEXFile.Text);

            byte[] hexdata = hexfile.GetData();

            postMessage("Verifying device");
            long tick2 = System.DateTime.Now.Ticks;

            byte[] flashprogrammemory = usb.CPU_readbytes(0x4000, hexdata.Length);//usb.CPU_flashsize());
            // 64 bytes : 26.5s
            // 40 bytes : 20.0s
            // 32 bytes : 18.0s
            // 24 bytes : 16.1s
            // 16 bytes : 13.9s
            //  9 bytes : 13.9s
            double tock2     = (System.DateTime.Now.Ticks - tick2) / 10000000.0;
            bool   flashedok = true;

            for (int i = 0; i < hexdata.Length; i++)
            {
                if (flashprogrammemory[i] != hexdata[i])
                {
                    postMessage("Verification failed at address " + i);
                    flashedok = false;
                    break;
                }
            }
            if (flashedok)
            {
                postMessage("Verification successful");
            }
            postMessage("Verification took " + tock2.ToString() + "s");

            postMessage("Deselecting device");
            usb.S_HIGH();
            usb.flush();
        }
Example #2
0
        private void buttonReadSignature_Click(object sender, EventArgs e)
        {
            listBoxProgramMessages.Items.Clear();
            textBoxSignature.Text = "Signature not read";

            USB_ATTinyTPI usb       = createInterface();
            List <string> msgs      = new List <string>();
            bool          connected = usb.connect(msgs);

            postMessages(msgs);

            if (!connected)
            {
                postMessage("Target: connection failed");
                return;
            }
            postMessage("Target: connected");

            usb.NVM_command(USB_ATTinyTPI.NVMCommand.NO_OPERATION);
            usb.NVM_waitbusy();

            byte[] devid    = usb.CPU_deviceidbits_read();
            string sigbytes = string.Format("0x{0:X02} 0x{1:X02} 0x{2:X02}", devid[0], devid[1], devid[2]);

            textBoxSignature.Text = sigbytes;
            postMessage("Signature is " + sigbytes);

            USB_ATTinyTPI.Processor proc = usb.CPU_identify();
            postMessage("CPU is " + proc.ToString());

            postMessage("Deselecting device");
            usb.S_HIGH();
            usb.flush();
        }
Example #3
0
        private void buttonProgramRead_Click(object sender, EventArgs e)
        {
            listBoxProgramMessages.Items.Clear();

            USB_ATTinyTPI usb       = createInterface();
            List <string> msgs      = new List <string>();
            bool          connected = usb.connect(msgs);

            postMessages(msgs);

            if (!connected)
            {
                postMessage("Target: connection failed");
                return;
            }
            postMessage("Target: connected");

            USB_ATTinyTPI.Processor proc = usb.CPU_identify();
            listBoxProgramMessages.Items.Add("CPU = " + proc.ToString());

            usb.NVM_command(USB_ATTinyTPI.NVMCommand.NO_OPERATION);
            usb.NVM_waitbusy();

            postMessage("Reading device at address " + usb.CPU_flashaddress() + " number of bytes " + usb.CPU_flashsize());
            long tick2 = System.DateTime.Now.Ticks;

            byte[] flashprogrammemory = usb.CPU_readbytes(usb.CPU_flashaddress(), usb.CPU_flashsize());
            double tock2     = (System.DateTime.Now.Ticks - tick2) / 10000000.0;
            bool   flashedok = true;

            postMessage("Reading took " + tock2.ToString() + "s");

            SaveFileDialog fd = new SaveFileDialog();

            fd.AddExtension = true;
            fd.Filter       = "Raw Binary File (*.bin)|*.bin";
            DialogResult res = fd.ShowDialog();

            if (res == DialogResult.OK)
            {
                RawBinaryfile rbf = new RawBinaryfile(flashprogrammemory);
                rbf.SaveFile(fd.FileName);
            }
        }