Skip to content

Commit 62e2d95

Browse files
authored
Improvements in ESP32 flash write operations (#163)
1 parent fadf470 commit 62e2d95

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

nanoFirmwareFlasher.Library/EspTool.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ internal ExitCodes WriteFlash(
466466
var regexPattern = new StringBuilder();
467467
int counter = 1;
468468
var regexGroupNames = new List<string>();
469+
string flashFreqParam;
469470

470471
foreach (var part in partsToWrite)
471472
{
@@ -485,9 +486,22 @@ internal ExitCodes WriteFlash(
485486
_ => "detect",
486487
};
487488

489+
// process flash frequency
490+
if (_flashFrequency == -1)
491+
{
492+
// no flash frequency was requested on the CLI options
493+
// defaulting to 'keep' to make this work with image files with checksum
494+
flashFreqParam = "keep";
495+
}
496+
else
497+
{
498+
// compose option for flash freq para
499+
flashFreqParam = $"{_flashFrequency}m";
500+
}
501+
488502
// execute write_flash command and parse the result; progress message can be found be searching for linefeed
489503
if (!RunEspTool(
490-
$"write_flash --flash_mode {_flashMode} --flash_freq {_flashFrequency}m --flash_size {flashSize} {partsArguments.ToString().Trim()}",
504+
$"write_flash --flash_mode {_flashMode} --flash_freq {flashFreqParam} --flash_size {flashSize} {partsArguments.ToString().Trim()}",
491505
false,
492506
useStandardBaudrate,
493507
true,
@@ -623,7 +637,7 @@ private bool RunEspTool(
623637
if (!espTool.Start())
624638
{
625639
throw new EspToolExecutionException("Error starting esptool!");
626-
}
640+
}
627641

628642
var messageBuilder = new StringBuilder();
629643

nanoFirmwareFlasher.Tool/Options.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ public class Options
108108
[Option(
109109
"flashmode",
110110
Required = false,
111-
Default = "dio",
111+
Default = "keep",
112112
HelpText = "Flash mode to use.")]
113113
public string Esp32FlashMode { get; set; }
114114

115115
[Option(
116116
"flashfreq",
117117
Required = false,
118-
Default = 40,
118+
Default = -1,
119119
HelpText = "Flash frequency to use [MHz].")]
120120
public int Esp32FlashFrequency { get; set; }
121121

0 commit comments

Comments
 (0)