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(); }
private void buttonFusesRead_Click(object sender, EventArgs e) { listBoxProgramMessages.Items.Clear(); textBoxFusesHIGH.Text = ""; textBoxFusesLOW.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_configurationbits_read(); string conflo = string.Format("0x{0:X02}", conf[0]); string confhi = string.Format("0x{0:X02}", conf[1]); textBoxFusesLOW.Text = conflo; textBoxFusesHIGH.Text = confhi; string 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(); }