Skip to content

Commit fb147f0

Browse files
authored
Fix deployment operation for ESP32 (#93)
1 parent f3263fb commit fb147f0

File tree

5 files changed

+36
-49
lines changed

5 files changed

+36
-49
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,21 @@ nanoff --platform esp32 --serialport COM31 --devicedetails
138138

139139
### Deploy a managed application to an ESP32 target
140140

141-
To deploy a managed application to an ESP32_PSRAM_REV0 target connected to COM31, which has the deployment region at 0x190000 flash address.
141+
To deploy a managed application to an ESP32_PSRAM_REV0 target connected to COM31.
142142

143143
>Note: The binary file with the deployment image can be found on the Release or Debug folder of a Visual Studio project after a successful build. This file contains everything that's required to deploy a managed application to a target (meaning application executable and all referenced libraries and assemblies).
144144
145145
```console
146-
nanoff --target ESP32_PSRAM_REV0 --serialport COM12 --deploy --image "E:\GitHub\nf-Samples\samples\Blinky\Blinky\bin\Debug\Blinky.bin" --address 0x190000
146+
nanoff --target ESP32_PSRAM_REV0 --serialport COM12 --deploy --image "E:\GitHub\nf-Samples\samples\Blinky\Blinky\bin\Debug\Blinky.bin"
147147
```
148148

149149
### Update the firmware of an ESP32 target along with a managed application
150150

151-
To update the firmware of an ESP32 target connected to COM31, to the latest available development version.
152-
You have to specify the path to the managed application.
153-
This example uses the binary format file that was saved on a previous backup operation.
151+
To deploy an application on an ESP32 target connected to COM31, with your application, you have to specify the path to the managed application. Optionally you can provide an address which will override the default deployment address.
152+
This example uses the binary format file that you can find when you are building an application. Note, as only application can run, when you are building a library, a bin file is not created automatically. Only for applications.
154153

155154
```console
156-
nanoff --update --target ESP32_PSRAM_REV0 --serialport COM31 --deployment "c:\eps32-backups\my_awesome_app.bin"
155+
nanoff --target ESP32_PSRAM_REV0 --update --serialport COM31 --deploy --image "c:\eps32-backups\my_awesome_app.bin" --address 0x1B000
157156
```
158157

159158
## STMP32 usage examples

nanoFirmwareFlasher/Esp32Firmware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ internal class Esp32Firmware : FirmwarePackage
3333
internal PartitionTableSize? _partitionTableSize;
3434

3535
/// <summary>
36-
/// Address of the deployment partition.
36+
/// Default address of the deployment partition.
3737
/// </summary>
38-
internal int DeploymentPartitionAddress => 0x110000;
38+
internal int DeploymentPartitionAddress => 0x1B0000;
3939

4040
public Esp32Firmware(
4141
string targetName,

nanoFirmwareFlasher/Esp32Operations.cs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
251251
// check application file
252252
if (File.Exists(applicationPath))
253253
{
254-
if (!updateFw)
254+
// this operation includes a deployment image
255+
// try parsing the deployment address from parameter, if provided
256+
if (!string.IsNullOrEmpty(deploymentAddress))
255257
{
256-
// this is a deployment operation only
257-
// try parsing the deployment address from parameter
258258
// need to remove the leading 0x and to specify that hexadecimal values are allowed
259259
if (!uint.TryParse(deploymentAddress.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.InvariantCulture, out address))
260260
{
@@ -263,10 +263,12 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
263263
}
264264

265265
string applicationBinary = new FileInfo(applicationPath).FullName;
266+
267+
// add DEPLOYMENT partition with the address provided in the command OR the address from the partition table
266268
firmware.FlashPartitions = new Dictionary<int, string>()
267269
{
268270
{
269-
updateFw ? firmware.DeploymentPartitionAddress : (int)address,
271+
address != 0 ? (int)address : firmware.DeploymentPartitionAddress,
270272
applicationBinary
271273
}
272274
};
@@ -277,44 +279,35 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
277279
}
278280
}
279281

280-
if (verbosity >= VerbosityLevel.Normal)
281-
{
282-
Console.ForegroundColor = ConsoleColor.White;
283-
Console.WriteLine($"Erasing flash...");
284-
}
285-
286282
if (updateFw)
287283
{
284+
// updating fw calls for a flash erase
285+
if (verbosity >= VerbosityLevel.Normal)
286+
{
287+
Console.ForegroundColor = ConsoleColor.White;
288+
Console.WriteLine($"Erasing flash...");
289+
}
290+
288291
// erase flash
289292
operationResult = espTool.EraseFlash();
290-
}
291-
else
292-
{
293-
// erase flash segment
294-
295-
// need to get deployment address here
296-
// length must both be multiples of the SPI flash erase sector size. This is 0x1000 (4096) bytes for supported flash chips.
297-
298-
var fileStream = File.OpenRead(firmware.BootloaderPath);
299293

300-
uint fileLength = (uint)Math.Ceiling((decimal)fileStream.Length / 0x1000) * 0x1000;
301-
302-
operationResult = espTool.EraseFlashSegment(address, fileLength);
294+
if (operationResult == ExitCodes.OK)
295+
{
296+
if (verbosity >= VerbosityLevel.Normal)
297+
{
298+
Console.ForegroundColor = ConsoleColor.Green;
299+
Console.WriteLine("OK");
300+
}
301+
else
302+
{
303+
Console.WriteLine("");
304+
}
305+
}
303306
}
304307

305308
if (operationResult == ExitCodes.OK)
306309
{
307-
if (verbosity >= VerbosityLevel.Normal)
308-
{
309-
Console.ForegroundColor = ConsoleColor.Green;
310-
Console.WriteLine("OK");
311-
}
312-
else
313-
{
314-
Console.WriteLine("");
315-
}
316-
317-
Console.ForegroundColor = ConsoleColor.White;
310+
Console.ForegroundColor = ConsoleColor.White;
318311

319312
if (verbosity >= VerbosityLevel.Normal)
320313
{

nanoFirmwareFlasher/Program.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,13 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
449449
if (o.Deploy)
450450
{
451451
// need to take care of flash address
452-
string appFlashAddress = null;
452+
string appFlashAddress = string.Empty;
453453

454454
if (o.FlashAddress.Any())
455455
{
456456
// take the first address, it should be the only one valid
457457
appFlashAddress = o.FlashAddress.ElementAt(0);
458458
}
459-
else
460-
{
461-
_exitCode = ExitCodes.E9009;
462-
return;
463-
}
464459

465460
// this to flash a deployment image without updating the firmware
466461
try
@@ -469,7 +464,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
469464
_exitCode = await Esp32Operations.UpdateFirmwareAsync(
470465
espTool,
471466
esp32Device,
472-
null,
467+
o.TargetName,
473468
false,
474469
null,
475470
false,

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "1.28",
3+
"version": "1.29",
44
"assemblyVersion": {
55
"precision": "minor"
66
},

0 commit comments

Comments
 (0)