1111class ESP32UltraFlasher :
1212 def __init__ (self ):
1313 self .esp32_folder = 'esp32'
14+ self .esp32_supported_baudrates = [
15+ 50 ,
16+ 75 ,
17+ 110 ,
18+ 134 ,
19+ 150 ,
20+ 200 ,
21+ 300 ,
22+ 600 ,
23+ 1200 ,
24+ 1800 ,
25+ 2400 ,
26+ 4800 ,
27+ 9600 , # Default baudrate for many USB-UART bridges
28+ 14400 ,
29+ 19200 ,
30+ 28800 ,
31+ 38400 ,
32+ 57600 ,
33+ 74880 , # Default bootloader baudrate
34+ 115200 , # Most common and default flashing speed
35+ 128000 ,
36+ 230400 ,
37+ 256000 ,
38+ 460800 , # Fast and reliable
39+ 512000 ,
40+ 921600 , # Maximum reliable speed for many USB-UART bridges (CP210x, CH340)
41+ 1000000 ,
42+ 1152000 ,
43+ 1500000 ,
44+ 2000000 , # Often flaky unless high-end bridge + short cable
45+ 2500000 ,
46+ 3000000 ,
47+ 3500000 ,
48+ 4000000 # ESP32 supports it, but most bridges can't
49+ ]
1450 self .menu_items = []
1551 self .current_item = None
1652 self .config = configparser .ConfigParser ()
@@ -26,7 +62,7 @@ def display_menu(self) -> None:
2662 exit ()
2763
2864 tprint .info ("Select a project to flash:" )
29- for idx , (item , error , _ ) in enumerate (self .menu_items ):
65+ for idx , (item , error , issues , warn ) in enumerate (self .menu_items ):
3066 if error :
3167 tprint .warning (f" <{ idx + 1 } > { item } " )
3268 else :
@@ -35,7 +71,6 @@ def display_menu(self) -> None:
3571 selection = tprint .input ("Enter a number to select, or 'exit' to quit: > " ).strip ()
3672
3773 if selection .lower () == 'exit' :
38- tprint .debug ("Exiting..." )
3974 exit ()
4075
4176 while True :
@@ -52,7 +87,6 @@ def display_menu(self) -> None:
5287 tprint .error ("Invalid input, please enter a valid number or 'exit'." )
5388 selection = tprint .input ("Enter a number to select, or 'exit' to quit: > " ).strip ()
5489 if selection .lower () == 'exit' :
55- tprint .debug ("Exiting..." )
5690 exit ()
5791 except Exception as e :
5892 handler .exception (msg = e )
@@ -117,27 +151,26 @@ def __load_menu_items(self) -> None:
117151 for folder in os .listdir (self .esp32_folder ):
118152 folder_path = os .path .join (self .esp32_folder , folder )
119153 if os .path .isdir (folder_path ):
120- issues = self .__check_folder_for_issues (folder_path )
121- if issues :
122- self .menu_items .append ((folder , True , issues ))
123- else :
124- self .menu_items .append ((folder , False , []))
154+ issues , warn = self .__check_folder_for_issues (folder_path )
155+ self .menu_items .append ((folder , True if issues else False , issues if issues else [], warn if warn else []))
156+
125157 except Exception as e :
126158 handler .exception (msg = e )
127159
128- def __check_folder_for_issues (self , folder_path : str ) -> list [str ]:
160+ def __check_folder_for_issues (self , folder_path : str ) -> tuple [ list [str ], list [ str ] ]:
129161 try :
130162 issues = []
163+ warn = []
131164 config_path = os .path .join (folder_path , 'config.ini' )
132165
133166 if not os .path .exists (config_path ):
134167 issues .append ("Missing config.ini" )
135- return issues
168+ return issues , warn
136169
137170 self .config .read (config_path )
138171 if 'Settings' not in self .config .sections ():
139172 issues .append ("Missing [Settings] section in config.ini" )
140- return issues
173+ return issues , warn
141174
142175 bin_files = [f for f in os .listdir (folder_path ) if f .endswith ('.bin' )]
143176 referenced_files = [key for key in self .config ['Settings' ] if key .endswith ('.bin' )]
@@ -159,11 +192,20 @@ def __check_folder_for_issues(self, folder_path: str) -> list[str]:
159192 baud_rate = self .config .get ('Settings' , 'Baud_Rate' , fallback = None )
160193 if not baud_rate or not baud_rate .isdigit ():
161194 issues .append (f"Invalid or missing Baud_Rate in config.ini" )
162-
163- return issues
195+ else :
196+ baud_rate = int (baud_rate )
197+ if baud_rate not in self .esp32_supported_baudrates :
198+ warn .append (f"Baud Rate: { baud_rate } is unusual, so take heed." )
199+ if baud_rate < 0 :
200+ issues .append (f"Invalid Baud Rate: { baud_rate } . Must be above 0." )
201+ if baud_rate > 2000000 :
202+ warn .append (
203+ f"Baud Rate: { baud_rate } is unusually high, so take heed. Anything above 2000000 may not work." )
204+
205+ return issues , warn
164206 except Exception as e :
165207 handler .exception (msg = e )
166- return ["Unexpected error during folder check." ]
208+ return ["Unexpected error during folder check." ], []
167209
168210 def __validate_memory_addresses (self ) -> list [str ]:
169211 """Ensure all memory addresses are valid hex."""
@@ -179,14 +221,18 @@ def __validate_memory_addresses(self) -> list[str]:
179221 handler .exception (msg = e )
180222 return ["Unexpected error during memory address validation." ]
181223
182- def __handle_selection (self , item : tuple [str , str , list [str ]]) -> None :
224+ def __handle_selection (self , item : tuple [str , str , list [str ], list [ str ] ]) -> None :
183225 try :
184- folder_name , error , issues = item
226+ folder_name , error , issues , warn = item
185227 folder_path = os .path .join (self .esp32_folder , folder_name )
186228
229+ print ()
230+ tprint .info (f"Project: { folder_name } " )
231+ if warn :
232+ for w in warn :
233+ tprint .warning (w )
234+
187235 if error :
188- print ()
189- tprint .info (f"Project: { folder_name } " )
190236 tprint .warning ("Issues detected:" )
191237 for issue in issues :
192238 print (f"\033 [91m - { issue } \033 [0m" )
@@ -202,8 +248,10 @@ def __handle_selection(self, item: tuple[str, str, list[str]]) -> None:
202248 if choice == '1' :
203249 os .system (f'explorer { folder_path } ' )
204250 tprint .input ("Press enter to recheck the project: > " )
251+ self .__check_project (folder_name , folder_path )
205252 elif choice == '2' :
206253 self .__autogenerate_config (folder_path )
254+ self .__check_project (folder_name , folder_path )
207255 elif choice == '3' :
208256 self .__check_project (folder_name , folder_path )
209257 else :
@@ -216,7 +264,7 @@ def __handle_selection(self, item: tuple[str, str, list[str]]) -> None:
216264
217265 def __check_project (self , folder_name : str , folder_path : str ) -> None :
218266 try :
219- refreshed_issues = self .__check_folder_for_issues (folder_path )
267+ refreshed_issues , _ = self .__check_folder_for_issues (folder_path )
220268 for idx , (name , _ , _ ) in enumerate (self .menu_items ):
221269 if name == folder_name :
222270 error = True if refreshed_issues else False
0 commit comments