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

            USB_I2C_Flash i2cflash = null;

            switch (comboBoxI2CFlashType.Text)
            {
            case "Microchip 24FC256":
                i2cflash = new USB_24FC256();
                break;
            }
            if (i2cflash == null)
            {
                postMessage("No flash type selected");
                return;
            }

            List <string> msgs      = new List <string>();
            bool          connected = i2cflash.connect(msgs);

            postMessages(msgs);

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

            int flashsiz = i2cflash.FlashSize();

            postMessage("FlashInfo: " + flashsiz.ToString() + " bytes flash");

            postMessage("Reading device at address 0 number of bytes " + flashsiz.ToString());
            long tick2 = System.DateTime.Now.Ticks;

            byte[] flashprogrammemory = i2cflash.SequentialRead(0, flashsiz);
            double tock2 = (System.DateTime.Now.Ticks - tick2) / 10000000.0;

            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 #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
        private void buttonI2Cprogram_Click(object sender, EventArgs e)
        {
            listBoxProgramMessages.Items.Clear();

            USB_I2C_Flash i2cflash = null;

            switch (comboBoxI2CFlashType.Text)
            {
            case "Microchip 24FC256":
                i2cflash = new USB_24FC256();
                break;
            }
            if (i2cflash == null)
            {
                postMessage("No flash type selected");
                return;
            }

            List <string> msgs      = new List <string>();
            bool          connected = i2cflash.connect(msgs);

            postMessages(msgs);

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

            int flashsiz = i2cflash.FlashSize();

            postMessage("Flash chip info: " + flashsiz.ToString() + " bytes flash memory");

            postMessage("Reading binary file");
            RawBinaryfile rbf = new RawBinaryfile(textBoxI2CFlashHEXFile.Text);

            byte[] hexdata = rbf.GetData();
            postMessage("File info: " + hexdata.Length + " bytes data");

            bool fastWrite = checkBoxI2CfastFlash.Checked;

            int  address = 0;
            long tick2   = System.DateTime.Now.Ticks;

            while ((address < flashsiz) && (address < hexdata.Length))
            {
                int    pagesiz = i2cflash.PageSize(address);
                byte[] buff    = new byte[pagesiz];
                int    copysiz = Math.Min(pagesiz, hexdata.Length - address);
                Array.Copy(hexdata, address, buff, 0, copysiz);

                //postMessage("Writing data at " + address.ToString());
                i2cflash.PageWrite(address, buff, fastWrite);

                address += pagesiz;
            }
            double tock2 = (System.DateTime.Now.Ticks - tick2) / 10000000.0;

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

            i2cflash.condition_STOP();
        }