Skip to content

Commit fff36e4

Browse files
Fix flash/monitoring of 26mhz targets (#584)
* 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
1 parent 9592c92 commit fff36e4

File tree

12 files changed

+18
-80
lines changed

12 files changed

+18
-80
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727

2828
### Fixed
2929

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

3839
### Changed
3940

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

4648
### Removed
4749

cargo-espflash/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,8 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
344344
let pid = flasher.get_usb_pid()?;
345345

346346
// The 26MHz ESP32-C2's need to be treated as a special case.
347-
let default_baud = if chip == Chip::Esp32c2
348-
&& args.connect_args.no_stub
349-
&& target_xtal_freq == XtalFrequency::_26Mhz
350-
{
347+
let default_baud = if chip == Chip::Esp32c2 && target_xtal_freq == XtalFrequency::_26Mhz {
348+
// 115_200 * 26 MHz / 40 MHz = 74_880
351349
74_880
352350
} else {
353351
115_200

espflash/resources/stubs/stub_flasher_32c2.toml

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

espflash/src/bin/espflash.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,8 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
279279
let pid = flasher.get_usb_pid()?;
280280

281281
// The 26MHz ESP32-C2's need to be treated as a special case.
282-
let default_baud = if chip == Chip::Esp32c2
283-
&& args.connect_args.no_stub
284-
&& target_xtal_freq == XtalFrequency::_26Mhz
285-
{
282+
let default_baud = if chip == Chip::Esp32c2 && target_xtal_freq == XtalFrequency::_26Mhz {
283+
// 115_200 * 26 MHz / 40 MHz = 74_880
286284
74_880
287285
} else {
288286
115_200

espflash/src/cli/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
439439

440440
// The 26MHz ESP32-C2's need to be treated as a special case.
441441
let default_baud = if chip == Chip::Esp32c2
442-
&& args.connect_args.no_stub
443442
&& target.crystal_freq(flasher.connection())? == XtalFrequency::_26Mhz
444443
{
444+
// 115_200 * 26 MHz / 40 MHz = 74_880
445445
74_880
446446
} else {
447447
115_200

espflash/src/connection/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,9 @@ impl Connection {
131131
Ok(_) => {
132132
return Ok(());
133133
}
134-
Err(e) => match e {
135-
Error::InvalidSerialRead => {
136-
return Err(Error::InvalidSerialRead);
137-
}
138-
_ => {
139-
debug!("Failed to reset, error {:#?}, retrying", e);
140-
}
141-
},
134+
Err(e) => {
135+
debug!("Failed to reset, error {:#?}, retrying", e);
136+
}
142137
}
143138
}
144139

@@ -173,9 +168,6 @@ impl Connection {
173168
}
174169

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

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

espflash/src/error.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ pub enum Error {
9595
#[error("The provided bootloader binary is invalid")]
9696
InvalidBootloader,
9797

98-
#[error("Invalid byte sequence read from the serial port while trying to detect Boot Mode")]
99-
#[diagnostic(
100-
code(espflash::invalid_serial_read),
101-
help("This might be caused by a xtal frequency mismatch")
102-
)]
103-
InvalidSerialRead,
104-
10598
#[error("Specified bootloader path is not a .bin file")]
10699
#[diagnostic(code(espflash::invalid_bootloader_path))]
107100
InvalidBootloaderPath,

espflash/src/flasher/mod.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use std::{
1111
path::{Path, PathBuf},
1212
str::FromStr,
1313
thread::sleep,
14+
time::Duration,
1415
};
1516

16-
use bytemuck::{Pod, Zeroable, __core::time::Duration};
1717
use esp_idf_part::PartitionTable;
1818
use log::{debug, info, warn};
1919
use md5::{Digest, Md5};
@@ -497,32 +497,6 @@ impl SpiAttachParams {
497497
const TRY_SPI_PARAMS: [SpiAttachParams; 2] =
498498
[SpiAttachParams::default(), SpiAttachParams::esp32_pico_d4()];
499499

500-
#[derive(Zeroable, Pod, Copy, Clone, Debug)]
501-
#[repr(C)]
502-
struct BlockParams {
503-
size: u32,
504-
sequence: u32,
505-
dummy1: u32,
506-
dummy2: u32,
507-
}
508-
509-
#[derive(Zeroable, Pod, Copy, Clone, Debug)]
510-
#[repr(C)]
511-
struct BeginParams {
512-
size: u32,
513-
blocks: u32,
514-
block_size: u32,
515-
offset: u32,
516-
encrypted: u32,
517-
}
518-
519-
#[derive(Zeroable, Pod, Copy, Clone)]
520-
#[repr(C)]
521-
struct EntryParams {
522-
no_entry: u32,
523-
entry: u32,
524-
}
525-
526500
/// Information about the connected device
527501
#[derive(Debug, Clone)]
528502
pub struct DeviceInfo {

espflash/src/targets/esp32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const FLASH_RANGES: &[Range<u32>] = &[
1717
0x3f40_0000..0x3f80_0000, // DROM
1818
];
1919

20+
// UART0_BASE_REG + 0x14
2021
const UART_CLKDIV_REG: u32 = 0x3ff4_0014;
2122
const UART_CLKDIV_MASK: u32 = 0xfffff;
2223

espflash/src/targets/esp32c2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const FLASH_RANGES: &[Range<u32>] = &[
2020
0x3c00_0000..0x3c40_0000, // DROM
2121
];
2222

23+
// UART0_BASE_REG + 0x14
2324
const UART_CLKDIV_REG: u32 = 0x6000_0014;
2425
const UART_CLKDIV_MASK: u32 = 0xfffff;
2526

0 commit comments

Comments
 (0)