Skip to content

Commit abb81dc

Browse files
Fix ST devices that cannot handle DFU packages (#44)
1 parent ac13292 commit abb81dc

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

nanoFirmwareFlasher/Program.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,10 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
473473
return;
474474
}
475475

476-
if (!string.IsNullOrEmpty(o.DfuFile))
476+
var connectedStDfuDevices = StmDfuDevice.ListDfuDevices();
477+
var connectedStJtagDevices = StmJtagDevice.ListDevices();
478+
479+
if (!string.IsNullOrEmpty(o.DfuFile) && connectedStDfuDevices.Count != 0)
477480
{
478481
// there is a DFU file argument, so follow DFU path
479482
var dfuDevice = new StmDfuDevice(o.DfuDeviceId);
@@ -522,7 +525,9 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
522525
}
523526
else if (
524527
o.BinFile.Any() &&
525-
o.HexFile.Any())
528+
o.HexFile.Any() &&
529+
connectedStJtagDevices.Count != 0
530+
)
526531
{
527532
// this has to be a JTAG connected device
528533

nanoFirmwareFlasher/Stm32Firmware.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ public Stm32Firmware(string targetName, string fwVersion, bool stable)
4040
{
4141
DfuPackage = dfuFile.FirstOrDefault();
4242
}
43-
else
44-
{
45-
nanoBooterFile = Directory.EnumerateFiles(LocationPath, "nanoBooter.hex").FirstOrDefault();
46-
nanoCLRFile = Directory.EnumerateFiles(LocationPath, "nanoCLR.hex").FirstOrDefault();
47-
}
43+
nanoBooterFile = Directory.EnumerateFiles(LocationPath, "nanoBooter.hex").FirstOrDefault();
44+
nanoCLRFile = Directory.EnumerateFiles(LocationPath, "nanoCLR.hex").FirstOrDefault();
4845
}
4946

5047
return executionResult;

nanoFirmwareFlasher/Stm32Operations.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
8585
}
8686
}
8787

88+
var connectedStDfuDevices = StmDfuDevice.ListDfuDevices();
89+
var connectedStJtagDevices = StmJtagDevice.ListDevices();
90+
8891
// need DFU or JTAG device
89-
if (firmware.HasDfuPackage)
92+
if (firmware.HasDfuPackage && connectedStDfuDevices.Count !=0)
9093
{
9194
// DFU package
9295
dfuDevice = new StmDfuDevice(dfuDeviceId);
@@ -120,7 +123,7 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
120123
return ExitCodes.E1003;
121124
}
122125
}
123-
else
126+
else if (connectedStJtagDevices.Count != 0)
124127
{
125128
// JATG device
126129
jtagDevice = new StmJtagDevice(jtagId);
@@ -162,6 +165,11 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
162165

163166
return programResult;
164167
}
168+
else
169+
{
170+
// no device was found to update.
171+
return ExitCodes.E7000;
172+
}
165173
}
166174

167175
internal static ExitCodes ResetMcu(

0 commit comments

Comments
 (0)