Skip to content

Commit 0eaf0fc

Browse files
authored
Fix ESP32 revision parsing (#236)
1 parent dd8e67e commit 0eaf0fc

File tree

1 file changed

+82
-54
lines changed

1 file changed

+82
-54
lines changed

nanoFirmwareFlasher.Library/Esp32Operations.cs

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,25 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
145145
{
146146
if (esp32Device.ChipType == "ESP32")
147147
{
148+
// version schema for ESP32
149+
//Previously Used Schemes | Previous Identification | vM.X
150+
// V0 | 0 | v0.0
151+
// ECO, V1 | 1 | v1.0
152+
// ECO, V3 | 3 | v3.0
153+
148154
if (esp32Device.ChipName.Contains("PICO"))
149155
{
150156
targetName = "ESP32_PICO";
151157
}
152158
else
153159
{
154-
var revisionSuffix = "REV0";
160+
var revisionSuffix = "_REV0";
155161
var psRamSegment = "";
156162
var otherSegment = "";
157163

158-
if (esp32Device.ChipName.Contains("revision 3"))
164+
if (esp32Device.ChipName.Contains("revision v3"))
159165
{
160-
revisionSuffix = "REV3";
166+
revisionSuffix = "_REV3";
161167
}
162168

163169
if (esp32Device.PSRamAvailable == PSRamAvailability.Yes)
@@ -174,28 +180,51 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
174180
psRamSegment = "_PSRAM";
175181

176182
// also need to force rev0 even if that's higher
177-
revisionSuffix = "REV0";
183+
revisionSuffix = "_REV0";
178184
}
179185

180-
if (esp32Device.ChipName.Contains("ESP32_C3"))
186+
// compose target name
187+
targetName = $"ESP32{psRamSegment}{otherSegment}{revisionSuffix}";
188+
}
189+
190+
if (fitCheck)
191+
{
192+
if (targetName.EndsWith("REV3") &&
193+
(esp32Device.ChipName.Contains("revision v0") ||
194+
esp32Device.ChipName.Contains("revision v1") ||
195+
esp32Device.ChipName.Contains("revision v2")))
181196
{
182-
if (esp32Device.ChipName.Contains("revision 2"))
183-
{
184-
revisionSuffix = "REV2";
185-
}
186-
else
187-
{
188-
// all the others (rev3 and rev4) will take rev3
189-
revisionSuffix = "REV3";
190-
}
197+
// trying to use a target that's not compatible with the connected device
198+
Console.ForegroundColor = ConsoleColor.Yellow;
199+
Console.WriteLine("");
200+
Console.WriteLine("***************************************** WARNING ****************************************");
201+
Console.WriteLine("Seems that the firmware image that's about to be used is for a revision 3 device, but the");
202+
Console.WriteLine($"connected device is {esp32Device.ChipName}.");
203+
Console.WriteLine("******************************************************************************************");
204+
Console.WriteLine("");
191205
}
192206

193-
// compose target name
194-
targetName = $"ESP32{psRamSegment}{otherSegment}_{revisionSuffix}";
207+
if (targetName.Contains("BLE") &&
208+
!esp32Device.Features.Contains(", BT,"))
209+
{
210+
// trying to use a traget with BT and the connected device doens't have support for it
211+
Console.ForegroundColor = ConsoleColor.Yellow;
212+
Console.WriteLine("");
213+
Console.WriteLine("******************************************* WARNING *******************************************");
214+
Console.WriteLine("Seems that the firmware image that's about to be used includes Bluetooth features, but the");
215+
Console.WriteLine($"connected device does not have support for it. You should use a target without BLE in the name.");
216+
Console.WriteLine("************************************************************************************************");
217+
Console.WriteLine("");
218+
}
195219
}
196220
}
197221
else if (esp32Device.ChipType == "ESP32-S2")
198222
{
223+
// version schema for ESP32-S2
224+
//Previously Used Schemes | Previous Identification | vM.X
225+
// n/a | 0 | v0.0
226+
// ECO1 | 1 | v1.0
227+
199228
// can't guess with certainty for this series, better request a target name to the user
200229

201230
Console.ForegroundColor = ConsoleColor.Red;
@@ -211,16 +240,23 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
211240
}
212241
else if (esp32Device.ChipType == "ESP32-C3")
213242
{
243+
// version schema for ESP32-C3
244+
//Previously Used Schemes | Previous Identification | vM.X
245+
// Chip Revision 2 | 2 | v0.2
246+
// Chip Revision 3 | 3 | v0.3
247+
// Chip Revision 4 | 4 | v0.4
248+
214249
string revisionSuffix;
215250

216-
if (esp32Device.ChipName.Contains("revision 2"))
251+
if (esp32Device.ChipName.Contains("revision v0.2"))
217252
{
218-
revisionSuffix = "REV2";
253+
// this is the "default" one we're offering
254+
revisionSuffix = "";
219255
}
220-
else if (esp32Device.ChipName.Contains("revision 3") || esp32Device.ChipName.Contains("revision 4"))
256+
else if (esp32Device.ChipName.Contains("revision v0.3") || esp32Device.ChipName.Contains("revision v0.4"))
221257
{
222258
// all the others (rev3 and rev4) will take rev3
223-
revisionSuffix = "REV3";
259+
revisionSuffix = "_REV3";
224260
}
225261
else
226262
{
@@ -236,14 +272,37 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
236272
}
237273

238274
// compose target name
239-
targetName = $"ESP32_C3_{revisionSuffix}";
275+
targetName = $"ESP32_C3{revisionSuffix}";
240276
}
241277
else if (esp32Device.ChipType == "ESP32-S3")
242278
{
243-
// ESP32_S3 has only one revision
279+
// version schema for ESP32-S3
280+
//Previously Used Schemes | Previous Identification | vM.X
281+
// V001 | 0 (bug in logs) | v0.1
282+
// V002 | n/a | v0.2
283+
284+
string revisionSuffix;
285+
286+
// so far we are only offering a single ESP32_S3 build
287+
if (esp32Device.ChipName.Contains("revision 0.1") || esp32Device.ChipName.Contains("revision 0.2"))
288+
{
289+
revisionSuffix = "";
290+
}
291+
else
292+
{
293+
Console.ForegroundColor = ConsoleColor.Red;
294+
295+
Console.WriteLine("");
296+
Console.WriteLine($"Unsupported ESP32_S3 revision.");
297+
Console.WriteLine("");
298+
299+
Console.ForegroundColor = ConsoleColor.White;
300+
301+
return ExitCodes.E9000;
302+
}
244303

245304
// compose target name
246-
targetName = $"ESP32_S3";
305+
targetName = $"ESP32_S3{revisionSuffix}";
247306
}
248307

249308
Console.ForegroundColor = ConsoleColor.Blue;
@@ -255,37 +314,6 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
255314
Console.ForegroundColor = ConsoleColor.White;
256315
}
257316

258-
if (fitCheck)
259-
{
260-
if (targetName.EndsWith("REV3") &&
261-
(esp32Device.ChipName.Contains("revision 0") ||
262-
esp32Device.ChipName.Contains("revision 1") ||
263-
esp32Device.ChipName.Contains("revision 2")))
264-
{
265-
// trying to use a target that's not compatible with the connected device
266-
Console.ForegroundColor = ConsoleColor.Yellow;
267-
Console.WriteLine("");
268-
Console.WriteLine("***************************************** WARNING ****************************************");
269-
Console.WriteLine("Seems that the firmware image that's about to be used is for a revision 3 device, but the");
270-
Console.WriteLine($"connected device is {esp32Device.ChipName}.");
271-
Console.WriteLine("******************************************************************************************");
272-
Console.WriteLine("");
273-
}
274-
275-
if (targetName.Contains("BLE") &&
276-
!esp32Device.Features.Contains(", BT,"))
277-
{
278-
// trying to use a traget with BT and the connected device doens't have support for it
279-
Console.ForegroundColor = ConsoleColor.Yellow;
280-
Console.WriteLine("");
281-
Console.WriteLine("******************************************* WARNING *******************************************");
282-
Console.WriteLine("Seems that the firmware image that's about to be used includes Bluetooth features, but the");
283-
Console.WriteLine($"connected device does not have support for it. You should use a target without BLE in the name.");
284-
Console.WriteLine("************************************************************************************************");
285-
Console.WriteLine("");
286-
}
287-
}
288-
289317
Esp32Firmware firmware = new Esp32Firmware(
290318
targetName,
291319
fwVersion,

0 commit comments

Comments
 (0)