Skip to content

Commit

Permalink
feat: Support 26 MHz ESP32
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed Apr 2, 2024
1 parent 1fd08de commit d86a622
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
if args.flash_args.monitor {
let pid = flasher.get_usb_pid()?;

// The 26MHz ESP32-C2's need to be treated as a special case.
let default_baud = if chip == Chip::Esp32c2 && target_xtal_freq == XtalFrequency::_26Mhz {
// The 26MHz ESP32's and ESP32-C2's need to be treated as a special case.
let default_baud = if (chip == Chip::Esp32c2 || chip == Chip::Esp32)
&& target_xtal_freq == XtalFrequency::_26Mhz
{
// 115_200 * 26 MHz / 40 MHz = 74_880
74_880
} else {
Expand Down
6 changes: 4 additions & 2 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,10 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
if args.flash_args.monitor {
let pid = flasher.get_usb_pid()?;

// The 26MHz ESP32-C2's need to be treated as a special case.
let default_baud = if chip == Chip::Esp32c2 && target_xtal_freq == XtalFrequency::_26Mhz {
// The 26MHz ESP32's and ESP32-C2's need to be treated as a special case.
let default_baud = if (chip == Chip::Esp32c2 || chip == Chip::Esp32)
&& target_xtal_freq == XtalFrequency::_26Mhz
{
// 115_200 * 26 MHz / 40 MHz = 74_880
74_880
} else {
Expand Down
4 changes: 2 additions & 2 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
let chip = flasher.chip();
let target = chip.into_target();

// The 26MHz ESP32-C2's need to be treated as a special case.
let default_baud = if chip == Chip::Esp32c2
// The 26MHz ESP32's and ESP32-C2's need to be treated as a special case.
let default_baud = if (chip == Chip::Esp32c2 || chip == Chip::Esp32)
&& target.crystal_freq(flasher.connection())? == XtalFrequency::_26Mhz
{
// 115_200 * 26 MHz / 40 MHz = 74_880
Expand Down
5 changes: 4 additions & 1 deletion espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,10 @@ impl Flasher {
// The ROM code thinks it uses a 40 MHz XTAL. Recompute the baud rate in order
// to trick the ROM code to set the correct baud rate for a 26 MHz XTAL.
let mut new_baud = speed;
if self.chip == Chip::Esp32c2 && !self.use_stub && xtal_freq == XtalFrequency::_26Mhz {
if (self.chip == Chip::Esp32c2 || self.chip == Chip::Esp32)
&& !self.use_stub
&& xtal_freq == XtalFrequency::_26Mhz
{
new_baud = new_baud * 40 / 26;
}

Expand Down

0 comments on commit d86a622

Please sign in to comment.