Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/nanoFirmwareFlasher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nanoFirmwareFlasher", "nanoFirmwareFlasher\nanoFirmwareFlasher.csproj", "{762BA2A1-B3E9-4E26-9491-AE11D1F1C1EA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9FD8C426-A16A-49DB-952D-747C3AD96C42}"
ProjectSection(SolutionItems) = preProject
NuGet.Config = NuGet.Config
version.json = version.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down
6 changes: 3 additions & 3 deletions source/nanoFirmwareFlasher/EspTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ internal EspTool(
test.Open();
test.Close();
}
catch(IOException)
catch
{
// presume any IOException here is caused by the serial not existing or not possible to open
return;
// presume any exception here is caused by the serial not existing or not possible to open
throw new EspToolExecutionException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ internal class EspToolExecutionException : Exception
/// </summary>
public string ExecutionError;

public EspToolExecutionException() : base()
{

}

public EspToolExecutionException(string message) : base(message)
{
ExecutionError = message;
Expand Down
5 changes: 5 additions & 0 deletions source/nanoFirmwareFlasher/ExitCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public enum ExitCodes : int
[Display(Name = "Failed to read from ESP32 flash.")]
E4004 = 4004,

/// <summary>
/// Can't open COM port.
/// </summary>
[Display(Name = "Failed to open specified COM port.")]
E4005 = 4005,

////////////////////
// ST Link Errors //
Expand Down
20 changes: 15 additions & 5 deletions source/nanoFirmwareFlasher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,22 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
_exitCode = ExitCodes.E6001;
return;
}

EspTool espTool;

var espTool = new EspTool(
o.SerialPort,
o.BaudRate,
o.Esp32FlashMode,
o.Esp32FlashFrequency);
try
{
espTool = new EspTool(
o.SerialPort,
o.BaudRate,
o.Esp32FlashMode,
o.Esp32FlashFrequency);
}
catch(Exception)
{
_exitCode = ExitCodes.E4005;
return;
}

EspTool.DeviceInfo esp32Device;

Expand Down
17 changes: 14 additions & 3 deletions source/nanoFirmwareFlasher/StDfu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,12 @@ private static void EraseSector(
while (dfuStatus.bState != STATE_DFU_IDLE)
{
STDFU_ClrStatus(ref hDevice);
STDFU_GetStatus(ref hDevice, ref dfuStatus);
returnValue = STDFU_GetStatus(ref hDevice, ref dfuStatus);
}

if (returnValue != STDFU_NOERROR)
{
throw new DownloadException("STDFU_Dnload returned " + returnValue.ToString("X8"));
}
}
else
Expand Down Expand Up @@ -912,23 +917,29 @@ internal static void WriteBlock(
byte[] data,
uint blockNumber)
{
uint returnValue;
DfuStatus dfuStatus = new DfuStatus();

if (0 == blockNumber)
{
SetAddressPointer(hDevice, address);
}

STDFU_GetStatus(ref hDevice, ref dfuStatus);
returnValue = STDFU_GetStatus(ref hDevice, ref dfuStatus);
while (dfuStatus.bState != STATE_DFU_IDLE)
{
STDFU_ClrStatus(ref hDevice);
STDFU_GetStatus(ref hDevice, ref dfuStatus);
}

STDFU_Dnload(ref hDevice, data, (uint)data.Length, (ushort)(blockNumber + 2));
returnValue = STDFU_Dnload(ref hDevice, data, (uint)data.Length, (ushort)(blockNumber + 2));

STDFU_GetStatus(ref hDevice, ref dfuStatus);
if (dfuStatus.bState != STATE_DFU_DOWNLOAD_BUSY)
{
throw new DownloadException("STDFU_Dnload returned " + returnValue.ToString("X8"));
}

while (dfuStatus.bState != STATE_DFU_IDLE)
{
STDFU_ClrStatus(ref hDevice);
Expand Down
12 changes: 0 additions & 12 deletions source/nanoFirmwareFlasher/StmDfuDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,6 @@ public void FlashDfuFile(string filePath)
// grab data for write and store it into a 2048 byte buffer
byte[] buffer = dfuElement.Data.Skip((int)(_maxWriteBlockSize * blockNumber)).Take(_maxWriteBlockSize).ToArray();

if (buffer.Length < _maxWriteBlockSize)
{
var i = buffer.Length;
Array.Resize(ref buffer, _maxWriteBlockSize);

// Pad with 0xFF so our CRC matches the ST Bootloader and STLink's CRC
for (; i < _maxWriteBlockSize; i++)
{
buffer[i] = 0xFF;
}
}

StDfu.WriteBlock(_hDevice, dfuElement.Address, buffer, blockNumber);
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.11.0",
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.12.1",
"assemblyVersion": {
"precision": "revision"
},
Expand Down