|
@@ -9,13 +9,17 @@ namespace ST_LINK_MES.Service
|
|
|
{
|
|
|
public class STLinkCliWrapService
|
|
|
{
|
|
|
- public STLinkCliWrapService(string cliPath)
|
|
|
+ public STLinkCliWrapService(string cliPath, string port = "", string customDefaultOption = null)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(cliPath))
|
|
|
{
|
|
|
cliPath = "C:\\Program Files (x86)\\STMicroelectronics\\STM32 ST-LINK Utility\\ST-LINK Utility\\ST-LINK_CLI.exe";
|
|
|
}
|
|
|
this.cliPath = cliPath;
|
|
|
+
|
|
|
+ SetPortStringParam(port);
|
|
|
+
|
|
|
+ SetCustomDefaultOptionParam(customDefaultOption);
|
|
|
}
|
|
|
|
|
|
public delegate void OnMsgRecevicedEvent(string msg);
|
|
@@ -24,30 +28,32 @@ namespace ST_LINK_MES.Service
|
|
|
public string CliPath => cliPath;
|
|
|
|
|
|
private readonly string cliPath;
|
|
|
+ private string portParamString;
|
|
|
+ private string defaultOptionString;
|
|
|
|
|
|
public int SetDefaultOptions()
|
|
|
{
|
|
|
- return RunConsole(cliPath, $"-OB RDP=0 BOR_LEV=3 IWDG_SW=1 nRST_STOP=1 nRST_STDBY=1");
|
|
|
+ return RunConsole(cliPath, $"{portParamString} {defaultOptionString}");
|
|
|
}
|
|
|
|
|
|
public int StartProgram(string filePath)
|
|
|
{
|
|
|
- return RunConsole(cliPath, $"-P \"{filePath}\" 0x08000000");
|
|
|
+ return RunConsole(cliPath, $"{portParamString} -P \"{filePath}\" 0x08000000 -V \"after_programing\"");
|
|
|
}
|
|
|
|
|
|
public int Rest()
|
|
|
{
|
|
|
- return RunConsole(cliPath, $"-Rst");
|
|
|
+ return RunConsole(cliPath, $"{portParamString} -Rst");
|
|
|
}
|
|
|
|
|
|
public int Check(string filePath)
|
|
|
{
|
|
|
- return RunConsole(cliPath, $"-CmpFile \"{filePath}\" 0x08000000");
|
|
|
+ return RunConsole(cliPath, $"{portParamString} -CmpFile \"{filePath}\" 0x08000000");
|
|
|
}
|
|
|
|
|
|
public int GetCheckSum(string filePath)
|
|
|
{
|
|
|
- return RunConsole(cliPath, $"-Cksum \"{filePath}\"");
|
|
|
+ return RunConsole(cliPath, $"{portParamString} -Cksum \"{filePath}\"");
|
|
|
}
|
|
|
|
|
|
private int RunConsole(string exePath, string param)
|
|
@@ -78,5 +84,25 @@ namespace ST_LINK_MES.Service
|
|
|
{
|
|
|
OnMsgReceviced?.Invoke(e.Data);
|
|
|
}
|
|
|
+
|
|
|
+ private void SetPortStringParam(string port)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(port))
|
|
|
+ {
|
|
|
+ portParamString = string.Empty;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ portParamString = $"-c {port}";
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetCustomDefaultOptionParam(string customDefaultOption)
|
|
|
+ {
|
|
|
+ if (customDefaultOption != null)
|
|
|
+ {
|
|
|
+ defaultOptionString = customDefaultOption;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ defaultOptionString = $"-OB RDP=0 BOR_LEV=3 IWDG_SW=1 nRST_STOP=1 nRST_STDBY=1";
|
|
|
+ }
|
|
|
}
|
|
|
}
|