Skip to content

Commit 1019b5a

Browse files
authored
Add support for ESP32-C3 (#167)
1 parent 4467ff7 commit 1019b5a

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

nanoFirmwareFlasher.Library/Esp32Firmware.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ public Esp32Firmware(
5050
_partitionTableSize = partitionTableSize;
5151
}
5252

53-
internal async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync(int flashSize)
53+
internal async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync(Esp32DeviceInfo deviceInfo)
5454
{
55+
int flashSize = deviceInfo.FlashSize;
56+
5557
if (_partitionTableSize is not null)
5658
{
5759
// if specified, partition table size overrides flash size.
@@ -64,7 +66,7 @@ internal async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync(in
6466
{
6567
if (Verbosity >= VerbosityLevel.Detailed)
6668
{
67-
Console.WriteLine($"There is no firmware available for ESP32 with {Esp32DeviceInfo.GetFlashSizeAsString(flashSize)} flash size!{Environment.NewLine}Only the following flash sizes are supported: {string.Join(", ", SupportedFlashSizes.Select(size => size >= 0x10000 ? $"{ size / 0x100000 }MB" : $"{ size / 0x400 }kB."))}");
69+
Console.WriteLine($"There is no firmware available for ESP32 with {Esp32DeviceInfo.GetFlashSizeAsString(flashSize)} flash size!{Environment.NewLine}Only the following flash sizes are supported: {string.Join(", ", SupportedFlashSizes.Select(size => size >= 0x10000 ? $"{size / 0x100000}MB" : $"{size / 0x400}kB."))}");
6870
}
6971

7072
return ExitCodes.E4001;
@@ -80,8 +82,8 @@ internal async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync(in
8082
// get ESP32 partitions
8183
FlashPartitions = new Dictionary<int, string>
8284
{
83-
// bootloader goes to 0x1000
84-
{ 0x1000, Path.Combine(LocationPath, BootloaderPath) },
85+
// bootloader goes to 0x1000, except for ESP32_C3 which goes to 0x0
86+
{ deviceInfo.ChipType == "ESP32-C3" ? 0x0 : 0x1000, Path.Combine(LocationPath, BootloaderPath) },
8587

8688
// nanoCLR goes to 0x10000
8789
{ CLRAddress, Path.Combine(LocationPath, "nanoCLR.bin") },

nanoFirmwareFlasher.Library/Esp32Operations.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
126126

127127
// perform sanity checks for the specified target against the connected device details
128128
if (esp32Device.ChipType != "ESP32" &&
129-
esp32Device.ChipType != "ESP32-S2")
129+
esp32Device.ChipType != "ESP32-S2" &&
130+
esp32Device.ChipType != "ESP32-C3")
130131
{
131132
// connected to a device not supported
132133
Console.ForegroundColor = ConsoleColor.Yellow;
@@ -175,6 +176,19 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
175176
revisionSuffix = "REV0";
176177
}
177178

179+
if (esp32Device.ChipName.Contains("ESP32_C3"))
180+
{
181+
if (esp32Device.ChipName.Contains("revision 2"))
182+
{
183+
revisionSuffix = "REV2";
184+
}
185+
else
186+
{
187+
// all the others (rev3 and rev4) will take rev3
188+
revisionSuffix = "REV3";
189+
}
190+
}
191+
178192
// compose target name
179193
targetName = $"ESP32{psRamSegment}{otherSegment}_{revisionSuffix}";
180194
}
@@ -194,6 +208,36 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
194208

195209
return ExitCodes.E9000;
196210
}
211+
else if (esp32Device.ChipType == "ESP32-C3")
212+
{
213+
string revisionSuffix;
214+
215+
if (esp32Device.ChipName.Contains("revision 2"))
216+
{
217+
revisionSuffix = "REV2";
218+
}
219+
else if (esp32Device.ChipName.Contains("revision 3") || esp32Device.ChipName.Contains("revision 4"))
220+
{
221+
// all the others (rev3 and rev4) will take rev3
222+
revisionSuffix = "REV3";
223+
}
224+
else
225+
{
226+
Console.ForegroundColor = ConsoleColor.Red;
227+
228+
Console.WriteLine("");
229+
Console.WriteLine($"Unsupported ESP32_C3 revision.");
230+
Console.WriteLine("");
231+
232+
Console.ForegroundColor = ConsoleColor.White;
233+
234+
return ExitCodes.E9000;
235+
}
236+
237+
// compose target name
238+
targetName = $"ESP32_C3_{revisionSuffix}";
239+
}
240+
197241

198242
Console.ForegroundColor = ConsoleColor.Blue;
199243

@@ -265,7 +309,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
265309
// need to download update package?
266310
if (updateFw)
267311
{
268-
operationResult = await firmware.DownloadAndExtractAsync(esp32Device.FlashSize);
312+
operationResult = await firmware.DownloadAndExtractAsync(esp32Device);
269313

270314
if (operationResult != ExitCodes.OK)
271315
{

nanoFirmwareFlasher.Library/EspTool.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,16 @@ public Esp32DeviceInfo GetDeviceDetails(
252252
// FEATHER_S2's have PSRAM, so don't even bother
253253
psramIsAvailable = PSRamAvailability.Yes;
254254
}
255+
else if (name.Contains("ESP32-C3"))
256+
{
257+
// all ESP32-C3 SDK config have support for PSRAM, so don't even bother
258+
psramIsAvailable = PSRamAvailability.Undetermined;
259+
}
255260
else
256261
{
257-
// if a target name was provided, don't bother to check PSRAM
258-
if (targetName == null)
262+
// if a target name wasn't provided, check for PSRAM
263+
// except for ESP32_C3
264+
if (targetName == null && !name.Contains("ESP32-C3"))
259265
{
260266
psramIsAvailable = FindPSRamAvailable();
261267
}

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": "2.3",
3+
"version": "2.4",
44
"assemblyVersion": {
55
"precision": "minor"
66
},

0 commit comments

Comments
 (0)