public ESPxxGDBStubSettingsEditor(ESPxxGDBStubSettingsBase settings, KnownInterfaceInstance context, IBSPConfiguratorHost host, bool esp32Mode) { _Context = context; _Host = host; IsESP32 = esp32Mode; Settings = settings; if (Settings == null) { if (esp32Mode) { Settings = new ESP32GDBStubSettings(); } else { Settings = new ESP8266GDBStubSettings(); } } if (context.COMPortNumber.HasValue) { Settings.COMPort = "COM" + context.COMPortNumber; COMPortSelectorVisibility = Visibility.Collapsed; } if (Settings.FLASHResources != null) { foreach (var r in Settings.FLASHResources) { FLASHResources.Add(r); } } FLASHResources.CollectionChanged += (s, e) => { Settings.FLASHResources = FLASHResources.ToArray(); OnSettingsChanged(); }; }
public GDBStubInstance(DebugStartContext context) { _Context = context; _Settings = (ESP8266GDBStubSettings)_Context.Configuration; if (context.ResolvedDevices?.BestMatch.COMPortNumber.HasValue == true) { _COMPort = "COM" + context.ResolvedDevices.BestMatch.COMPortNumber; } else { _COMPort = _Settings.COMPort; } }
public GDBStubInstance(DebugStartContext context, IDebugStartService startService) { _Context = context; _Settings = (ESP8266GDBStubSettings)_Context.Configuration; if (startService.AdvancedDebugService is IExternallyProgrammedProjectDebugService eps) { _COMPort = eps.TryGetProgrammingCOMPortIfKnown(true) ?? _COMPort; } else if (context.ResolvedDevices?.BestMatch.COMPortNumber.HasValue == true) { _COMPort = "COM" + context.ResolvedDevices.BestMatch.COMPortNumber; } else { _COMPort = _Settings.COMPort; } }
public ESPxxGDBStubSettingsEditor(ESPxxGDBStubSettingsBase settings, KnownInterfaceInstance context, IBSPConfiguratorHost host, bool esp32Mode) { _Context = context; _Host = host; IsESP32 = esp32Mode; Settings = settings; if (Settings == null) { if (esp32Mode) { Settings = new ESP32GDBStubSettings(); } else { Settings = new ESP8266GDBStubSettings(); } } if (context.COMPortNumber.HasValue) { Settings.COMPort = "COM" + context.COMPortNumber; COMPortSelectorVisibility = Visibility.Collapsed; } else if (host.AdvancedModeContext is IExternallyProgrammableProjectDebugContext ectx) { ExternalCOMPortSelectionHint = ectx.ExternalProgrammingOptionHint; if (ExternalCOMPortSelectionHint != null) { COMPortSelectorVisibility = DirectFLASHProgrammingOptionVisibility = Visibility.Collapsed; } } if (Settings.FLASHResources != null) { foreach (var r in Settings.FLASHResources) { FLASHResources.Add(r); } } FLASHResources.CollectionChanged += (s, e) => { Settings.FLASHResources = FLASHResources.ToArray(); OnSettingsChanged(); }; }
static void DoConnect(IDebugStartService service, ISimpleGDBSession session, ESP8266GDBStubSettings settings, string comPort, bool programFLASH) { var targetPath = service.TargetPath; if (targetPath != null) //When doing connection test without an active project, the targetPath will be NULL { if (!File.Exists(targetPath)) { throw new Exception(targetPath + " not found. Debugging will not be possible."); } bool stubFound = false; using (var elf = new ELFFile(targetPath)) { foreach (var sym in elf.LoadAllSymbols()) { if (sym.Name == "gdbstub_init") { stubFound = true; break; } } } if (!stubFound) { if (service.GUIService.Prompt("The programmed image does not contain the GDB stub. Do you want to open instructions on debugging with ESP8266 GDB stub?", MessageBoxIcon.Warning)) { Process.Start("http://visualgdb.com/KB/esp8266gdbstub"); throw new OperationCanceledException(); } } } List <string> steps = new List <string>(); if (programFLASH) { steps.Add("Connecting to bootloader"); steps.Add("Programming FLASH memory"); } if (service.Mode != EmbeddedDebugMode.ProgramWithoutDebugging) { steps.Add("Connecting to GDB stub"); } using (var ctx = session.CreateScopedProgressReporter("Connecting to target device", steps.ToArray())) { if (programFLASH) { if (!settings.SuppressResetConfirmation) { service.GUIService.Report("Please reboot your ESP8266 into the bootloader mode and press OK."); } using (var serialPort = new SerialPortStream(comPort, settings.BootloaderBaudRate, System.IO.Ports.Handshake.None)) { serialPort.AllowTimingOutWithZeroBytes = true; ESP8266BootloaderClient client = new ESP8266BootloaderClient(serialPort, settings.BootloaderResetDelay, settings.BootloaderActivationSequence); client.Sync(); var regions = ESP8266StartupSequence.BuildFLASHImages(service, settings, (l, t) => session.SendInformationalOutput(l)); ctx.ReportTaskCompletion(true); int totalSize = 0, writtenSize = 0; foreach (var r in regions) { totalSize += r.Size; } ESP8266BootloaderClient.BlockWrittenHandler handler = (s, addr, len) => ctx.ReportTaskProgress(writtenSize += len, totalSize, $"Writing FLASH at 0x{addr:x8}..."); bool useDIO = false; try { client.BlockWritten += handler; foreach (var r in regions) { var data = File.ReadAllBytes(r.FileName); if (r.Offset == 0 && data.Length >= 4) { useDIO = (data[2] == 2); } client.ProgramFLASH((uint)r.Offset, data); } } finally { client.BlockWritten -= handler; } client.RunProgram(useDIO, false); } } ctx.ReportTaskCompletion(true); if (service.Mode != EmbeddedDebugMode.ProgramWithoutDebugging) { ctx.ReportTaskCompletion(true); session.RunGDBCommand("set serial baud " + settings.StubBaudRate); var result = session.RunGDBCommand(@"target remote \\.\" + comPort); if (!result.IsDone) { throw new Exception("Failed to connect to the gdb stub. Please check your settings."); } } } }