Skip to content

Commit

Permalink
Improvements in JLink flash (#183)
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
josesimoes authored Dec 13, 2022
1 parent a52bf43 commit 29c85c5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions nanoFirmwareFlasher.Library/JLinkCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ public class JLinkCli
private const string FlashFileCommandTemplate = $@"
USB
speed auto
Reset
Halt
LoadFile {FilePathToken},{FlashAddressToken}
Sleep 1000
LoadFile {FilePathToken} {FlashAddressToken}
Reset
Go
Exit
";

Expand Down Expand Up @@ -276,9 +275,14 @@ public void ShowCLIOutput(string cliOutput)
// show CLI output, if verbosity is diagnostic
if (Verbosity == VerbosityLevel.Diagnostic)
{
Console.ForegroundColor = ConsoleColor.Yellow;

Console.WriteLine();
Console.WriteLine(">>>>>>>>");
Console.WriteLine($"{cliOutput}");
Console.WriteLine(">>>>>>>>");

Console.ForegroundColor = ConsoleColor.White;
}
}

Expand Down Expand Up @@ -314,18 +318,19 @@ internal static string RunJLinkCLI(string cmdFile, string arguments = null)
RedirectStandardError = true,
RedirectStandardOutput = true
};

if (!jlinkExe_.Start())
{
throw new EspToolExecutionException("Error changing permissions for J-Link executable!");
throw new InvalidOperationException("Error changing permissions for J-Link executable!");
}

while (!jlinkExe_.HasExited)
if (!jlinkExe_.WaitForExit(250))
{
Thread.Sleep(10);
throw new InvalidOperationException("Error changing permissions for J-Link executable!");
}
}

Process jlinkCli = new Process();
Process jlinkCli = new();
string parameter = $" -nogui 1 -device default -si swd -CommandFile {cmdFilesDir}";

jlinkCli.StartInfo = new ProcessStartInfo(Path.Combine(appDir, appName), parameter)
Expand All @@ -340,8 +345,8 @@ internal static string RunJLinkCLI(string cmdFile, string arguments = null)
// start J-Link Programmer CLI and...
jlinkCli.Start();

// ... wait for exit (1 min max!)
jlinkCli.WaitForExit((int)TimeSpan.FromMinutes(1).TotalMilliseconds);
// ... wait for exit (30secs max!)
jlinkCli.WaitForExit((int)TimeSpan.FromSeconds(30).TotalMilliseconds);

return jlinkCli.StandardOutput.ReadToEnd();
}
Expand Down

0 comments on commit 29c85c5

Please sign in to comment.