Skip to content

Commit

Permalink
Fix flash/monitoring of 26mhz targets (#584)
Browse files Browse the repository at this point in the history
* feat: Remove InvalidSerialRead Err

* style: Remove unconstructeds structs

* feat: Update monitoring baudrate when using stub

* feat: Update stubs to support 26MHz targets

* docs: Update changelog
  • Loading branch information
SergioGasquez authored Feb 16, 2024
1 parent 9592c92 commit fff36e4
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 80 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fixed printing panic backtraces when using `esp-println` and `defmt` (#496)
- Fixed `defmt` parsing when data is read in parts (#503)
- Fix printing panic backtraces when using `esp-println` and `defmt` (#496)
- Fix `defmt` parsing when data is read in parts (#503)
- Use partition table instead of hard-coded values for the location of partitions (#516)
- Fixed a missed `flush` call that may be causing communication errors (#521)
- Fix a missed `flush` call that may be causing communication errors (#521)
- Fix "SHA-256 comparison failed: [...] attempting to boot anyway..." (#567)
- Windows: Update RST/DTR order to avoid issues.
- Tolerate non-utf8 data in boot detection (#573)
- Fix flash/monitoring of 26mhz targets (#584)

### Changed

Expand All @@ -42,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Unify configuration methods (#551)
- MSRV bumped to `1.73.0` (#578)
- Improved symbol resolving (#581)
- Update ESP32-C2 stub (#584)

### Removed

Expand Down
6 changes: 2 additions & 4 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,8 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
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
&& args.connect_args.no_stub
&& target_xtal_freq == XtalFrequency::_26Mhz
{
let default_baud = if chip == Chip::Esp32c2 && target_xtal_freq == XtalFrequency::_26Mhz {
// 115_200 * 26 MHz / 40 MHz = 74_880
74_880
} else {
115_200
Expand Down
4 changes: 2 additions & 2 deletions espflash/resources/stubs/stub_flasher_32c2.toml

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,8 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
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
&& args.connect_args.no_stub
&& target_xtal_freq == XtalFrequency::_26Mhz
{
let default_baud = if chip == Chip::Esp32c2 && target_xtal_freq == XtalFrequency::_26Mhz {
// 115_200 * 26 MHz / 40 MHz = 74_880
74_880
} else {
115_200
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {

// The 26MHz ESP32-C2's need to be treated as a special case.
let default_baud = if chip == Chip::Esp32c2
&& args.connect_args.no_stub
&& target.crystal_freq(flasher.connection())? == XtalFrequency::_26Mhz
{
// 115_200 * 26 MHz / 40 MHz = 74_880
74_880
} else {
115_200
Expand Down
14 changes: 3 additions & 11 deletions espflash/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,9 @@ impl Connection {
Ok(_) => {
return Ok(());
}
Err(e) => match e {
Error::InvalidSerialRead => {
return Err(Error::InvalidSerialRead);
}
_ => {
debug!("Failed to reset, error {:#?}, retrying", e);
}
},
Err(e) => {
debug!("Failed to reset, error {:#?}, retrying", e);
}
}
}

Expand Down Expand Up @@ -173,9 +168,6 @@ impl Connection {
}

let read_slice = String::from_utf8_lossy(&buff[..read_bytes as usize]).into_owned();
if !read_slice.contains("boot") {
return Err(Error::InvalidSerialRead);
}

let pattern = Regex::new(r"boot:(0x[0-9a-fA-F]+)(.*waiting for download)?").unwrap();

Expand Down
7 changes: 0 additions & 7 deletions espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ pub enum Error {
#[error("The provided bootloader binary is invalid")]
InvalidBootloader,

#[error("Invalid byte sequence read from the serial port while trying to detect Boot Mode")]
#[diagnostic(
code(espflash::invalid_serial_read),
help("This might be caused by a xtal frequency mismatch")
)]
InvalidSerialRead,

#[error("Specified bootloader path is not a .bin file")]
#[diagnostic(code(espflash::invalid_bootloader_path))]
InvalidBootloaderPath,
Expand Down
28 changes: 1 addition & 27 deletions espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
thread::sleep,
time::Duration,
};

use bytemuck::{Pod, Zeroable, __core::time::Duration};
use esp_idf_part::PartitionTable;
use log::{debug, info, warn};
use md5::{Digest, Md5};
Expand Down Expand Up @@ -497,32 +497,6 @@ impl SpiAttachParams {
const TRY_SPI_PARAMS: [SpiAttachParams; 2] =
[SpiAttachParams::default(), SpiAttachParams::esp32_pico_d4()];

#[derive(Zeroable, Pod, Copy, Clone, Debug)]
#[repr(C)]
struct BlockParams {
size: u32,
sequence: u32,
dummy1: u32,
dummy2: u32,
}

#[derive(Zeroable, Pod, Copy, Clone, Debug)]
#[repr(C)]
struct BeginParams {
size: u32,
blocks: u32,
block_size: u32,
offset: u32,
encrypted: u32,
}

#[derive(Zeroable, Pod, Copy, Clone)]
#[repr(C)]
struct EntryParams {
no_entry: u32,
entry: u32,
}

/// Information about the connected device
#[derive(Debug, Clone)]
pub struct DeviceInfo {
Expand Down
1 change: 1 addition & 0 deletions espflash/src/targets/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const FLASH_RANGES: &[Range<u32>] = &[
0x3f40_0000..0x3f80_0000, // DROM
];

// UART0_BASE_REG + 0x14
const UART_CLKDIV_REG: u32 = 0x3ff4_0014;
const UART_CLKDIV_MASK: u32 = 0xfffff;

Expand Down
1 change: 1 addition & 0 deletions espflash/src/targets/esp32c2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const FLASH_RANGES: &[Range<u32>] = &[
0x3c00_0000..0x3c40_0000, // DROM
];

// UART0_BASE_REG + 0x14
const UART_CLKDIV_REG: u32 = 0x6000_0014;
const UART_CLKDIV_MASK: u32 = 0xfffff;

Expand Down
12 changes: 0 additions & 12 deletions espflash/src/targets/flash_target/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use bytemuck::{Pod, Zeroable};

pub(crate) use self::ram::MAX_RAM_BLOCK_SIZE;
pub use self::{esp32::Esp32Target, ram::RamTarget};
#[cfg(feature = "serialport")]
Expand All @@ -26,13 +24,3 @@ pub trait FlashTarget {
/// Complete the flashing operation
fn finish(&mut self, connection: &mut Connection, reboot: bool) -> Result<(), Error>;
}

#[derive(Zeroable, Pod, Copy, Clone, Debug)]
#[repr(C)]
struct BeginParams {
size: u32,
blocks: u32,
block_size: u32,
offset: u32,
encrypted: u32,
}
9 changes: 0 additions & 9 deletions espflash/src/targets/flash_target/ram.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use bytemuck::{Pod, Zeroable};

use crate::{
command::{Command, CommandType},
elf::RomSegment,
Expand All @@ -11,13 +9,6 @@ use crate::{connection::Connection, targets::FlashTarget};

pub const MAX_RAM_BLOCK_SIZE: usize = 0x1800;

#[derive(Zeroable, Pod, Copy, Clone)]
#[repr(C)]
struct EntryParams {
no_entry: u32,
entry: u32,
}

/// Applications running in the target device's RAM
pub struct RamTarget {
entry: Option<u32>,
Expand Down

0 comments on commit fff36e4

Please sign in to comment.