Esempio n. 1
0
        public async Task DeployAsync(CancellationToken cancellationToken, TextWriter outputPaneWriter)
        {
            // Kill all instances of PyOcd and OpenOcd because they affect the flash-tool and debugger
            await MbedHelpers.TryKillPyocdAsync();

            await MbedHelpers.TryKillOpenOcdAsync();

            var properties = await Properties.GetMbedDebuggerPropertiesAsync();

            var deployTool = await properties.MbedDeployTool.GetEvaluatedValueAtEndAsync();

            string deployToolPath = string.Empty;
            string binaryPath     = string.Empty;

            if (string.Compare(deployTool, "pyocdflashtool", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy with pyOCD Flash Tool
                deployToolPath = await properties.MbedFlashToolPath.GetEvaluatedValueAtEndAsync();

                deployToolPath = Path.GetFullPath(deployToolPath.Trim('"'));
                if (!File.Exists(deployToolPath))
                {
                    var msg = $"Flash programming tool not found: '{deployToolPath}'";
                    outputPaneWriter.Write(msg);
                    throw new FileNotFoundException(msg);
                }
            }
            else if (string.Compare(deployTool, "stlinkutility", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy with ST-Link Utility
                deployToolPath = await properties.MbedSTLinkUtilityPath.GetEvaluatedValueAtEndAsync();

                deployToolPath = Path.GetFullPath(deployToolPath.Trim('"'));
                if (!File.Exists(deployToolPath))
                {
                    var msg = $"STLink Utility not found: '{deployToolPath}'";
                    outputPaneWriter.Write(msg);
                    throw new FileNotFoundException(msg);
                }
            }
            else if (string.Compare(deployTool, "copytodrive", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy by copying to the drive. Do nothing
            }
            else
            {
                // Deploy with GDB command, or Do Not Deploy
                return;
            }

            binaryPath = await properties.MbedOutputBin.GetEvaluatedValueAtEndAsync();

            binaryPath = Path.GetFullPath(binaryPath.Trim('"'));

            if (!File.Exists(binaryPath))
            {
                var msg = $"Flash binary file not found: '{binaryPath}'";
                outputPaneWriter.Write(msg);
                throw new FileNotFoundException(msg);
            }

            if (string.Compare(deployTool, "pyocdflashtool", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy with pyOCD Flash Tool
                string flashToolArgs = await properties.MbedFlashToolArgs.GetEvaluatedValueAtEndAsync();

                flashToolArgs = $"{EnsureQuotedPathIfNeeded(binaryPath)} {flashToolArgs}";

                await RunDeployTool(cancellationToken, outputPaneWriter, deployToolPath, flashToolArgs);
            }
            else if (string.Compare(deployTool, "stlinkutility", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy with ST-Link Utility
                string stlinkConnectArgs = await properties.MbedSTLinkUtilityConnectArgs.GetEvaluatedValueAtEndAsync();

                string stlinkEraseArgs = await properties.MbedSTLinkUtilityEraseArgs.GetEvaluatedValueAtEndAsync();

                string stlinkProgramArgs = await properties.MbedSTLinkUtilityProgramArgs.GetEvaluatedValueAtEndAsync();

                string stlinkDeployArgs = stlinkConnectArgs + " " + stlinkEraseArgs + " " + stlinkProgramArgs;

                await RunDeployTool(cancellationToken, outputPaneWriter, deployToolPath, stlinkDeployArgs);
            }
            else if (string.Compare(deployTool, "copytodrive", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Copy to the specified drive
                string drive = await properties.MbedDriveToCopyTo.GetEvaluatedValueAtEndAsync();

                drive = drive.Trim();

                if (string.IsNullOrWhiteSpace(drive))
                {
                    throw new ArgumentNullException("Drive not specified");
                }

                // Get the properly formatted string for the drive letter
                DriveInfo driveInfo = new DriveInfo(drive);
                drive = driveInfo.RootDirectory.FullName;

                if (!Directory.Exists(drive))
                {
                    throw new DriveNotFoundException("The drive specified could not be located");
                }

                string[] binaryPathArr = binaryPath.Split('\\');
                string   binaryName    = binaryPathArr[binaryPathArr.Length - 1];
                string   destFile      = System.IO.Path.Combine(drive, binaryName);

                // Allow the copy to fail, and throw an exception on its own
                File.Copy(binaryPath, destFile, true);
            }
        }
Esempio n. 2
0
        public override async Task <IReadOnlyList <IDebugLaunchSettings> > QueryDebugTargetsAsync(DebugLaunchOptions launchOptions)
        {
            var settings = new DebugLaunchSettings(launchOptions);

            // The properties that are available via DebuggerProperties are determined by the property XAML files in your project.
            var debuggerProperties = await this.DebuggerProperties.GetPyOCDPropertiesAsync();

            string dir = await debuggerProperties.PyOCDWorkingDirectory.GetEvaluatedValueAtEndAsync();

            string executable = await debuggerProperties.PyOCDBinary.GetEvaluatedValueAtEndAsync();

            string gdbPath = await debuggerProperties.GdbPath.GetEvaluatedValueAtEndAsync();

            string gdbArgs = await debuggerProperties.GdbArgs.GetEvaluatedValueAtEndAsync();

            // Check to ensure the executable is there
            if (!File.Exists(executable))
            {
                string binDir = await debuggerProperties.PyOCDBinaryDirectory.GetEvaluatedValueAtEndAsync();

                var files = Directory.GetFiles(binDir, "*.elf");

                if (files != null && files.Length > 0)
                {
                    executable = files[0];
                }
                else
                {
                    throw new FileNotFoundException("The compiled ELF file could not be found");
                }
            }

            settings.CurrentDirectory = dir;
            settings.Executable       = executable;

            // If we are going to deploy with GDB load command, create a script that will also load the elf file
            string debugScript = DebuggerScriptContentFormat;
            var    deployTool  = "gdbloadcommand";//await debuggerProperties.LlilumDeployTool.GetEvaluatedValueAtEndAsync();

            if (string.Compare(deployTool, "gdbloadcommand", true) == 0)
            {
                debugScript = DebuggerLoadScriptContentFormat;
            }

            // Create the temporary file for passing to the debug engine
            string debuggerFile = CreateDebuggerFileIfNoneExist(dir, executable, gdbPath, gdbArgs, debugScript);

            settings.Options               = string.Format(DebuggerOptionsFormat, debuggerFile);
            settings.LaunchOperation       = DebugLaunchOperation.CreateProcess;
            settings.LaunchDebugEngineGuid = new Guid(Microsoft.MIDebugEngine.EngineConstants.EngineId);

            // Launch py_ocd to communicate with GDB
            string gdbServerPath = await debuggerProperties.PyOcdPath.GetEvaluatedValueAtEndAsync();

            string gdbServerArgs = await debuggerProperties.PyOcdArgs.GetEvaluatedValueAtEndAsync();

            if (!string.IsNullOrWhiteSpace(gdbServerPath))
            {
                // Even though we did it in deploy, do it here just in case we go straight to debug
                await MbedHelpers.TryKillPyocdAsync();

                ProcessStartInfo start = new ProcessStartInfo();
                start.FileName               = gdbServerPath;
                start.Arguments              = gdbServerArgs;
                start.UseShellExecute        = false;
                start.RedirectStandardOutput = true;
                Process gdbServerProcess = Process.Start(start);
            }

            return(new IDebugLaunchSettings[] { settings });
        }