@@ -348,13 +348,13 @@ impl Flasher {
348
348
349
349
// Now that we have established a connection and detected the chip and flash
350
350
// size, we can set the baud rate of the connection to the configured value.
351
- if let Some ( b ) = speed {
351
+ if let Some ( baud ) = speed {
352
352
match flasher. chip {
353
353
Chip :: Esp8266 => ( ) , // Not available
354
354
_ => {
355
- if b > 115_200 {
355
+ if baud > 115_200 {
356
356
warn ! ( "Setting baud rate higher than 115,200 can cause issues" ) ;
357
- flasher. change_baud ( b ) ?;
357
+ flasher. change_baud ( baud ) ?;
358
358
}
359
359
}
360
360
}
@@ -776,16 +776,29 @@ impl Flasher {
776
776
false => 0 ,
777
777
} ;
778
778
779
+ let target = self . chip . into_target ( ) ;
780
+ let xtal_freq = target. crystal_freq ( & mut self . connection ) ?;
781
+
782
+ // Probably this is just a temporary solution until the next chip revision.
783
+ //
784
+ // The ROM code thinks it uses a 40 MHz XTAL. Recompute the baud rate in order
785
+ // to trick the ROM code to set the correct baud rate for a 26 MHz XTAL.
786
+ let mut new_baud = speed;
787
+ if self . chip == Chip :: Esp32c2 && !self . use_stub && xtal_freq == 26 {
788
+ new_baud = new_baud * 40 / 26 ;
789
+ }
790
+
779
791
self . connection
780
792
. with_timeout ( CommandType :: ChangeBaud . timeout ( ) , |connection| {
781
793
connection. command ( Command :: ChangeBaud {
782
- new_baud : speed ,
794
+ new_baud,
783
795
prior_baud,
784
796
} )
785
797
} ) ?;
786
798
self . connection . set_baud ( speed) ?;
787
- std :: thread :: sleep ( Duration :: from_secs_f32 ( 0.05 ) ) ;
799
+ sleep ( Duration :: from_secs_f32 ( 0.05 ) ) ;
788
800
self . connection . flush ( ) ?;
801
+
789
802
Ok ( ( ) )
790
803
}
791
804
0 commit comments