public StatusEx DownloadSimple(string OutputPath, FwTools.FwFormat Format, Bsl430NetDevice Dev, byte[] Password, int AddrStart, int DataSize) { using (var dev = new BSL430NET(Dev)) { dev.ProgressChanged += new Bsl430NetEventHandler(delegate (object s, Bsl430NetEventArgs args) { Console.WriteLine($"{args.Progress} {args.Report}"); }); dev.SetBaudRate(BaudRate.BAUD_115200); dev.SetMCU(MCU.MSP430_F5xx); dev.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG); StatusEx ret = dev.Download(Password, AddrStart, DataSize, out List <byte> Data); string fw = FwTools.Create(Data, AddrStart, Format); using (StreamWriter wr = new StreamWriter(OutputPath)) { wr.Write(fw); } Console.WriteLine($"{ret}\n{fw}"); return(ret); } }
public StatusEx Download(Bsl430NetDevice device, byte[] password, int addr_start, int data_size, out List <byte> data) { return(LoadEx(device, Command.Download, password, "", addr_start, data_size, out data)); }
public async void UploadDetailed() { // Devices string HardcodedDevice = "FTDI1"; // hardcoded device name var DeviceFromScan = new Bsl430NetDevice("USB2"); // device from Scan methods Mode GenericDevice = Mode.UART_Serial; // not know device yet // Input data string FirmwarePath = @"firmware.hex"; // firmware file path // Dev1 and dev2 use DefaultDevice - default device is entered once into // constructor, and then doesnt need to be filled again; the usual way. // Dev3 use generic approach, that can be useful when target multiple MCUs using (var dev1 = new BSL430NET(HardcodedDevice)) using (var dev2 = new BSL430NET(DeviceFromScan)) using (var dev3 = new BSL430NET(GenericDevice)) { // create simple event handler, prints progress (0-100) and report var BslEventHandler = new Bsl430NetEventHandler(delegate (object s, Bsl430NetEventArgs args) { Console.WriteLine($"{args.Progress} {args.Report}"); }); // assign same event handler for all devices dev1.ProgressChanged += BslEventHandler; dev2.ProgressChanged += BslEventHandler; dev3.ProgressChanged += BslEventHandler; // dev1 settings: fastest speed, F5xx MCU, stanard Invoke (TEST pin) Status stat1Baud = dev1.SetBaudRate(BaudRate.BAUD_115200); Status stat1Mcu = dev1.SetMCU(MCU.MSP430_F5xx); Status stat1Invoke = dev1.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG); // dev2 settings: slowest speed, FR6xx MCU, dedicated JTAG pins (TCK pin) Status stat2Baud = dev2.SetBaudRate(BaudRate.BAUD_9600); Status stat2Mcu = dev2.SetMCU(MCU.MSP430_FR6xx); Status stat2Invoke = dev2.SetInvokeMechanism(InvokeMechanism.DEDICATED_JTAG); // dev3 settings: middle speed, old G2xx3 MCU -> old protocol ! read below Status stat3Baud = dev3.SetBaudRate(BaudRate.BAUD_38400); Status stat3Mcu = dev3.SetMCU(MCU.MSP430_G2xx3); Status stat3Invoke = dev3.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG); // Run Upload of single firmware to 3 MCUs, BSL password is not needed, // as Mass Erase is executed first, clearing memory. Only beware when // 1xx/2xx/4xx old MCU is used, Mass Erase could wipe also Info A with // calibration data. This is not case of modern 5xx/6xx MCUs, however // if you dont want to clear memory first, you must supply BSL password var result1 = Task.FromResult <StatusEx>(dev1.Upload(FirmwarePath)); var result2 = Task.FromResult <StatusEx>(dev2.Upload(FirmwarePath)); var result3 = await Task.FromResult <StatusEx>(dev3.Upload(FirmwarePath, "COM1")); // use overiden ToString method to output all important result data Console.WriteLine($"Dev1: {result1}\n\n"); Console.WriteLine($"Dev2: {result2}\n\n"); Console.WriteLine($"Dev3: {result3}"); } }
public CommFTD2XX(BSL430NET root = null, Bsl430NetDevice device = null) : base(root, Mode.UART_FTD2XX) { int check = FTDICheckDriver(); if (check == -1) { throw new Bsl430NetException(323); // mising or wrong dll } //if (check == 0) //throw new Bsl430NetException(333); // missing or wrong driver DefaultDevice = device; }
public async void EraseDetailed() { // Devices string HardcodedDevice = "FTDI1"; // hardcoded device name var DeviceFromScan = new Bsl430NetDevice("USB2"); // device from Scan methods Mode GenericDevice = Mode.UART_Serial; // not know device yet // For Erase there is no need for input data // Dev1 and dev2 use DefaultDevice - default device is entered once into // constructor, and then doesnt need to be filled again; the usual way. // Dev3 use generic approach, that can be useful when target multiple MCUs using (var dev1 = new BSL430NET(HardcodedDevice)) using (var dev2 = new BSL430NET(DeviceFromScan)) using (var dev3 = new BSL430NET(GenericDevice)) { // create simple event handler, prints progress (0-100) and report var BslEventHandler = new Bsl430NetEventHandler(delegate (object s, Bsl430NetEventArgs args) { Console.WriteLine($"{args.Progress} {args.Report}"); }); // assign same event handler for all devices dev1.ProgressChanged += BslEventHandler; dev2.ProgressChanged += BslEventHandler; dev3.ProgressChanged += BslEventHandler; // dev1 settings: F6xx MCU, dedicated JTAG pins (TCK pin) Status stat1Mcu = dev1.SetMCU(MCU.MSP430_F6xx); Status stat1Invoke = dev1.SetInvokeMechanism(InvokeMechanism.DEDICATED_JTAG); // dev2 settings: F5xx MCU, shared JTAG pins (TEST pin) Status stat2Mcu = dev2.SetMCU(MCU.MSP430_F5xx); Status stat2Invoke = dev2.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG); // dev3 settings: old G2xx3 MCU - careful to not wipe Info A! set LOCK A bit Status stat3Mcu = dev3.SetMCU(MCU.MSP430_G2xx3); Status stat3Invoke = dev3.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG); // Run Mass Erase of 3 MCUs - whole memory is wiped. Beware when 1xx/2xx/4xx // old MCU is used and LOCK A is NOT set, Info A with calib data is wiped! var result1 = Task.FromResult <StatusEx>(dev1.Erase()); var result2 = Task.FromResult <StatusEx>(dev2.Erase()); var result3 = await Task.FromResult <StatusEx>(dev3.Erase("COM1")); // use overiden ToString method to output all important result data Console.WriteLine($"Dev1: {result1}\n\n"); Console.WriteLine($"Dev2: {result2}\n\n"); Console.WriteLine($"Dev3: {result3}"); } }
public CommUSB(BSL430NET root = null, Bsl430NetDevice device = null) : base(root, Mode.USB_HID) { int check = USBCheckLibrary(); if (check == -1) { throw new Bsl430NetException(623); // mising or wrong dll } if (check == -2) { throw new Bsl430NetException(633); // dll load exception } DefaultDevice = device; }
public CommSerial(BSL430NET root = null, Bsl430NetDevice device = null) : base(root, Mode.UART_Serial) { int check = SerialCheckLibrary(); if (check == -1) { throw new Bsl430NetException(723); // mising or wrong dll } if (check == -2) { throw new Bsl430NetException(733); // dll load exception } DefaultDevice = device; }
public CommLibftdi(BSL430NET root = null, Bsl430NetDevice device = null) : base(root, Mode.UART_libftdi) { int check = LibftdiCheckLibrary(); if (check == -1) { throw new Bsl430NetException(523); // mising or wrong dll } if (check == -2) { throw new Bsl430NetException(533); // dll load exception } DefaultDevice = device; }
public override void CommOpen(Bsl430NetDevice device) { try { Bsl430NetDevice _device = device; if (device == null) { _device = DefaultDevice; } if (_device == null || _device.Name == "") { throw new Bsl430NetException(461); } if (!devices.ContainsKey(_device.Name.ToLower())) { Status stat = Scan <USB_HID_Device>(out _); if (!stat.OK) { throw new Bsl430NetException(stat.Error); } } if (!devices.TryGetValue(_device.Name.ToLower(), out USB_HID_Device dev)) { throw new Bsl430NetException(462); } DeviceList.Local.GetHidDeviceOrNull(dev.Vid, dev.Pid)?.TryOpen(out usb); if (usb == null) { throw new Bsl430NetException(610); } else { max_output_len = usb.Device.GetMaxOutputReportLength(); max_input_len = usb.Device.GetMaxInputReportLength(); usb.ReadTimeout = Timeout.Infinite; reportDescriptor = usb.Device.GetReportDescriptor(); inputReceiver = reportDescriptor.CreateHidDeviceInputReceiver(); inputReceiver.Start(usb); } } catch (Exception ex) { throw new Bsl430NetException(611, ex); } }
public override void CommOpen(Bsl430NetDevice device) { try { Bsl430NetDevice _device = device; if (device == null) { _device = DefaultDevice; } if (_device == null || _device.Name == "") { throw new Bsl430NetException(461); } if (!devices.ContainsKey(_device.Name.ToLower())) { Status stat = Scan <Serial_Device>(out _); if (!stat.OK) { throw new Bsl430NetException(stat.Error); } } if (!devices.TryGetValue(_device.Name.ToLower(), out Serial_Device dev)) { throw new Bsl430NetException(462); } serial = new SerialPortStream(dev.Port, (int)BaudRate.BAUD_9600, 8, Parity.Even, StopBits.One); serial.Open(); // OpenDirect if (serial == null || !serial.IsOpen) { throw new Bsl430NetException(710); } serial.WriteTimeout = TIMEOUT_WRITE; serial.ReadTimeout = TIMEOUT_READ; } catch (Exception ex) { throw new Bsl430NetException(711, ex); } }
public StatusEx EraseSimple(Bsl430NetDevice Dev) { using (var dev = new BSL430NET(Dev)) { dev.ProgressChanged += new Bsl430NetEventHandler(delegate (object s, Bsl430NetEventArgs args) { Console.WriteLine($"{args.Progress} {args.Report}"); }); dev.SetBaudRate(BaudRate.BAUD_115200); dev.SetMCU(MCU.MSP430_F5xx); dev.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG); StatusEx ret = dev.Erase(); Console.WriteLine($"{ret}"); return(ret); } }
public override void CommOpen(Bsl430NetDevice device) { try { Bsl430NetDevice _device = device; if (device == null) { _device = DefaultDevice; } if (_device == null || _device.Name == "") { throw new Bsl430NetException(461); } if (!devices.ContainsKey(_device.Name.ToLower())) { Status stat = Scan <Libftdi_Device>(out _); if (!stat.OK) { throw new Bsl430NetException(stat.Error); } } if (!devices.TryGetValue(_device.Name.ToLower(), out Libftdi_Device dev)) { throw new Bsl430NetException(462); } ftdi = new FTDIContext(dev.Vid, dev.Pid); if (ftdi == null) { throw new Bsl430NetException(510); } } catch (Exception ex) { throw new Bsl430NetException(511, ex); } }
public async void DownloadDetailed() { // Devices string HardcodedDevice = "FTDI1"; // hardcoded device name var DeviceFromScan = new Bsl430NetDevice("USB2"); // device from Scan methods Mode GenericDevice = Mode.UART_Serial; // not know device yet // Input data // Output firmware file paths string OutputPath1 = @"firmware1.hex"; // firmware output path 1 string OutputPath2 = @"firmware2.txt"; // firmware output path 2 string OutputPath3 = @"firmware3.s19"; // firmware output path 3 // Output firmware file formats FwTools.FwFormat OutputFormat1 = FwTools.FwFormat.INTEL_HEX; // Intel-HEX FwTools.FwFormat OutputFormat2 = FwTools.FwFormat.TI_TXT; // TI-TXT FwTools.FwFormat OutputFormat3 = FwTools.FwFormat.SREC; // SREC // First address - from where to start int AddrStart1 = 0x8000; // start address 1 - 0x8000 int AddrStart2 = 0x9999; // start address 2 - 0x9999 int AddrStart3 = 0xAACC; // start address 3 - 0xAACC // Byte size - how many bytes to download int DataSize1 = 32768; // byte size 1 - 0x8000 hex int DataSize2 = 1000; // byte size 2 - 1000 dec int DataSize3 = 1; // byte size 3 - single byte // BSL password, crucial parameter (read doc) byte[] Password1 = Enumerable.Repeat((byte)0xFF, 32).ToArray(); // standard 32 len byte[] Password2 = Enumerable.Repeat((byte)0xFF, 16).ToArray(); // F543x Non A only byte[] Password3 = Enumerable.Repeat((byte)0xFF, 20).ToArray(); // 20 byte old MCUs // Dev1 and dev2 use DefaultDevice - default device is entered once into // constructor, and then doesnt need to be filled again; the usual way. // Dev3 use generic approach, that can be useful when target multiple MCUs using (var dev1 = new BSL430NET(HardcodedDevice)) using (var dev2 = new BSL430NET(DeviceFromScan)) using (var dev3 = new BSL430NET(GenericDevice)) { // create simple event handler, prints progress (0-100) and report var BslEventHandler = new Bsl430NetEventHandler(delegate (object s, Bsl430NetEventArgs args) { Console.WriteLine($"{args.Progress} {args.Report}"); }); // assign same event handler for all devices dev1.ProgressChanged += BslEventHandler; dev2.ProgressChanged += BslEventHandler; dev3.ProgressChanged += BslEventHandler; // dev1 settings: fastest speed, F6xx MCU, standard 32 byte password Status stat1Baud = dev1.SetBaudRate(BaudRate.BAUD_115200); Status stat1Mcu = dev1.SetMCU(MCU.MSP430_F6xx); Status stat1Invoke = dev1.SetInvokeMechanism(InvokeMechanism.DEDICATED_JTAG); // dev2 settings: slowest speed, F543x MCU Non A -> 16 byte password! Status stat2Baud = dev2.SetBaudRate(BaudRate.BAUD_9600); Status stat2Mcu = dev2.SetMCU(MCU.MSP430_F543x_NON_A); Status stat2Invoke = dev2.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG); // dev3 settings: middle speed, old G2xx3 MCU -> 20 byte password, old protocol Status stat3Baud = dev3.SetBaudRate(BaudRate.BAUD_38400); Status stat3Mcu = dev3.SetMCU(MCU.MSP430_G2xx3); Status stat3Invoke = dev3.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG); // Run Download of 3 firmwares to 3 MCUs, BSL password is required, // Beware when 1xx/2xx/4xx old MCU is used, incorrect password could // wipe also Info A with calibration data. This is not case when // LOCK A bit is set, preventing erase, or if modern 5xx/6xx MCUs used var result1 = Task.FromResult <StatusEx>( dev1.Download(Password1, AddrStart1, DataSize1, out List <byte> Data1)); var result2 = Task.FromResult <StatusEx>( dev2.Download(Password2, AddrStart2, DataSize2, out List <byte> Data2)); var result3 = await Task.FromResult <StatusEx>( dev3.Download(Password3, AddrStart3, DataSize3, out List <byte> Data3, "COM1")); // After download create firmare string from raw data string fw1 = FwTools.Create(Data1, AddrStart1, OutputFormat1); string fw2 = FwTools.Create(Data2, AddrStart2, OutputFormat2); string fw3 = FwTools.Create(Data3, AddrStart3, OutputFormat3); // Finally write ready firmwares to disk using (StreamWriter wr1 = new StreamWriter(OutputPath1)) using (StreamWriter wr2 = new StreamWriter(OutputPath2)) using (StreamWriter wr3 = new StreamWriter(OutputPath3)) { wr1.Write(fw1); wr2.Write(fw2); wr3.Write(fw3); } // use overiden ToString method to output all important result data Console.WriteLine($"Dev1: {result1}\n{fw1}\n\n"); Console.WriteLine($"Dev2: {result2}\n{fw2}\n\n"); Console.WriteLine($"Dev3: {result3}\n{fw3}"); } }
public abstract void CommOpen(Bsl430NetDevice device);
private StatusEx LoadEx(Bsl430NetDevice device, Command cmd, byte[] password, string firmware_path, int?addr_start, int?data_size, out List <byte> output) { output = new List <byte>(); byte[] bsl_version = new byte[0]; Debug.Assert(cmd == Command.Upload || cmd == Command.Download || cmd == Command.MassErase); List <Rx_Block> rx_blocks = new List <Rx_Block>(); FwTools.FwInfo fw_info = new FwTools.FwInfo(); bool baud_rate_fail = false; block_pending = false; progress_pending = 0.0; byte[] pw; try { string dev_name = (device != null) ? device.Name : CommGetDefaultDevice().Name; pw = ValidatePassword(password, out bool pw_overide); UpdateProgress(5, $"INIT '{mode}'"); if (cmd == Command.Upload) { BlockStart("FW READ", 10); Status parsed_fw = ParseFirmware(firmware_path, out rx_blocks, out fw_info); if (!parsed_fw.OK) { BlockEnd(ReportResult.FAILED); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(180, parsed_fw, reports, report, bsl_version, (fw_info == null) ? 0 : fw_info.SizeFull)); } BlockEnd($"FW {fw_info.Format.ToString().Replace('_', '-')} x{fw_info.AddrFirst.ToString("X4")} " + $"{(fw_info.SizeFull / 1024.0).ToString("F1", CultureInfo.InvariantCulture)}K"); } else if (cmd == Command.Download) { BlockStart("PREPARE FW DATA", 10); fw_info = new FwTools.FwInfo(addr_start ?? 0, (addr_start ?? 0) + (data_size ?? 0), data_size ?? 0, GetBufferSize(protocol)); BlockEnd(); } if (fw_info != null && fw_info.AddrLast > int.MaxValue) { return(Utils.StatusCreateEx(100, reports, report, bsl_version, fw_info.SizeFull)); } // --- BlockStart($"OPEN '{dev_name}'", 15); CommOpen(device); CommSet(Utility.Utility.GetEnumDefaultValue <BaudRate>()); BlockEnd(); // --- BlockStart($"INVOKE '{invoke}'", 20, true); if (mode != Mode.USB_HID && invoke != InvokeMechanism.MANUAL) { skipped = false; InvokeBSL(invoke); Task.Delay(100).Wait(); } BlockEnd(); // -- CommClrBuff(); BlockStart($"#BAUD RATE '{(int)baud_rate}'", 25, true); if (mode != Mode.USB_HID && baud_rate != BaudRate.BAUD_9600) { skipped = false; Result <Data_Void> result_baudrate = ParseResp <Data_Void>(ProcessMsg(BuildMsg(Command.BaudRate))); if (!result_baudrate.ok) { baud_rate_fail = true; } Task.Delay(5).Wait(); if (baud_rate_fail) { BlockEnd(ReportResult.FAILED); if (result_baudrate.status.ToString().Contains("timeout")) { CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(100, result_baudrate.status, reports, report, bsl_version, fw_info.SizeFull)); } #if BREAK_ON_BAUD_CHANGE_ERROR CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(100, result_baudrate.status, reports, report, bsl_version, fw_info.SizeFull)); #endif } else { BlockEnd(ReportResult.SUCCESS); CommSet(baud_rate); } Task.Delay(10).Wait(); } else { BlockEnd(); } // -- if ((pw_overide || protocol == Protocol.USB_5_6 || cmd == Command.Download) && cmd != Command.MassErase) { BlockStart("#PASSWORD (CUSTOM)", 35); if (pw_overide && ((protocol == Protocol.UART_1_2_4 && pw.Length == 20) || ((mcu == MCU.MSP430_F543x_NON_A && pw.Length == 16) || pw.Length == 32))) { Result <Data_Void> result_password = ParseResp <Data_Void>(ProcessMsg(BuildMsg(Command.Password, pw))); if (!result_password.ok) { BlockEnd(ReportResult.FAILED); CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(120, result_password.status, reports, report, bsl_version, fw_info.SizeFull)); } else { pw_overide = true; } } else { return(Utils.StatusCreateEx(470, reports, report, bsl_version, fw_info.SizeFull)); } Task.Delay(Const.BSL430_DELAY_BETWEEN_CMDS).Wait(); BlockEnd(); } else // if (!pw_overide && protocol != Protocol.USB_5_6) { BlockStart("#MASS ERASE", 30); Result <Data_Void> result_masserase = ParseResp <Data_Void>(ProcessMsg(BuildMsg(Command.MassErase))); if (!result_masserase.ok) { BlockEnd(ReportResult.FAILED); CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(110, result_masserase.status, reports, report, bsl_version, fw_info.SizeFull)); } BlockEnd(); Task.Delay(100).Wait(); // -- BlockStart("#PASSWORD (DEFAULT)", 35); Result <Data_Void> result_password = ParseResp <Data_Void>(ProcessMsg(BuildMsg(Command.Password, pw))); if (!result_password.ok) { BlockEnd(ReportResult.FAILED); CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(120, result_password.status, reports, report, bsl_version, fw_info.SizeFull)); } Task.Delay(Const.BSL430_DELAY_BETWEEN_CMDS).Wait(); BlockEnd(); } // -- BlockStart("#BSL VERSION", 40, true); if (mode != Mode.USB_HID) { skipped = false; Result <Data_BSLVersion> result_ver = ParseResp <Data_BSLVersion>(ProcessMsg(BuildMsg(Command.BSLVersion))); if (!result_ver.ok) { BlockEnd(ReportResult.FAILED); } else { BlockEnd(ReportResult.SUCCESS, $"#BSL VERSION {BitConverter.ToString(result_ver.data.version).Replace("-", ".")}"); bsl_version = result_ver.data.version.ToArray(); } Task.Delay(Const.BSL430_DELAY_BETWEEN_CMDS).Wait(); } else { BlockEnd(); } // -- if (mode == Mode.USB_HID) { // TODO Upload RAM BSL // TODO Load PC } // -- if (cmd == Command.Upload) { double quantum = 50.0 / (double)rx_blocks.Count; double _prg = 40; Result <Data_Void> result_rx; for (int x = 0; x < rx_blocks.Count; x++) { BlockStart($"#UPLOADING ({x + 1}/{rx_blocks.Count})", _prg); result_rx = ParseResp <Data_Void>(ProcessMsg(BuildMsg(Command.Upload, rx_blocks[x].addr, rx_blocks[x].data))); if (!result_rx.ok) { BlockEnd(ReportResult.FAILED); CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(140, result_rx.status, (x + 1) + "/" + rx_blocks.Count, reports, report, bsl_version, fw_info.SizeFull)); } _prg += quantum; Task.Delay(5).Wait(); if (x == rx_blocks.Count - 1) { BlockEnd($"#UPLOADED ({x + 1}/{rx_blocks.Count})"); } else { BlockEnd(); } } Task.Delay(5).Wait(); } else if (cmd == Command.Download) { int _data_size = (data_size ?? 0); int total = (_data_size + fw_info.SizeBuffer - 1) / fw_info.SizeBuffer; double quantum = 50.0 / (double)total; double _prg = 40; Result <Data_Download> result_tx; for (int x = 0; x < total; x++) { BlockStart($"#DOWNLOADING ({x + 1}/{total})", _prg); int len = data_size ?? 0; if (len > fw_info.SizeBuffer) { len = fw_info.SizeBuffer; } result_tx = ParseResp <Data_Download>(ProcessMsg(BuildMsg(Command.Download, addr_start, new byte[2] { (byte)(len & 0x00FF), (byte)(len >> 8) }))); if (!result_tx.ok) { BlockEnd(ReportResult.FAILED); CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(150, result_tx.status, x + "/" + rx_blocks.Count, reports, report, bsl_version, fw_info.SizeFull)); } output.AddRange(result_tx.data.bytes.ToList()); _prg += quantum; addr_start += fw_info.SizeBuffer; data_size -= fw_info.SizeBuffer; Task.Delay(5).Wait(); if (x == total - 1) { BlockEnd($"#DOWNLOADED ({x + 1}/{total})"); } else { BlockEnd(); } } fw_info.Crc16 = output.Crc16Ccitt(); Task.Delay(5).Wait(); } // -- if (cmd != Command.MassErase) { BlockStart($"#CRC CHECK ({fw_info.Crc16.ToString("X4")})", 95, true); if (protocol != Protocol.UART_1_2_4 && fw_info != null && !(pw_overide && cmd == Command.Upload)) { skipped = false; Result <Data_CRC> result_crc = ParseResp <Data_CRC>(ProcessMsg(BuildMsg(Command.CRC, (int)fw_info.AddrFirst, new byte[2] { (byte)(fw_info.SizeFull & 0x00FF), (byte)(fw_info.SizeFull >> 8) }))); if (!result_crc.ok) { BlockEnd(ReportResult.FAILED); CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(160, result_crc.status, reports, report, bsl_version, fw_info.SizeFull)); } if (result_crc.data.crc != fw_info.Crc16) { BlockEnd(ReportResult.FAILED, $"#CRC CHECK ({fw_info.Crc16.ToString("X4")}!={result_crc.data.crc.ToString("X4")})"); CommClose(true); Task.Delay(Const.DELAY_ERR_RET).Wait(); return(Utils.StatusCreateEx(161, reports, report, bsl_version, fw_info.SizeFull)); } Task.Delay(Const.BSL430_DELAY_BETWEEN_CMDS).Wait(); BlockEnd($"#CRC CHECK ({fw_info.Crc16.ToString("X4")}=={result_crc.data.crc.ToString("X4")})"); } else { BlockEnd(); } } // -- if (cmd != Command.MassErase) { BlockStart("#LOAD USER PROGRAM", 98, true); if (fw_info.ResetVector != null) { skipped = false; Result <Data_Void> result_load = ParseResp <Data_Void>(ProcessMsg(BuildMsg(Command.LoadPC, (int)fw_info.ResetVector))); if (result_load.ok) { BlockEnd(ReportResult.SUCCESS); } else { BlockEnd(ReportResult.FAILED); //Task.Delay(Const.DELAY_ERR_RET).Wait(); //return Utils.StatusCreateEx(170); } } else { BlockEnd(); } } // -- BlockStart($"RESET '{mcu}'", 99, true); if (mode != Mode.USB_HID) { skipped = false; ResetMCU(invoke); } BlockEnd(); // -- BlockStart($"FINISH", 100); CommClose(); BlockEnd(); Task.Delay(Const.DELAY_OK_RET).Wait(); return(Utils.StatusCreateEx(0, reports, null, bsl_version, fw_info.SizeFull)); } catch (Exception ex) { CommClose(true); if (block_pending) { BlockEnd(ReportResult.FAILED); Task.Delay(Const.DELAY_ERR_RET).Wait(); } if (ex is Bsl430NetException) { return(Utils.StatusCreateEx((ex as Bsl430NetException).Status.Error, (ex as Bsl430NetException).Status, reports, report, bsl_version, fw_info.SizeFull)); } else { return(Utils.StatusCreateEx( Utils.StatusCreate(467, ex.Message + ((Const.IS_DEBUG) ? ex.StackTrace : "")), reports, report, bsl_version, fw_info.SizeFull)); } } }
public StatusEx Upload(Bsl430NetDevice device, string firmware_path, byte[] password) { return(LoadEx(device, Command.Upload, password, firmware_path, null, null, out _)); }
public override void CommOpen(Bsl430NetDevice device) { try { if (ftdi == null) { ftdi = new FTDI(); } ftStatus = FTDI.FT_STATUS.FT_OK; Bsl430NetDevice _device = device; if (device == null) { _device = DefaultDevice; } if (_device == null || _device.Name == "") { throw new Bsl430NetException(461); } if (!devices.ContainsKey(_device.Name.ToLower())) { Status stat = Scan <FTDI_Device>(out _); if (!stat.OK) { throw new Bsl430NetException(stat.Error); } } if (!devices.TryGetValue(_device.Name.ToLower(), out FTDI_Device dev)) { throw new Bsl430NetException(462); } ftStatus = FTDI.FT_STATUS.FT_OK; int repeats = OPEN_REPEATS; do { Task.Delay(DELAY_OPEN).Wait(); ftStatus = ftdi.OpenBySerialNumber(dev.Serial); repeats -= 1; if (repeats <= 0) { throw new Bsl430NetException(310); } if (BSL430NET.Interrupted) { throw new Bsl430NetException(666); } }while (ftStatus != FTDI.FT_STATUS.FT_OK); } catch (Bsl430NetException ex) { if (ex.Status.Error == 666) { throw ex; } else { throw new Bsl430NetException(311, ex); } } catch (Exception ex) { throw new Bsl430NetException(311, ex); } }
public StatusEx Erase(Bsl430NetDevice device) { return(LoadEx(device, Command.MassErase, null, "", null, null, out _)); }