Skip to content

Commit fad8fa2

Browse files
authored
Add support to flash ESP32 with a local CLR image (#57)
1 parent 3ab664d commit fad8fa2

File tree

8 files changed

+90
-18
lines changed

8 files changed

+90
-18
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ The tool includes help for all available commands. You can see a list of all ava
5858
nanoff --help
5959
```
6060

61+
## ESP32 usage examples
62+
6163
### Update the firmware of an ESP32_WROOM_32 target
6264

6365
To update the firmware of an ESP32_WROOM_32 target connected to COM31, to the latest available development version.
@@ -66,6 +68,15 @@ To update the firmware of an ESP32_WROOM_32 target connected to COM31, to the la
6668
nanoff --update --target ESP32_WROOM_32 --serialport COM31
6769
```
6870

71+
### Update the firmware of an ESP32_WROOM_32 target with a local CLR file
72+
73+
To update the firmware of an ESP32_WROOM_32 target connected to COM31 with a local CLR file (for example from a build).
74+
This file has to be a binary file with a valid CLR from a build. No other checks or validations are performed on the file content.
75+
76+
```console
77+
nanoff --update --target ESP32_WROOM_32 --serialport COM31 --clrfile "C:\nf-interpreter\build\nanoCLR.bin"
78+
```
79+
6980
### Deploy a managed application to an ESP32_WROOM_32 target
7081

7182
To deploy a managed application to an ESP32_WROOM_32 target connected to COM31, which has the deployment region at 0x190000 flash address.
@@ -86,6 +97,8 @@ This example uses the binary format file that was saved on a previous backup ope
8697
nanoff --update --target ESP32_WROOM_32 --serialport COM31 --deployment "c:\eps32-backups\my_awesome_app.bin"
8798
```
8899

100+
## STMP32 usage examples
101+
89102
### Update the firmware of a specific STM32 target
90103

91104
To update the firmware of the ST_STM32F769I_DISCOVERY target to the latest available stable version using the JTAG connection.
@@ -146,6 +159,8 @@ To install the drivers for STM32 DFU connected targets.
146159
nanoff --installdfudrivers
147160
```
148161

162+
## TI CC13x2 usage examples
163+
149164
### Update the firmware of a specific TI CC13x2 target
150165

151166
To update the firmware of the TI_CC1352R1_LAUNCHXL target to the latest preview version.

nanoFirmwareFlasher/Esp32Firmware.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ namespace nanoFramework.Tools.FirmwareFlasher
1616
/// </summary>
1717
internal class Esp32Firmware : FirmwarePackage
1818
{
19+
/// <summary>
20+
/// Address of the CLR partition.
21+
/// </summary>
22+
public const int CLRAddress = 0x10000;
23+
1924
/// <summary>
2025
/// ESP32 nanoCLR is available for 2MB, 4MB, 8MB and 16MB flash sizes
2126
/// </summary>
@@ -80,7 +85,7 @@ internal async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync(in
8085
{ 0x1000, Path.Combine(LocationPath, BootloaderPath) },
8186

8287
// nanoCLR goes to 0x10000
83-
{ 0x10000, Path.Combine(LocationPath, "nanoCLR.bin") },
88+
{ CLRAddress, Path.Combine(LocationPath, "nanoCLR.bin") },
8489

8590
// partition table goes to 0x8000; there are partition tables for 2MB, 4MB, 8MB and 16MB flash sizes
8691
{ 0x8000, Path.Combine(LocationPath, $"partitions_{humanReadable.ToLowerInvariant()}.bin") }

nanoFirmwareFlasher/Esp32Operations.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
9292
bool preview,
9393
string applicationPath,
9494
string deploymentAddress,
95-
PartitionTableSize? partitionTableSize,
96-
VerbosityLevel verbosity)
95+
string clrFile,
96+
VerbosityLevel verbosity,
97+
PartitionTableSize? partitionTableSize)
9798
{
9899
var operationResult = ExitCodes.OK;
99100
uint address = 0;
101+
bool updateCLRfile = !string.IsNullOrEmpty(clrFile);
100102

101103
// if a target name wasn't specified use the default (and only available) ESP32 target
102104
if (string.IsNullOrEmpty(targetName))
@@ -113,17 +115,46 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
113115
Verbosity = verbosity
114116
};
115117

118+
// if this is updating with a local CLR file, download the package silently
119+
if (updateCLRfile)
120+
{
121+
// check file
122+
if (!File.Exists(clrFile))
123+
{
124+
return ExitCodes.E9011;
125+
}
126+
127+
// has to be a binary file
128+
if (Path.GetExtension(clrFile) != ".bin")
129+
{
130+
return ExitCodes.E9012;
131+
}
132+
133+
firmware.Verbosity = VerbosityLevel.Quiet;
134+
}
135+
116136
// need to download update package?
117137
if (updateFw)
118138
{
119139
operationResult = await firmware.DownloadAndExtractAsync(esp32Device.FlashSize);
140+
120141
if (operationResult != ExitCodes.OK)
121142
{
122143
return operationResult;
123144
}
124145
// download successful
125146
}
126147

148+
// if updating with a CRL file, need to have a new fw package
149+
if(updateCLRfile)
150+
{
151+
// remove the CLR file from the image
152+
firmware.FlashPartitions.Remove(Esp32Firmware.CLRAddress);
153+
154+
// add it back with the file image from the command line option
155+
firmware.FlashPartitions.Add(Esp32Firmware.CLRAddress, clrFile);
156+
}
157+
127158
// need to include application file?
128159
if (!string.IsNullOrEmpty(applicationPath))
129160
{
@@ -197,7 +228,7 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
197228

198229
if (verbosity >= VerbosityLevel.Normal)
199230
{
200-
Console.Write($"Flashing firmware...");
231+
Console.WriteLine($"Flashing firmware...");
201232
}
202233

203234
// write to flash

nanoFirmwareFlasher/EspTool.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,6 @@ internal ExitCodes EraseFlash()
302302
throw new EraseEsp32FlashException(messages);
303303
}
304304

305-
if (Verbosity >= VerbosityLevel.Detailed)
306-
{
307-
Console.WriteLine(match.Groups["message"].ToString().Trim());
308-
}
309-
310305
return ExitCodes.OK;
311306
}
312307

nanoFirmwareFlasher/ExitCodes.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,17 @@ public enum ExitCodes
242242
/// </summary>
243243
[Display(Name = "Couldn't find any device connected.")]
244244
E9010 = 9010,
245+
246+
/// <summary>
247+
/// Couldn't find CLR image file. Check the path.
248+
/// </summary>
249+
[Display(Name = "Couldn't find CLR image file. Check the path.")]
250+
E9011 = 9011,
251+
252+
/// <summary>
253+
/// CLR image file has wrong format. It has to be a binary file.
254+
/// </summary>
255+
[Display(Name = "CLR image file has wrong format.It has to be a binary file.")]
256+
E9012 = 9012,
245257
}
246258
}

nanoFirmwareFlasher/FirmwarePackage.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,12 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
365365
}
366366
}
367367

368-
Console.ForegroundColor = ConsoleColor.Yellow;
369-
Console.WriteLine($"Updating to {Version}");
370-
Console.ForegroundColor = ConsoleColor.White;
368+
if (Verbosity >= VerbosityLevel.Normal)
369+
{
370+
Console.ForegroundColor = ConsoleColor.Yellow;
371+
Console.WriteLine($"Updating to {Version}");
372+
Console.ForegroundColor = ConsoleColor.White;
373+
}
371374

372375
return ExitCodes.OK;
373376
}

nanoFirmwareFlasher/Options.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,18 @@ public class Options
139139
Default = null,
140140
HelpText = "Partition table size to use. Valid sizes are: 2, 4, 8 and 16.")]
141141
public PartitionTableSize? Esp32PartitionTableSize { get; set; }
142+
143+
[Option(
144+
"clrfile",
145+
Required = false,
146+
Default = null,
147+
HelpText = "Path to file with CLR image. Partitions table and bootloader file will be automatically flashed to the device.")]
148+
public string Esp32ClrFile { get; set; }
149+
142150
#endregion
143151

144152

145-
# region TI options
153+
#region TI options
146154

147155

148156
[Option(

nanoFirmwareFlasher/Program.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
237237
!string.IsNullOrEmpty(o.SerialPort) ||
238238
(o.BaudRate != 921600) ||
239239
(o.Esp32FlashMode != "dio") ||
240-
(o.Esp32FlashFrequency != 40))
240+
(o.Esp32FlashFrequency != 40) ||
241+
!string.IsNullOrEmpty(o.Esp32ClrFile))
241242
{
242243
o.Platform = "esp32";
243244
}
@@ -361,8 +362,9 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
361362
o.Preview,
362363
o.DeploymentImage,
363364
null,
364-
o.Esp32PartitionTableSize,
365-
_verbosityLevel);
365+
o.Esp32ClrFile,
366+
_verbosityLevel,
367+
o.Esp32PartitionTableSize);
366368

367369
if (_exitCode != ExitCodes.OK)
368370
{
@@ -421,8 +423,9 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
421423
false,
422424
o.DeploymentImage,
423425
appFlashAddress,
424-
o.Esp32PartitionTableSize,
425-
_verbosityLevel);
426+
null,
427+
_verbosityLevel,
428+
o.Esp32PartitionTableSize);
426429

427430
if (_exitCode != ExitCodes.OK)
428431
{

0 commit comments

Comments
 (0)