@@ -24,28 +24,35 @@ def __init__(self, cfg, device, flash_tool):
2424        self .mplabx_base  =  None 
2525        self .java_bin  =  None 
2626        self .ipecmd_jar  =  None 
27-         if  platform .system () ==  'Linux'  or  platform .system () ==  'Windows' :
28-             self .mplabx_base  =  self .find_mplabx_base ()
29-             if  not  self .mplabx_base :
30-                 print ("Error: Could not locate mplabx base directory" )
31-                 sys .exit (1 )
3227
33-              version_path   =  self .find_latest_version_dir ( self . mplabx_base )
34-              if  not  version_path :
35-                  print ("Error: No MPLAB X version directories found " )
36-                  sys .exit (1 )
28+         self . mplabx_base   =  self .find_mplabx_base ( )
29+         if  not  self . mplabx_base :
30+             print ("Error: Could not locate mplabx base directory " )
31+             sys .exit (1 )
3732
33+         version_path  =  self .find_latest_version_dir (self .mplabx_base )
34+         if  not  version_path :
35+             print ("Error: No MPLAB X version directories found" )
36+             sys .exit (1 )
37+         if  platform .system () ==  'Linux' :
3838            self .java_bin  =  self .find_java_bin (version_path )
3939            if  not  self .java_bin  or  not  os .access (self .java_bin , os .X_OK ):
4040                print ("Error: Java executable not found or not executable" )
4141                sys .exit (1 )
4242
43-             self .ipecmd_jar  =  self .find_ipecmd_jar (version_path )
43+             self .ipecmd_jar  =  self .find_ipecmd (version_path ,  "ipecmd.jar" )
4444            if  not  self .ipecmd_jar :
4545                print (f"Error: ipecmd.jar not found in { version_path }  )
4646                sys .exit (1 )
4747            else :
4848                print (f'ipecmd: { self .ipecmd_jar }  )
49+         elif  platform .system () ==  'Windows' :
50+             self .ipecmd_exe  =  self .find_ipecmd (version_path , "ipecmd.exe" )
51+             if  not  self .ipecmd_exe :
52+                 print (f"Error: ipecmd.exe not found in { version_path }  )
53+                 sys .exit (1 )
54+             else :
55+                 print (f'ipecmd: { self .ipecmd_exe }  )
4956        self .app_bin  =  cfg .bin_file 
5057        print (f'bin file: { cfg .bin_file }  )
5158        self .hex_file  =  cfg .hex_file 
@@ -78,19 +85,30 @@ def do_run(self, command, **kwargs):
7885        self .ensure_output ('hex' )
7986
8087        self .logger .info (f'Flashing file: { self .hex_file }  )
88+         self .logger .info (f'flash tool: { self .flash_tool } { self .device }  )
8189        if  self .hex_file  is  not None :
82-             self .logger .info (f'flash tool: { self .flash_tool } { self .device }  )
83-             self .logger .info (f'flash cmd: { self .ipecmd_jar }  )
84-             cmd  =  [
85-                 str (self .java_bin ),
86-                 '-jar' ,
87-                 str (self .ipecmd_jar ),
88-                 '-TP'  +  self .flash_tool ,
89-                 '-P'  +  self .device ,
90-                 '-M' ,
91-                 '-F'  +  self .hex_file ,
92-                 '-OL' ,
93-             ]
90+             if  platform .system () ==  'Linux' :
91+                 self .logger .info (f'flash cmd: { self .ipecmd_jar }  )
92+                 cmd  =  [
93+                     str (self .java_bin ),
94+                     '-jar' ,
95+                     str (self .ipecmd_jar ),
96+                     '-TP'  +  self .flash_tool ,
97+                     '-P'  +  self .device ,
98+                     '-M' ,
99+                     '-F'  +  self .hex_file ,
100+                     '-OL' ,
101+                 ]
102+             elif  platform .system () ==  'Windows' :
103+                 self .logger .info (f'flash cmd: { self .ipecmd_exe }  )
104+                 cmd  =  [
105+                     str (self .ipecmd_exe ),
106+                     '-TP'  +  self .flash_tool ,
107+                     '-P'  +  self .device ,
108+                     '-M' ,
109+                     '-F'  +  self .hex_file ,
110+                     '-OL' ,
111+                 ]
94112            self .require (cmd [0 ])
95113            self .check_call (cmd )
96114        else :
@@ -118,9 +136,9 @@ def find_java_bin(self, version_path):
118136            sys .exit (1 )
119137        return  java_dirs [0 ] if  java_dirs  else  None 
120138
121-     def  find_ipecmd_jar (self , version_path ):
139+     def  find_ipecmd (self , version_path ,  tool ):
122140        ipe_dir  =  version_path  /  "mplab_platform/mplab_ipe" 
123141        for  root , _ , files  in  os .walk (ipe_dir ):
124-             if  "ipecmd.jar"  in  files :
125-                 return  Path (root ) /  "ipecmd.jar" 
142+             if  tool  in  files :
143+                 return  Path (root ) /  tool 
126144        return  None 
0 commit comments