Skip to content

Commit

Permalink
Remove support for Raspberry Pi's internal UART peripherals (#585)
Browse files Browse the repository at this point in the history
* feat: Remove raspberry feature

* feat: Replace Interface types

* feat: Remove interface mod

* docs: Update changelog
  • Loading branch information
SergioGasquez authored Feb 16, 2024
1 parent fff36e4 commit 0a5d5e6
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 375 deletions.
4 changes: 1 addition & 3 deletions .github/actions/package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ inputs:
required: false
github_token:
required: true
features:
required: false
target:
required: true
runs_on:
Expand All @@ -22,7 +20,7 @@ runs:
- name: Build
shell: bash
run: |
cargo build --release --all --target ${{ inputs.target }} ${{ inputs.features }}
cargo build --release --all --target ${{ inputs.target }}
- name: Compress (Unix)
if: ${{ inputs.runs_on != 'windows-2022' }}
Expand Down
20 changes: 5 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ jobs:
- os: "ubuntu-22.04"
target: "aarch64-unknown-linux-gnu"
arch: "arm64"
features: "--features=raspberry"
- os: "ubuntu-22.04"
target: "armv7-unknown-linux-gnueabihf"
arch: "armhf"
features: "--features=raspberry"
runs-on: ${{ matrix.platform.os }}

steps:
Expand All @@ -59,7 +57,7 @@ jobs:
arch: ${{ matrix.platform.arch }}
target: ${{ matrix.platform.target }}

- run: cargo check ${{ matrix.platform.features }}
- run: cargo check

check-lib:
name: Check lib (${{ matrix.platform.target }})
Expand All @@ -71,10 +69,8 @@ jobs:
arch: "x86_64"
- target: "aarch64-unknown-linux-gnu"
arch: "arm64"
features: "--features=raspberry"
- target: "armv7-unknown-linux-gnueabihf"
arch: "armhf"
features: "--features=raspberry"
runs-on: ubuntu-22.04

steps:
Expand All @@ -86,7 +82,7 @@ jobs:
arch: ${{ matrix.platform.arch }}
target: ${{ matrix.platform.target }}

- run: cargo check -p espflash --lib --no-default-features ${{ matrix.platform.features }}
- run: cargo check -p espflash --lib --no-default-features

msrv:
name: Check MSRV (${{ matrix.platform.target }})
Expand All @@ -98,10 +94,8 @@ jobs:
arch: "x86_64"
- target: "aarch64-unknown-linux-gnu"
arch: "arm64"
features: "--features=raspberry"
- target: "armv7-unknown-linux-gnueabihf"
arch: "armhf"
features: "--features=raspberry"
runs-on: ubuntu-22.04

steps:
Expand All @@ -114,7 +108,7 @@ jobs:
target: ${{ matrix.platform.target }}
toolchain: "1.73"

- run: cargo check ${{ matrix.platform.features }}
- run: cargo check

# --------------------------------------------------------------------------
# Test
Expand All @@ -129,10 +123,8 @@ jobs:
arch: "x86_64"
- target: "aarch64-unknown-linux-gnu"
arch: "arm64"
features: "--features=raspberry"
- target: "armv7-unknown-linux-gnueabihf"
arch: "armhf"
features: "--features=raspberry"
runs-on: ubuntu-22.04

steps:
Expand All @@ -144,7 +136,7 @@ jobs:
arch: ${{ matrix.platform.arch }}
target: ${{ matrix.platform.target }}

- run: cargo test --lib ${{ matrix.platform.features }}
- run: cargo test --lib

# --------------------------------------------------------------------------
# Lint
Expand All @@ -159,10 +151,8 @@ jobs:
arch: "x86_64"
- target: "aarch64-unknown-linux-gnu"
arch: "arm64"
features: "--features=raspberry"
- target: "armv7-unknown-linux-gnueabihf"
arch: "armhf"
features: "--features=raspberry"
runs-on: ubuntu-22.04

steps:
Expand All @@ -175,7 +165,7 @@ jobs:
target: ${{ matrix.platform.target }}
components: clippy

- run: cargo clippy ${{ matrix.platform.features }} -- -D warnings -A clippy::too_many_arguments
- run: cargo clippy -- -D warnings -A clippy::too_many_arguments

rustfmt:
name: Rustfmt
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ jobs:
- os: "ubuntu-20.04"
target: "aarch64-unknown-linux-gnu"
arch: "arm64"
features: "--features=raspberry"
- os: "ubuntu-20.04"
target: "armv7-unknown-linux-gnueabihf"
arch: "armhf"
features: "--features=raspberry"
# Windows
- os: "windows-2022"
target: "x86_64-pc-windows-msvc"
Expand All @@ -50,7 +48,6 @@ jobs:
with:
arch: ${{ matrix.platform.arch }}
github_token: ${{ secrets.GITHUB_TOKEN }}
features: ${{ matrix.platform.features }}
target: ${{ matrix.platform.target }}
runs_on: ${{ matrix.platform.os }}

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Remove support for the ESP8266 (#576)
- Remove the direct boot image format (#577)
- Remove support for Raspberry Pi's internal UART peripherals (#585)

## [2.1.0] - 2023-10-03

Expand Down
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions cargo-espflash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ Alternatively, you can use [cargo-binstall] to download pre-compiled artifacts f
cargo binstall cargo-espflash
```

If you would like to flash from a Raspberry Pi using the built-in UART peripheral, you can enable the `raspberry` feature (note that this is not available if using [cargo-binstall]):

```bash
cargo install cargo-espflash --features=raspberry
```

By default, in Unix systems, we use the [`vendored-openssl` Cargo feature] which may require additional tools such as `perl` and `make`. To disable this feature, use:

```
Expand Down
2 changes: 1 addition & 1 deletion cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
};

monitor(
flasher.into_interface(),
flasher.into_serial(),
Some(&elf_data),
pid,
args.flash_args.monitor_baud.unwrap_or(default_baud),
Expand Down
2 changes: 0 additions & 2 deletions espflash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ md-5 = "0.10.6"
miette = { version = "7.0.0", features = ["fancy"] }
parse_int = { version = "0.6.0", optional = true }
regex = { version = "1.10.3", optional = true }
rppal = { version = "0.17.1", optional = true }
serde = { version = "1.0.196", features = ["derive"] }
serialport = { version = "4.3.0", optional = true }
sha2 = "0.10.8"
Expand Down Expand Up @@ -85,4 +84,3 @@ cli = [
]
serialport = ["dep:serialport"]

raspberry = ["dep:rppal"]
12 changes: 0 additions & 12 deletions espflash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ Alternatively, you can use [cargo-binstall] to download pre-compiled artifacts f
cargo binstall espflash
```

If you would like to flash from a Raspberry Pi using the built-in UART peripheral, you can enable the `raspberry` feature (note that this is not available if using [cargo-binstall]):

```bash
cargo install espflash --features=raspberry
```

[libuv]: https://libuv.org/
[cargo-binstall]: https://github.com/cargo-bins/cargo-binstall
[releases]: https://github.com/esp-rs/espflash/releases
Expand Down Expand Up @@ -129,12 +123,6 @@ or `cargo add espflash --no-default-features`
We disable the `default-features` to opt-out the `cli` feature, which is enabled by default; you likely will not need any of these types or functions in your application so there’s no use pulling in the extra dependencies.

Just like when using `espflash` as an application, you can enable the raspberry feature to allow your dependent application to use the Raspberry Pi’s built-in UART:

```toml
espflash = { version = "2.1", default-features = false, features = ["raspberry"] }
```

## Configuration File

The configuration file allows you to define various parameters for your application:
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
};

monitor(
flasher.into_interface(),
flasher.into_serial(),
Some(&elf_data),
pid,
args.flash_args.monitor_baud.unwrap_or(default_baud),
Expand Down
6 changes: 0 additions & 6 deletions espflash/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ use crate::error::Error;
pub struct Connection {
/// Name of the serial port used for communication
pub serial: Option<String>,
/// Data Transmit Ready pin
#[cfg(feature = "raspberry")]
pub dtr: Option<u8>,
/// Ready To Send pin
#[cfg(feature = "raspberry")]
pub rts: Option<u8>,
}

/// A configured, known USB device
Expand Down
28 changes: 7 additions & 21 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use esp_idf_part::{DataType, Partition, PartitionTable};
use indicatif::{style::ProgressStyle, HumanCount, ProgressBar};
use log::{debug, info, warn};
use miette::{IntoDiagnostic, Result, WrapErr};
use serialport::{SerialPortType, UsbPortInfo};
use serialport::{FlowControl, SerialPortType, UsbPortInfo};

use self::{
config::Config,
Expand All @@ -34,7 +34,6 @@ use crate::{
parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize, Flasher,
ProgressCallbacks,
},
interface::Interface,
targets::{Chip, XtalFrequency},
};

Expand Down Expand Up @@ -68,14 +67,6 @@ pub struct ConnectArgs {
/// Serial port connected to target device
#[arg(short = 'p', long, env = "ESPFLASH_PORT")]
pub port: Option<String>,
/// DTR pin to use for the internal UART hardware. Uses BCM numbering.
#[cfg(feature = "raspberry")]
#[cfg_attr(feature = "raspberry", clap(long))]
pub dtr: Option<u8>,
/// RTS pin to use for the internal UART hardware. Uses BCM numbering.
#[cfg(feature = "raspberry")]
#[cfg_attr(feature = "raspberry", clap(long))]
pub rts: Option<u8>,
}

/// Generate completions for the given shell
Expand Down Expand Up @@ -306,15 +297,10 @@ pub fn connect(
info!("Serial port: '{}'", port_info.port_name);
info!("Connecting...");

#[cfg(feature = "raspberry")]
let (dtr, rts) = (
args.dtr.or(config.connection.dtr),
args.rts.or(config.connection.rts),
);
#[cfg(not(feature = "raspberry"))]
let (dtr, rts) = (None, None);

let interface = Interface::new(&port_info, dtr, rts)
let serial_port = serialport::new(&port_info.port_name, 115_200)
.flow_control(FlowControl::None)
.open_native()
.map_err(Error::from)
.wrap_err_with(|| format!("Failed to open serial port {}", port_info.port_name))?;

// NOTE: since `get_serial_port_info` filters out all PCI Port and Bluetooth
Expand All @@ -335,7 +321,7 @@ pub fn connect(
};

Ok(Flasher::connect(
interface,
*Box::new(serial_port),
port_info,
args.baud.or(config.baudrate),
!args.no_stub,
Expand Down Expand Up @@ -448,7 +434,7 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
};

monitor(
flasher.into_interface(),
flasher.into_serial(),
elf.as_deref(),
pid,
args.connect_args.baud.unwrap_or(default_baud),
Expand Down
26 changes: 10 additions & 16 deletions espflash/src/cli/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! in our monitor the output is displayed immediately upon reading.

use std::{
io::{stdout, ErrorKind, Write},
io::{stdout, ErrorKind, Read, Write},
time::Duration,
};

Expand All @@ -21,12 +21,13 @@ use crossterm::{
};
use log::error;
use miette::{IntoDiagnostic, Result};
#[cfg(feature = "serialport")]
use serialport::SerialPort;
use strum::{Display, EnumIter, EnumString, VariantNames};

use crate::{
cli::monitor::parser::{InputParser, ResolvingPrinter},
connection::reset_after_flash,
interface::Interface,
connection::{reset_after_flash, Port},
};

pub mod parser;
Expand Down Expand Up @@ -63,9 +64,9 @@ impl Drop for RawModeGuard {
}
}

/// Open a serial monitor on the given interface, using the given input parser.
/// Open a serial monitor on the given serial port, using the given input parser.
pub fn monitor(
mut serial: Interface,
mut serial: Port,
elf: Option<&[u8]>,
pid: u16,
baud: u32,
Expand All @@ -78,12 +79,8 @@ pub fn monitor(

// Explicitly set the baud rate when starting the serial monitor, to allow using
// different rates for flashing.
serial.set_baud_rate(baud).into_diagnostic()?;
serial
.serial_port_mut()
.set_baud_rate(baud)
.into_diagnostic()?;
serial
.serial_port_mut()
.set_timeout(Duration::from_millis(5))
.into_diagnostic()?;

Expand All @@ -100,7 +97,7 @@ pub fn monitor(

let mut buff = [0; 1024];
loop {
let read_count = match serial.serial_port_mut().read(&mut buff) {
let read_count = match serial.read(&mut buff) {
Ok(count) => Ok(count),
Err(e) if e.kind() == ErrorKind::TimedOut => Ok(0),
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
Expand All @@ -126,11 +123,8 @@ pub fn monitor(
}

if let Some(bytes) = handle_key_event(key) {
serial
.serial_port_mut()
.write_all(&bytes)
.into_diagnostic()?;
serial.serial_port_mut().flush().into_diagnostic()?;
serial.write_all(&bytes).into_diagnostic()?;
serial.flush().into_diagnostic()?;
}
}
}
Expand Down
Loading

0 comments on commit 0a5d5e6

Please sign in to comment.