Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to eh-1; minor rework #4

Merged
merged 17 commits into from
Jun 23, 2024
65 changes: 59 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ on:

name: CI

env:
RUSTFLAGS: "-D warnings"

jobs:
build_examples:
name: Build examples
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-D warnings"
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand All @@ -30,8 +31,6 @@ jobs:
build_examples_release:
name: Build examples (release)
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-D warnings"
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand Down Expand Up @@ -61,7 +60,7 @@ jobs:
run: cargo fmt --all -- --check

- name: Run cargo clippy
run: cargo clippy --all-features --examples -- -D warnings
run: cargo clippy --all-features --examples --lib --bins -- -D warnings

docs:
name: Documentation
Expand All @@ -80,12 +79,66 @@ jobs:
RUSTDOCFLAGS: "-Dwarnings"
run: cargo doc --no-deps --examples --all-features

msrv:
name: Minimum Supported Rust Version, based on min dependency versions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@nightly

- name: Install dependencies
uses: taiki-e/install-action@v2
with:
tool: cargo-hack, cargo-minimal-versions, cargo-binstall

- name: Install cargo-msrv
run: cargo binstall --version 0.16.0-beta.22 --no-confirm cargo-msrv

# TODO: Revert to this, once https://github.com/foresterre/cargo-msrv/issues/936 is fixed.
# - name: Check with minimal versions
# # To find out the current MSRV, remove the `rust-version` entry from `Cargo.toml` and run:
# # run: cargo minimal-versions msrv --output-format json --all-features --target=thumbv7em-none-eabihf --log-target=stdout --log-level debug
# run: cargo minimal-versions msrv --output-format json --all-features --target thumbv7em-none-eabihf verify

# WORKAROUND:
- name: Determine MSRV
run: echo "MSRV=$(cargo msrv show --output-format=minimal)" >> $GITHUB_ENV

- name: Show MSRV
run: echo $MSRV

- name: Install MSRV Rust version
run: rustup toolchain install $MSRV --target thumbv7em-none-eabihf

- name: Check with minimal versions
run: cargo +${MSRV} minimal-versions check --target thumbv7em-none-eabihf --all-features

semver:
name: Semantic Versioning
runs-on: ubuntu-latest
env:
# No idea why this fixes the check.
RUSTFLAGS: "--cap-lints=warn"
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: thumbv7em-none-eabihf
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2
with:
feature-group: "all-features"

release:
name: Publish version
runs-on: ubuntu-latest
environment: production
if: github.event_name == 'release'
needs: [build_examples, build_examples_release, lints, docs]
needs: [build_examples, build_examples_release, lints, docs, msrv, semver]
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand Down
22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "imxrt-uart-panic"
authors = ["Finomnis <[email protected]>"]
version = "0.1.2"
version = "0.2.0"
rust-version = "1.68"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -16,23 +17,24 @@ exclude = ["/.gitignore", "/.github/", "/.vscode/"]
default = []

# Do not use; internally required for Github CI
github_ci = ["teensy4-bsp", "teensy4-panic"]
_ci = ["imxrt-ral/imxrt1062"]

[dependencies]
imxrt-hal = { version = "0.5.3", default-features = false }
imxrt-hal = { version = "0.5.5", default-features = false }
imxrt-ral = "0.5.3"
cortex-m = "0.7.7"
nb = "1.1.0"
embedded-hal = "0.2.7"
embedded-io = "0.6.1"

# Additional CI dependencies
teensy4-bsp = { version = "0.4", optional = true }
teensy4-panic = { version = "0.2", default-features = false, optional = true }
# Fix for min-versions.
# TODO: remove once unnecessary.
ral-registers = "0.1.2"
eh-old = { package = "embedded-hal", version = "0.2.6" }
bitflags-old = { package = "bitflags", version = "1.3" }

[dev-dependencies]
teensy4-bsp = { version = "0.4.4", features = ["rt"] }
teensy4-bsp = { version = "0.5.0", features = ["rt"] }
teensy4-panic = { version = "0.2.3", default-features = false }
rtic = { version = "2.0.1", features = ["thumbv7-backend"] }
rtic = { version = "2.1.1", features = ["thumbv7-backend"] }
imxrt-log = { version = "0.1.1", default-features = false, features = [
"log",
"lpuart",
Expand Down
17 changes: 9 additions & 8 deletions examples/with-logging-and-sos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ mod app {

use bsp::board;
use bsp::hal;
use bsp::logging;

use hal::gpt;

use embedded_hal::serial::Write;
use embedded_io::Write;

const LOG_POLL_INTERVAL: u32 = board::PERCLK_FREQUENCY / 100;
const LOG_DMA_CHANNEL: usize = 0;

#[local]
struct Local {
poll_log: hal::pit::Pit3,
log_poller: logging::Poller,
log_poller: imxrt_log::Poller,
gpt1: hal::gpt::Gpt1,
}

Expand All @@ -49,12 +48,14 @@ mod app {
// Logging
let log_dma = dma[LOG_DMA_CHANNEL].take().unwrap();
let mut log_uart = board::lpuart(lpuart6, pins.p1, pins.p0, 115200);
for &ch in "\r\n===== i.MX RT UART Panic Example =====\r\n\r\n".as_bytes() {
nb::block!(log_uart.write(ch)).unwrap();
}
nb::block!(log_uart.flush()).unwrap();

log_uart
.write_all(b"\r\n===== i.MX RT UART Panic Example =====\r\n\r\n")
.unwrap();
log_uart.flush().unwrap();

let log_poller =
logging::log::lpuart(log_uart, log_dma, logging::Interrupts::Enabled).unwrap();
imxrt_log::log::lpuart(log_uart, log_dma, imxrt_log::Interrupts::Enabled).unwrap();
poll_log.set_interrupt_enable(true);
poll_log.set_load_timer_value(LOG_POLL_INTERVAL);
poll_log.enable();
Expand Down
18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,31 @@
#[doc(hidden)]
pub mod _deps {
pub use cortex_m;
pub use embedded_hal;
pub use embedded_io;
pub use imxrt_hal;
pub use imxrt_ral;
pub use nb;
}

/// Registers the UART panic handler.
///
/// # Arguments
///
/// - `uart`: A peripheral defined in [`imxrt_ral::lpuart`].
/// - `tx_pin`: The UART tx pin. Usually defined in the bsp, such as [`teensy4_bsp::pins::common`].
/// - `rx_pin`: The UART rx pin. Usually defined in the bsp, such as [`teensy4_bsp::pins::common`].
/// - `tx_pin`: The UART tx pin. Usually defined in the bsp, such as [`teensy4_bsp::pins::common`](https://docs.rs/teensy4-pins/0.3.2/teensy4_pins/common).
/// - `rx_pin`: The UART rx pin. Usually defined in the bsp, such as [`teensy4_bsp::pins::common`](https://docs.rs/teensy4-pins/0.3.2/teensy4_pins/common).
/// - `baud`: The UART baud rate. Most common ones are `9600` and `115200`.
/// - `idle_func`: Optional. Specifies what function to enter in the end. Default is [`cortex_m::asm::udf`], but this could
/// for example be used to enter [`teensy4_panic::sos`].
/// for example be used to enter [`teensy4_panic::sos`](https://docs.rs/teensy4-panic/0.2.3/teensy4_panic/fn.sos.html).
#[macro_export]
macro_rules! register {
($uart: ident, $tx_pin: ident, $rx_pin: ident, $baud: expr, $idle_func: expr) => {
#[panic_handler]
fn panic(info: &::core::panic::PanicInfo) -> ! {
use ::core::fmt::Write as _;

use $crate::_deps::embedded_hal::serial::Write as _;
use $crate::_deps::embedded_io::Write as _;
use $crate::_deps::imxrt_hal as hal;
use $crate::_deps::imxrt_ral as ral;
use $crate::_deps::nb::block;

use hal::ccm;
use hal::lpuart::{Baud, Direction, Lpuart, Pins, Watermark};
Expand Down Expand Up @@ -75,9 +73,9 @@ macro_rules! register {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
for &b in s.as_bytes() {
if b == b'\n' {
let _ = block!(self.uart.write(b'\r'));
let _ = self.uart.write_all(b"\r");
}
let _ = block!(self.uart.write(b));
let _ = self.uart.write_all(core::slice::from_ref(&b));
}
Ok(())
}
Expand All @@ -89,7 +87,7 @@ macro_rules! register {
::core::writeln!(uart, "{}", info).ok();
::core::writeln!(uart).ok();

let _ = block!(uart.uart.flush());
let _ = uart.uart.flush();

$idle_func();
}
Expand Down
Loading