1- //
2- // Copyright (c) .NET Foundation and Contributors
3- // See LICENSE file in the project root for full license information.
4- //
1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
53
64using System ;
75using System . Collections . Generic ;
@@ -146,7 +144,8 @@ public EspTool(
146144 public Esp32DeviceInfo GetDeviceDetails (
147145 string targetName ,
148146 bool requireFlashSize = true ,
149- bool forcePsRamCheck = false )
147+ bool forcePsRamCheck = false ,
148+ bool hardResetAfterCommand = false )
150149 {
151150 string messages ;
152151
@@ -161,7 +160,7 @@ public Esp32DeviceInfo GetDeviceDetails(
161160 "flash_id" ,
162161 false ,
163162 true ,
164- false ,
163+ hardResetAfterCommand && ! requireFlashSize ,
165164 null ,
166165 out messages ) )
167166 {
@@ -182,14 +181,15 @@ public Esp32DeviceInfo GetDeviceDetails(
182181
183182 // check if we got flash size (in case we need it)
184183 if ( requireFlashSize
185- && messages . Contains ( "Detected flash size: Unknown" ) )
184+ && ( messages . Contains ( "Detected flash size: Unknown" ) || hardResetAfterCommand ) )
186185 {
187186 // try again now without the stub
187+ // Also run this for the hardResetAfterCommand, as there is no way to use the tool for a reset only (esptool issue 910).
188188 if ( ! RunEspTool (
189189 "flash_id" ,
190190 true ,
191191 true ,
192- false ,
192+ hardResetAfterCommand ,
193193 null ,
194194 out messages ) )
195195 {
@@ -328,13 +328,13 @@ private PSRamAvailability FindPSRamAvailable(
328328 var bootloaderPartition = new Dictionary < int , string >
329329 {
330330 // bootloader goes to 0x1000, except for ESP32_S3, which goes to 0x0
331- { _chipType == "esp32s3" ? 0x0 : 0x1000 , Path . Combine ( Utilities . ExecutingPath , $ "{ _chipType } bootloader", "bootloader.bin" ) } ,
331+ { _chipType == "esp32s3" ? 0x0 : 0x1000 , Path . Combine ( Utilities . ExecutingPath , $ "{ _chipType } bootloader", "bootloader.bin" ) } ,
332332
333- // nanoCLR goes to 0x10000
334- { 0x10000 , Path . Combine ( Utilities . ExecutingPath , $ "{ _chipType } bootloader", "test_startup.bin" ) } ,
333+ // nanoCLR goes to 0x10000
334+ { 0x10000 , Path . Combine ( Utilities . ExecutingPath , $ "{ _chipType } bootloader", "test_startup.bin" ) } ,
335335
336336 // partition table goes to 0x8000; there are partition tables for 2MB, 4MB, 8MB and 16MB flash sizes
337- { 0x8000 , Path . Combine ( Utilities . ExecutingPath , $ "{ _chipType } bootloader", $ "partitions_{ Esp32DeviceInfo . GetFlashSizeAsString ( flashSize ) . ToLowerInvariant ( ) } .bin") }
337+ { 0x8000 , Path . Combine ( Utilities . ExecutingPath , $ "{ _chipType } bootloader", $ "partitions_{ Esp32DeviceInfo . GetFlashSizeAsString ( flashSize ) . ToLowerInvariant ( ) } .bin") }
338338 } ;
339339
340340 // need to use standard baud rate here because of boards put in download mode
@@ -439,16 +439,18 @@ private PSRamAvailability FindPSRamAvailable(
439439 /// </summary>
440440 /// <param name="backupFilename">Backup file including full path</param>
441441 /// <param name="flashSize">Flash size in bytes</param>
442+ /// <param name="hardResetAfterCommand">if true the chip will execute a hard reset via DTR signal</param>
442443 /// <returns>true if successful</returns>
443444 internal void BackupFlash ( string backupFilename ,
444- int flashSize )
445+ int flashSize ,
446+ bool hardResetAfterCommand = false )
445447 {
446448 // execute read_flash command and parse the result; progress message can be found be searching for backspaces (ASCII code 8)
447449 if ( ! RunEspTool (
448450 $ "read_flash 0 0x{ flashSize : X} \" { backupFilename } \" ",
449451 true ,
450452 false ,
451- false ,
453+ hardResetAfterCommand ,
452454 ( char ) 8 ,
453455 out string messages ) )
454456 {
0 commit comments