Skip to content

Commit

Permalink
Merge branch 'main' into test-pipeline-build
Browse files Browse the repository at this point in the history
  • Loading branch information
networkfusion committed Jun 14, 2024
2 parents a13595f + 0d2f7b4 commit 0b69689
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 86 deletions.
3 changes: 0 additions & 3 deletions nanoFirmwareFlasher.Library/CC13x26x2Firmware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// See LICENSE file in the project root for full license information.
//

using System.IO;
using System.Linq;

namespace nanoFramework.Tools.FirmwareFlasher
{
/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions nanoFirmwareFlasher.Library/CC13x26x2Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace nanoFramework.Tools.FirmwareFlasher
{
Expand Down Expand Up @@ -119,15 +118,15 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(

ExitCodes programResult = ExitCodes.OK;
// write HEX files to flash
if (filesToFlash.Any(f => f.EndsWith(".hex")))
if (filesToFlash.Exists(f => f.EndsWith(".hex")))
{
programResult = ccDevice.FlashHexFiles(filesToFlash);
}

if (programResult == ExitCodes.OK && isApplicationBinFile)
{
// now program the application file
programResult = ccDevice.FlashBinFiles(new[] { applicationPath }, new[] { deploymentAddress });
programResult = ccDevice.FlashBinFiles([applicationPath], [deploymentAddress]);
}

if (updateFw)
Expand Down
2 changes: 1 addition & 1 deletion nanoFirmwareFlasher.Library/Esp32Firmware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class Esp32Firmware : FirmwarePackage
/// <summary>
/// ESP32 nanoCLR is available for 2MB, 4MB, 8MB and 16MB flash sizes
/// </summary>
private List<int> SupportedFlashSizes => new() { 0x200000, 0x400000, 0x800000, 0x1000000 };
private List<int> SupportedFlashSizes => [0x200000, 0x400000, 0x800000, 0x1000000];

internal string BootloaderPath;

Expand Down
5 changes: 2 additions & 3 deletions nanoFirmwareFlasher.Library/Esp32Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(

int configPartitionAddress = 0;
int configPartitionSize = 0;
string configPartitionBackup = Path.GetTempFileName();
string configPartitionBackup = Path.GetRandomFileName();

// if mass erase wasn't requested, backup config partitition
if (!massErase)
Expand Down Expand Up @@ -613,7 +613,6 @@ public static async System.Threading.Tasks.Task<ExitCodes> DeployApplicationAsyn
VerbosityLevel verbosity,
PartitionTableSize? partitionTableSize)
{
var operationResult = ExitCodes.OK;
uint address = 0;

// perform sanity checks for the specified target against the connected device details
Expand Down Expand Up @@ -688,7 +687,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> DeployApplicationAsyn
}

// write to flash
operationResult = espTool.WriteFlash(firmware.FlashPartitions);
ExitCodes operationResult = espTool.WriteFlash(firmware.FlashPartitions);

if (operationResult == ExitCodes.OK)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using nanoFramework.Tools.Debugger;
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

using nanoFramework.Tools.Debugger;
using nanoFramework.Tools.Debugger.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Text;
using System.Threading.Tasks;

namespace nanoFramework.Tools.FirmwareFlasher.FileDeployment
Expand All @@ -16,9 +17,9 @@ namespace nanoFramework.Tools.FirmwareFlasher.FileDeployment
/// </summary>
public class FileDeploymentManager
{
private FileDeploymentConfiguration _configuration;
private VerbosityLevel _verbosity;
private string _serialPort;
private readonly FileDeploymentConfiguration _configuration;
private readonly VerbosityLevel _verbosity;
private readonly string _serialPort;

/// <summary>
/// Creates an instance of FileDeploymentManager.
Expand Down
4 changes: 2 additions & 2 deletions nanoFirmwareFlasher.Library/FirmwarePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static List<CloudSmithPackageDetail> GetTargetList(
// Because new stable releases are published on a regular basis and preview very rarely, we query for stable versions published in past month and preview versions published during the past 6 months.
string requestUri = $"{repoName}/?page_size=500&q=uploaded:'>{(preview ? "6" : "1")} month ago' {(platform.HasValue ? "AND tag:" + platform.Value : "")}";

List<CloudSmithPackageDetail> targetPackages = new();
List<CloudSmithPackageDetail> targetPackages = [];

if (verbosity > VerbosityLevel.Normal)
{
Expand Down Expand Up @@ -246,7 +246,7 @@ internal async Task<ExitCodes> DownloadAndExtractAsync()
return ExitCodes.E9006;
}

List<FileInfo> fwFiles = new();
List<FileInfo> fwFiles = [];

if (_preview)
{
Expand Down
2 changes: 1 addition & 1 deletion nanoFirmwareFlasher.Library/JLinkDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static List<string> ListDevices()
if (jlinkMatches.Count == 0)
{
// no J-Link probe found
return new List<string>();
return [];
}

return jlinkMatches.Cast<Match>().Select(i => i.Value).ToList();
Expand Down
8 changes: 4 additions & 4 deletions nanoFirmwareFlasher.Library/JLinkOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
}

// setup files to flash
var filesToFlash = new List<string>();
List<string> filesToFlash = [];

if (updateFw)
{
Expand Down Expand Up @@ -153,15 +153,15 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
jlinkDevice.Verbosity = verbosity;

// write HEX files to flash
if (filesToFlash.Any(f => f.EndsWith(".hex")))
if (filesToFlash.Exists(f => f.EndsWith(".hex")))
{
operationResult = jlinkDevice.FlashHexFiles(filesToFlash);
}

if (operationResult == ExitCodes.OK && isApplicationBinFile)
{
// now program the application file
operationResult = jlinkDevice.FlashBinFiles(new[] { applicationPath }, new[] { deploymentAddress });
operationResult = jlinkDevice.FlashBinFiles([applicationPath], [deploymentAddress]);
}

return operationResult;
Expand All @@ -178,7 +178,7 @@ public static ExitCodes MassErase(
VerbosityLevel verbosity)
{
// J-Link device
JLinkDevice jlinkDevice = new JLinkDevice(probeId);
JLinkDevice jlinkDevice = new(probeId);

if (!jlinkDevice.DevicePresent)
{
Expand Down
7 changes: 0 additions & 7 deletions nanoFirmwareFlasher.Library/NanoDeviceOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ public ExitCodes GetDeviceDetails(
// report issue
throw new CantConnectToNanoDeviceException("Couldn't connect to specified nano device.");
}

if (nanoDevice is null)
{
throw new ArgumentNullException(nameof(nanoDevice));
}

return ExitCodes.E2000;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions nanoFirmwareFlasher.Library/Stm32Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
if (operationResult == ExitCodes.OK && isApplicationBinFile)
{
// now program the application file
operationResult = dfuDevice.FlashBinFiles(new[] { applicationPath }, new[] { deploymentAddress });
operationResult = dfuDevice.FlashBinFiles([applicationPath], [deploymentAddress]);
}

if (
Expand Down Expand Up @@ -282,7 +282,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
if (operationResult == ExitCodes.OK && isApplicationBinFile)
{
// now program the application file
operationResult = jtagDevice.FlashBinFiles(new[] { applicationPath }, new[] { deploymentAddress });
operationResult = jtagDevice.FlashBinFiles([applicationPath], [deploymentAddress]);
}

if (
Expand Down
2 changes: 1 addition & 1 deletion nanoFirmwareFlasher.Library/StmDfuDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public ExitCodes StartExecution(string startAddress)
if (dfuMatches.Count == 0)
{
// no DFU device found
return new List<(string serial, string device)>();
return [];
}

return dfuMatches.Cast<Match>().Select(i => (serial: i.Groups["serial"].Value, device: i.Groups["device"].Value)).ToList();
Expand Down
2 changes: 1 addition & 1 deletion nanoFirmwareFlasher.Library/StmJtagDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static List<string> ListDevices()
if (jtagMatches.Count == 0)
{
// no JTAG found
return new List<string>();
return [];
}

return jtagMatches.Cast<Match>().Select(i => i.Value).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>library</OutputType>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>latest</LangVersion>
<RootNamespace>nanoFramework.Tools.FirmwareFlasher</RootNamespace>
Expand Down
18 changes: 3 additions & 15 deletions nanoFirmwareFlasher.Library/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
"contentHash": "okurQJO6NRE/apDIP23ajJ0hpiNmJ+f0BwOlB/cSqTLQlw5upkf+5+96+iG2Jw40G1fCVCyPz/FhIABUjMR+RQ=="
}
},
"net6.0": {
"net8.0": {
"Microsoft.ApplicationInsights": {
"type": "Direct",
"requested": "[2.22.0, )",
Expand Down Expand Up @@ -413,10 +413,7 @@
"Microsoft.Extensions.Primitives": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g==",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
}
"contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g=="
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
Expand Down Expand Up @@ -1016,11 +1013,6 @@
"Microsoft.NETCore.Targets": "1.1.0"
}
},
"System.Runtime.CompilerServices.Unsafe": {
"type": "Transitive",
"resolved": "6.0.0",
"contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg=="
},
"System.Runtime.Extensions": {
"type": "Transitive",
"resolved": "4.3.0",
Expand Down Expand Up @@ -1247,17 +1239,13 @@
"System.Text.Encodings.Web": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ==",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
}
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
},
"System.Text.Json": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "OdrZO2WjkiEG6ajEFRABTRCi/wuXQPxeV6g8xvUJqdxMvvuCCEk86zPla8UiIQJz3durtUEbNyY/3lIhS0yZvQ==",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0",
"System.Text.Encodings.Web": "8.0.0"
}
},
Expand Down
5 changes: 2 additions & 3 deletions nanoFirmwareFlasher.Tool/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ public class Options

[Usage(ApplicationAlias = "nanoff")]
public static IEnumerable<Example> Examples =>
new List<Example>
{
[
new("- Update ESP32 WROVER Kit device with latest available firmware", new Options { TargetName = "ESP_WROVER_KIT", Update = true }),
new("- Update specific STM32 device (ST_STM32F769I_DISCOVERY) with latest available firmware, using JTAG interface", new Options { TargetName = "ST_STM32F769I_DISCOVERY" , Update = true, JtagUpdate = true}),
new("- Update ESP32 device with latest available firmware (stable version), device is connected to COM31", new Options { Platform = SupportedPlatform.esp32, Update = true, SerialPort = "COM31" }),
Expand All @@ -364,6 +363,6 @@ public class Options
new("- Install STM32 JTAG drivers", new Options { InstallJtagDrivers = true}),
new("- List all available STM32 targets", new Options { ListTargets = true, Platform = SupportedPlatform.stm32 }),
new("- List all available COM ports", new Options { ListComPorts = true }),
};
];
}
}
10 changes: 4 additions & 6 deletions nanoFirmwareFlasher.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ internal class Program
private static CopyrightInfo _copyrightInfo;
private static NanoDeviceOperations _nanoDeviceOperations;

internal static string ExecutingPath;

public static async Task<int> Main(string[] args)
{
// take care of static fields
Expand All @@ -49,7 +47,7 @@ public static async Task<int> Main(string[] args)
// need this to be able to use ProcessStart at the location where the .NET Core CLI tool is running from
string codeBase = Assembly.GetExecutingAssembly().Location;
var fullPath = Path.GetFullPath(codeBase);
ExecutingPath = Path.GetDirectoryName(fullPath);
var ExecutingPath = Path.GetDirectoryName(fullPath);

// grab AppInsights connection string to setup telemetry client
IConfigurationRoot appConfigurationRoot = new ConfigurationBuilder()
Expand All @@ -67,7 +65,7 @@ public static async Task<int> Main(string[] args)
// because of short-comings in CommandLine parsing
// need to customize the output to provide a consistent output
var parser = new Parser(config => config.HelpWriter = null);
var result = parser.ParseArguments<Options>(new[] { "", "" });
var result = parser.ParseArguments<Options>(new string[] { "", "" });

var helpText = new HelpText(
new HeadingInfo(_headerInfo),
Expand Down Expand Up @@ -309,7 +307,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
{
var connectedDevices = _nanoDeviceOperations.ListDevices(_verbosityLevel > VerbosityLevel.Normal);

if (connectedDevices.Count() == 0)
if (!connectedDevices.Any())
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("No devices found");
Expand Down Expand Up @@ -692,7 +690,7 @@ private static void DisplayNoOperationMessage()
// because of short-comings in CommandLine parsing
// need to customize the output to provide a consistent output
var parser = new Parser(config => config.HelpWriter = null);
var result = parser.ParseArguments<Options>(new[] { "", "" });
var result = parser.ParseArguments<Options>(new string[] { "", "" });

var helpText = new HelpText(
new HeadingInfo(_headerInfo),
Expand Down
2 changes: 1 addition & 1 deletion nanoFirmwareFlasher.Tool/SilabsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<ExitCodes> ProcessAsync()
else if (!string.IsNullOrEmpty(_options.DeploymentImage) && _options.Deploy)
{
var exitCode = jlinkDevice.FlashBinFiles(
new List<string>() { _options.DeploymentImage },
[_options.DeploymentImage],
_options.FlashAddress);

if (exitCode != ExitCodes.OK)
Expand Down
7 changes: 3 additions & 4 deletions nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PackageIconUrl></PackageIconUrl>
<Description>.NET nanoFirmwareFlasher tool to flash firmware images to target devices.</Description>
<!-- need this to allow async Main() -->
<LangVersion>latest</LangVersion>
<PackAsTool>true</PackAsTool>
<PlatformTarget>AnyCPU</PlatformTarget>
<Platforms>AnyCPU;x64</Platforms>
Expand All @@ -29,7 +28,7 @@
</PropertyGroup>

<PropertyGroup Condition="$(VSCodeExtensionBuild) == '' or $(VSCodeExtensionBuild) == 'False'">
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="$(VSCodeExtensionBuild) == 'True'">
<TargetFrameworks>net472</TargetFrameworks>
Expand Down Expand Up @@ -87,8 +86,8 @@
</Target>

<PropertyGroup>
<!-- set this to 'net6.0\' to package contents in this TFM folder -->
<PackageTfmSubFolder>net6.0\</PackageTfmSubFolder>
<!-- set this to 'net8.0\' to package contents in this TFM folder -->
<PackageTfmSubFolder>net8.0\</PackageTfmSubFolder>
</PropertyGroup>

<Import Project="..\nanoFirmwareFlasher.Library\nugetcontent.targets" />
Expand Down
Loading

0 comments on commit 0b69689

Please sign in to comment.