Exemple #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();
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        public static void Main()
        {
            USB_ATTinyTPI usb = new USB_ATTinyTPI();

            if (!usb.connect())
            {
                return;
            }

            USB_ATTinyTPI.Processor proc = usb.CPU_identify();

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

            byte[] fuses = usb.CPU_configurationbits_read();
            byte[] locks = usb.CPU_nvmlockbits_read();
            byte[] devid = usb.CPU_deviceidbits_read();

            OpenFileDialog fd = new OpenFileDialog();

            fd.ShowDialog();
            string filename = fd.FileName;// "ATTiny10_helloworld.hex";

            if (filename == "")
            {
                return;
            }
            IntelHEXfile hexfile = new IntelHEXfile(filename);

            byte[] hexdata = hexfile.GetData();

            long tick1 = System.DateTime.Now.Ticks;

            usb.NVM_SECTION_ERASE(usb.CPU_flashaddress());
            usb.NVM_WORD_WRITE(usb.CPU_flashaddress(), hexdata);
            double tock1 = (System.DateTime.Now.Ticks - tick1) / 10000000.0;

            return;

            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])
                {
                    flashedok = false;
                    break;
                }
            }

            usb.S_HIGH();
            usb.flush();
        }