private void buttonLockBitsRead_Click(object sender, EventArgs e) { listBoxProgramMessages.Items.Clear(); textBoxLockBitsLOW.Text = ""; 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[] conf = usb.CPU_nvmlockbits_read(); string conflo = string.Format("0x{0:X02}", conf[0]); textBoxLockBitsLOW.Text = conflo; string confbytes = string.Format("0x{0:X02} 0x{1:X02}", conf[0], conf[1]); postMessage("LockBits are " + confbytes); postMessage("Deselecting device"); usb.S_HIGH(); usb.flush(); }
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(); }
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(); }
private void buttonLockBitsWrite_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.NVM_command(USB_ATTinyTPI.NVMCommand.NO_OPERATION); usb.NVM_waitbusy(); byte[] conf = usb.CPU_nvmlockbits_read(); string confbytes = string.Format("0x{0:X02} 0x{1:X02}", conf[0], conf[1]); postMessage("LockBits were " + confbytes); byte conflo = Convert.ToByte(textBoxLockBitsLOW.Text, 16); byte confhi = 255; byte[] newconf = { conflo, confhi }; postMessage("Writing LockBits"); usb.NVM_SECTION_ERASE(usb.CPU_nvmlockbits_address()); usb.NVM_WORD_WRITE(usb.CPU_nvmlockbits_address(), newconf); conf = usb.CPU_nvmlockbits_read(); confbytes = string.Format("0x{0:X02} 0x{1:X02}", conf[0], conf[1]); postMessage("LockBits are " + confbytes); if (conf[0] != newconf[0] || conf[1] != newconf[1]) { postMessage("LockBits were not set. Will erase the entire chip"); usb.NVM_CHIP_ERASE(); usb.NVM_WORD_WRITE(usb.CPU_nvmlockbits_address(), newconf); conf = usb.CPU_nvmlockbits_read(); confbytes = string.Format("0x{0:X02} 0x{1:X02}", conf[0], conf[1]); postMessage("LockBits are " + confbytes); } postMessage("Deselecting device"); usb.S_HIGH(); usb.flush(); }
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); } }
private void buttonFusesWrite_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.NVM_command(USB_ATTinyTPI.NVMCommand.NO_OPERATION); usb.NVM_waitbusy(); byte[] conf = usb.CPU_configurationbits_read(); string confbytes = string.Format("0x{0:X02} 0x{1:X02}", conf[0], conf[1]); postMessage("Configuration was " + confbytes); byte conflo = Convert.ToByte(textBoxFusesLOW.Text, 16); byte confhi = Convert.ToByte(textBoxFusesHIGH.Text, 16); byte[] newconf = { conflo, confhi }; usb.NVM_SECTION_ERASE(usb.CPU_configurationbits_address()); usb.NVM_WORD_WRITE(usb.CPU_configurationbits_address(), newconf); conf = usb.CPU_configurationbits_read(); confbytes = string.Format("0x{0:X02} 0x{1:X02}", conf[0], conf[1]); postMessage("Configuration is " + confbytes); postMessage("Deselecting device"); usb.S_HIGH(); usb.flush(); }
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(); }