diff --git a/nanoFirmwareFlasher/Options.cs b/nanoFirmwareFlasher/Options.cs
index f1c570e5..3b67328d 100644
--- a/nanoFirmwareFlasher/Options.cs
+++ b/nanoFirmwareFlasher/Options.cs
@@ -179,6 +179,12 @@ public class Options
HelpText = "ID of the J-Link device to update. If not specified the first connected J-Link device will be used.")]
public string JLinkDeviceId { get; set; }
+ [Option(
+ "setvcpbr",
+ Required = false,
+ HelpText = "Set baud rate of J-Link Virtual COM Port. If a value is not specified it will use the default value for Wire Protocol.")]
+ public int? SetVcpBaudRate { get; set; }
+
#endregion
diff --git a/nanoFirmwareFlasher/Program.cs b/nanoFirmwareFlasher/Program.cs
index 4969a49c..77669136 100644
--- a/nanoFirmwareFlasher/Program.cs
+++ b/nanoFirmwareFlasher/Program.cs
@@ -1148,8 +1148,14 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
Console.WriteLine($"Connected to J-Link device with ID {jlinkDevice.ProbeId}");
}
- // set VCP baud rate (if needed)
- _ = SilinkCli.SetVcpBaudRate(o.JLinkDeviceId is null ? connectedJLinkDevices.First() : "", _verbosityLevel);
+ // set VCP baud rate (if requested)
+ if (o.SetVcpBaudRate.HasValue)
+ {
+ _ = SilinkCli.SetVcpBaudRate(
+ o.JLinkDeviceId is null ? connectedJLinkDevices.First() : "",
+ o.SetVcpBaudRate.Value,
+ _verbosityLevel);
+ }
// set verbosity
jlinkDevice.Verbosity = _verbosityLevel;
@@ -1200,8 +1206,14 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
operationPerformed = true;
- // set VCP baud rate (if needed)
- _ = SilinkCli.SetVcpBaudRate(o.JLinkDeviceId is null ? connectedJLinkDevices.First() : "", _verbosityLevel);
+ if (o.SetVcpBaudRate.HasValue)
+ {
+ // set VCP baud rate (if needed)
+ _ = SilinkCli.SetVcpBaudRate(
+ o.JLinkDeviceId is null ? connectedJLinkDevices.First() : "",
+ o.SetVcpBaudRate.Value,
+ _verbosityLevel);
+ }
if (_exitCode != ExitCodes.OK)
{
diff --git a/nanoFirmwareFlasher/SilinkCli.cs b/nanoFirmwareFlasher/SilinkCli.cs
index 02ea8093..c5d44ac8 100644
--- a/nanoFirmwareFlasher/SilinkCli.cs
+++ b/nanoFirmwareFlasher/SilinkCli.cs
@@ -19,13 +19,14 @@ internal class SilinkCli
{
private const int SilinkTelnetPort = 49000;
private const int SilinkAdminPort = SilinkTelnetPort + 2;
- private const int TargetBaudRate = 921600;
+ private const int DefaultBaudRate = 921600;
///
/// This will set the baud rate of the VCP in a Silabs Jlink board.
/// Before setting the value the devices is queried and the new setting is applied only if needed.
///
/// Id of the JLink probe to adjust the baud rate.
+ /// Value of baud rate to set.
/// Verbosity level for the operation. will be used if not specified.
///
///
@@ -33,6 +34,7 @@ internal class SilinkCli
///
public static ExitCodes SetVcpBaudRate(
string probeId,
+ int baudRate,
VerbosityLevel verbosity = VerbosityLevel.Quiet)
{
// check that we can run on this platform
@@ -50,6 +52,9 @@ public static ExitCodes SetVcpBaudRate(
return ExitCodes.E8002;
}
+ // store baud rate value
+ int targetBaudRate = baudRate == 0 ? DefaultBaudRate : baudRate;
+
Console.ForegroundColor = ConsoleColor.White;
// launch silink
@@ -101,12 +106,12 @@ public static ExitCodes SetVcpBaudRate(
const string regexPattern = "(?:Stored port speed : )(?'baudrate'\\d+)";
var myRegex1 = new Regex(regexPattern, RegexOptions.Multiline);
- var currentBaud = myRegex1.Match(currentConfig);
+ var currentVcomConfig = myRegex1.Match(currentConfig);
- if (currentBaud.Success)
+ if (currentVcomConfig.Success)
{
// verify current setting
- if (int.TryParse(currentBaud.Groups["baudrate"].Value, out int baudRate) && baudRate == TargetBaudRate)
+ if (int.TryParse(currentVcomConfig.Groups["baud rate"].Value, out int currentBaudRate) && currentBaudRate == targetBaudRate)
{
if (verbosity >= VerbosityLevel.Detailed)
{
@@ -131,7 +136,7 @@ public static ExitCodes SetVcpBaudRate(
Thread.Sleep(250);
// compose command
- buffer = Encoding.Default.GetBytes($"serial vcom config speed {TargetBaudRate}\r");
+ buffer = Encoding.Default.GetBytes($"serial vcom config speed {targetBaudRate}\r");
silinkSocket.Send(buffer);
Thread.Sleep(250);
@@ -146,7 +151,7 @@ public static ExitCodes SetVcpBaudRate(
Console.WriteLine($"{opResult}");
}
- if (opResult.Contains($"Baudrate set to {TargetBaudRate} bps"))
+ if (opResult.Contains($"Baudrate set to {targetBaudRate} bps"))
{
if (verbosity == VerbosityLevel.Normal)
{