@@ -206,6 +206,20 @@ def build_app(app, device_type, with_profiling=False, no_networking=False):
206
206
print ("Done.\n " )
207
207
208
208
209
+ def flash_app (app , port , baudrate = 1152000 ):
210
+ os .putenv ("ESPTOOL_CHIP" , os .getenv ("IDF_TARGET" , "auto" ))
211
+ os .putenv ("ESPTOOL_BAUD" , baudrate )
212
+ os .putenv ("ESPTOOL_PORT" , port )
213
+ if not os .path .exists ("partitions.bin" ):
214
+ print ("Reading device's partition table..." )
215
+ subprocess .run ("esptool.py read_flash 0x8000 0x1000 partitions.bin" , check = True , shell = True )
216
+ subprocess .run ("gen_esp32part.py partitions.bin" , shell = True )
217
+ app_bin = os .path .join (app , "build" , app + ".bin" )
218
+ print (f"Flashing '{ app_bin } ' to port { port } " )
219
+ args = ["parttool.py" , "--partition-table-file" , "partitions.bin" , "write_partition" , "--partition-name" , app , "--input" , app_bin ]
220
+ subprocess .run (args , check = True , shell = True )
221
+
222
+
209
223
def monitor_app (app , port , baudrate = 115200 ):
210
224
print (f"Starting monitor for app { app } on port { port } " )
211
225
try :
@@ -334,26 +348,14 @@ def monitor_app(app, port, baudrate=115200):
334
348
335
349
if command in ["flash" , "run" , "profile" ]:
336
350
print ("=== Step: Flashing ===\n " )
337
- os .putenv ("ESPTOOL_CHIP" , os .getenv ("IDF_TARGET" , "auto" ))
338
- os .putenv ("ESPTOOL_BAUD" , args .baud )
339
- os .putenv ("ESPTOOL_PORT" , args .port )
340
- print ("Reading device's partition table..." )
341
- subprocess .run ("esptool.py read_flash 0x8000 0x1000 partitions.bin" , check = True , shell = True )
342
- subprocess .run ("gen_esp32part.py partitions.bin" , shell = True )
351
+ try : os .unlink ("partitions.bin" )
352
+ except : pass
343
353
for app in apps :
344
- print ("Flashing app '%s'" % app )
345
- subprocess .run ([
346
- "parttool.py" ,
347
- "--partition-table-file" , "partitions.bin" ,
348
- "write_partition" , "--partition-name" , app , "--input" , os .path .join (app , "build" , app + ".bin" )
349
- ], check = True , shell = True )
354
+ flash_app (app , args .port , args .baud )
350
355
351
356
if command in ["monitor" , "run" , "profile" ]:
352
357
print ("=== Step: Monitoring ===\n " )
353
- if len (apps ) == 1 :
354
- monitor_app (apps [0 ], args .port )
355
- else :
356
- monitor_app ("dummy" , args .port )
358
+ monitor_app (apps [0 ] if len (apps ) else "dummy" , args .port )
357
359
358
360
print ("All done!" )
359
361
0 commit comments