Skip to content

Commit

Permalink
Add defmt support, make log optional (#773)
Browse files Browse the repository at this point in the history
* Executor related touchups

* Make log optional

* Add defmt feature and derive on Debug structs

* Test both log drivers

* Update esp-println

* Document defmt msrv
  • Loading branch information
bugadani authored Sep 4, 2023
1 parent 48e6171 commit 7866896
Show file tree
Hide file tree
Showing 36 changed files with 447 additions and 75 deletions.
86 changes: 72 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,31 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32-hal (common features)
run: cd esp32-hal/ && cargo check --examples --features=eh1,ufmt
run: |
cd esp32-hal/
cargo check --examples --features=eh1,ufmt,log
cargo check --examples --features=eh1,ufmt,defmt
- name: check esp32-hal (embassy)
run: |
cd esp32-hal/
cargo check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread
cargo check --example=embassy_multicore --features=embassy,embassy-time-timg0,embassy-executor-thread
cargo check --example=embassy_multicore_interrupt --features=embassy,embassy-time-timg0,embassy-executor-interrupt
cargo check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-interrupt
cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,defmt
cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,log
- name: check esp32-hal (embassy, async)
run: |
cd esp32-hal/
cargo check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread
cargo check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread
cargo check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread
cargo check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread
- name: check esp32-hal (embassy, log/defmt)
run: |
cd esp32-hal/
cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,defmt
cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,log
# Ensure documentation can be built
- name: rustdoc
run: cd esp32-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -122,7 +132,10 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32c2-hal (common features)
run: cd esp32c2-hal/ && cargo +nightly check --examples --features=eh1,ufmt
run: |
cd esp32c2-hal/
cargo +nightly check --examples --features=eh1,ufmt,log
cargo +nightly check --examples --features=eh1,ufmt,defmt
- name: check esp32c2-hal (async, systick)
run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-systick
- name: check esp32c2-hal (async, timg0)
Expand All @@ -139,6 +152,11 @@ jobs:
run: cd esp32c2-hal/ && cargo check --example=interrupt_preemption --features=interrupt-preemption
- name: check esp32c2-hal (direct-vectoring)
run: cd esp32c2-hal/ && cargo check --example=direct-vectoring --features=direct-vectoring
- name: check esp32c2-hal (embassy, log/defmt)
run: |
cd esp32c2-hal/
cargo +nightly check --examples --features=embassy,embassy-time-timg0,defmt
cargo +nightly check --examples --features=embassy,embassy-time-timg0,log
# Ensure documentation can be built
- name: rustdoc
run: cd esp32c2-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -168,7 +186,10 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32c3-hal (common features)
run: cd esp32c3-hal/ && cargo +nightly check --examples --features=eh1,ufmt
run: |
cd esp32c3-hal/
cargo +nightly check --examples --features=eh1,ufmt,log
cargo +nightly check --examples --features=eh1,ufmt,defmt
- name: check esp32c3-hal (async, systick)
run: cd esp32c3-hal/ && cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-systick
- name: check esp32c3-hal (async, timg0)
Expand All @@ -185,6 +206,11 @@ jobs:
run: cd esp32c3-hal/ && cargo check --example=interrupt_preemption --features=interrupt-preemption
- name: check esp32c3-hal (direct-vectoring)
run: cd esp32c3-hal/ && cargo check --example=direct-vectoring --features=direct-vectoring
- name: check esp32c3-hal (embassy, log/defmt)
run: |
cd esp32c3-hal/
cargo +nightly check --examples --features=embassy,embassy-time-timg0,defmt
cargo +nightly check --examples --features=embassy,embassy-time-timg0,log
# Ensure documentation can be built
- name: rustdoc
run: cd esp32c3-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -212,7 +238,10 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32c6-hal (common features)
run: cd esp32c6-hal/ && cargo +nightly check --examples --features=eh1,ufmt
run: |
cd esp32c6-hal/
cargo +nightly check --examples --features=eh1,ufmt,log
cargo +nightly check --examples --features=eh1,ufmt,defmt
- name: check esp32c6-hal (async, systick)
run: cd esp32c6-hal/ && cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-systick
- name: check esp32c6-hal (async, timg0)
Expand All @@ -229,6 +258,11 @@ jobs:
run: cd esp32c6-hal/ && cargo check --example=interrupt_preemption --features=interrupt-preemption
- name: check esp32c6-hal (direct-vectoring)
run: cd esp32c6-hal/ && cargo check --example=direct-vectoring --features=direct-vectoring
- name: check esp32c6-hal (embassy, log/defmt)
run: |
cd esp32c6-hal/
cargo +nightly check --examples --features=embassy,embassy-time-timg0,defmt
cargo +nightly check --examples --features=embassy,embassy-time-timg0,log
# Ensure documentation can be built
- name: rustdoc
run: cd esp32c6-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -276,7 +310,10 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32h2-hal (common features)
run: cd esp32h2-hal/ && cargo +nightly check --examples --features=eh1,ufmt
run: |
cd esp32h2-hal/
cargo +nightly check --examples --features=eh1,ufmt,log
cargo +nightly check --examples --features=eh1,ufmt,defmt
- name: check esp32h2-hal (async, systick)
run: cd esp32h2-hal/ && cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-systick
- name: check esp32h2-hal (async, timg0)
Expand All @@ -293,6 +330,11 @@ jobs:
run: cd esp32h2-hal/ && cargo check --example=interrupt_preemption --features=interrupt-preemption
- name: check esp32h2-hal (direct-vectoring)
run: cd esp32h2-hal/ && cargo check --example=direct-vectoring --features=direct-vectoring
- name: check esp32h2-hal (embassy, log/defmt)
run: |
cd esp32h2-hal/
cargo +nightly check --examples --features=embassy,embassy-time-timg0,defmt
cargo +nightly check --examples --features=embassy,embassy-time-timg0,log
# Ensure documentation can be built
- name: rustdoc
run: cd esp32h2-hal/ && cargo doc --features=eh1
Expand All @@ -316,7 +358,10 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32s2-hal (common features)
run: cd esp32s2-hal/ && cargo check --examples --features=eh1,ufmt
run: |
cd esp32s2-hal/
cargo check --examples --features=eh1,ufmt,log
cargo check --examples --features=eh1,ufmt,defmt
# FIXME: `time-systick` feature disabled for now, see 'esp32s2-hal/Cargo.toml'.
# - name: check esp32s2-hal (async, systick)
# run: cd esp32s2-hal/ && cargo check --example=embassy_hello_world --features=embassy,embassy-time-systick,executor
Expand All @@ -332,6 +377,11 @@ jobs:
cargo check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread
cargo check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread
cargo check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread
- name: check esp32s2-hal (embassy, log/defmt)
run: |
cd esp32s2-hal/
cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,defmt
cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,log
# Ensure documentation can be built
- name: rustdoc
run: cd esp32s2-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -359,7 +409,10 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32s3-hal (common features)
run: cd esp32s3-hal/ && cargo check --examples --features=eh1,ufmt
run: |
cd esp32s3-hal/
cargo check --examples --features=eh1,ufmt,log
cargo check --examples --features=eh1,ufmt,defmt
- name: check esp32s3-hal (embassy, timg0)
run: |
cd esp32s3-hal/
Expand Down Expand Up @@ -390,6 +443,11 @@ jobs:
cargo check --example=embassy_i2c --features=embassy,embassy-time-systick,async,embassy-executor-thread
- name: check esp32s3-hal (octal psram)
run: cd esp32s3-hal/ && cargo check --example=octal_psram --features=opsram_2m --release # This example requires release!
- name: check esp32s3-hal (embassy, log/defmt)
run: |
cd esp32s3-hal/
cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,defmt
cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,log
# Ensure documentation can be built
- name: rustdoc
run: cd esp32s3-hal/ && cargo doc --features=eh1
Expand Down Expand Up @@ -431,15 +489,15 @@ jobs:

# Verify the MSRV for all RISC-V chips.
- name: msrv (esp32c2-hal)
run: cd esp32c2-hal/ && cargo check --features=eh1,ufmt
run: cd esp32c2-hal/ && cargo check --features=eh1,ufmt,log
- name: msrv (esp32c3-hal)
run: cd esp32c3-hal/ && cargo check --features=eh1,ufmt
run: cd esp32c3-hal/ && cargo check --features=eh1,ufmt,log
- name: msrv (esp32c6-hal)
run: cd esp32c6-hal/ && cargo check --features=eh1,ufmt
run: cd esp32c6-hal/ && cargo check --features=eh1,ufmt,log
- name: msrv (esp32c6-lp-hal)
run: cd esp32c6-lp-hal/ && cargo check
- name: msrv (esp32h2-hal)
run: cd esp32h2-hal/ && cargo check --features=eh1,ufmt
run: cd esp32h2-hal/ && cargo check --features=eh1,ufmt,log

msrv-xtensa:
runs-on: ubuntu-latest
Expand All @@ -454,11 +512,11 @@ jobs:

# Verify the MSRV for all Xtensa chips.
- name: msrv (esp32-hal)
run: cd esp32-hal/ && cargo check --features=eh1,ufmt
run: cd esp32-hal/ && cargo check --features=eh1,ufmt,log
- name: msrv (esp32s2-hal)
run: cd esp32s2-hal/ && cargo check --features=eh1,ufmt
run: cd esp32s2-hal/ && cargo check --features=eh1,ufmt,log
- name: msrv (esp32s3-hal)
run: cd esp32s3-hal/ && cargo check --features=eh1,ufmt
run: cd esp32s3-hal/ && cargo check --features=eh1,ufmt,log

# --------------------------------------------------------------------------
# Lint
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add interrupt-executor for Xtensa MCUs (#723, #756).
- Add missing `Into<Gpio<Analog, GPIONUN>>` conversion (#764)
- Updated `clock` module documentation (#774)
- Add `log` feature to enable log output (#773)
- Add `defmt` feature to enable log output (#773)

### Changed

- Update the `embedded-hal-*` packages to `1.0.0-rc.1` and implement traits from `embedded-io` and `embedded-io-async` (#747)
- Moved AlignmentHelper to its own module (#753)
- Disable all watchdog timers by default at startup (#763)
- `log` crate is now opt-in (#773)

### Fixed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The **M**inimum **S**upported **R**ust **V**ersions are:
- This corresponds to the date that the `1.65.0` release was branched from `master`
- `1.65.0` for Xtensa devices (**ESP32**, **ESP32-S2**, **ESP32-S3**)
- `1.67.0` for all `async` examples (`embassy_hello_world`, `embassy_wait`, etc.)
- latest `stable` when using the `defmt` feature

It should be noted that targeting the Xtensa ISA currently requires the use of the [esp-rs/rust] compiler fork. Our recommend method of installation is [espup].

Expand Down
15 changes: 14 additions & 1 deletion esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bitflags = "2.3.3"
bitfield = "0.14.0"
cfg-if = "1.0.0"
critical-section = "1.1.2"
defmt = { version = "=0.3.5", optional = true }
embedded-can = { version = "0.4.1", optional = true }
embedded-dma = "0.2.0"
embedded-hal = { version = "0.2.7", features = ["unproven"] }
Expand All @@ -24,7 +25,7 @@ embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true }
embedded-io = "0.5.0"
esp-synopsys-usb-otg = { version = "0.3.2", optional = true, features = ["fs", "esp32sx"] }
fugit = "0.3.7"
log = "0.4.20"
log = { version = "0.4.20", optional = true }
lock_api = { version = "0.4.10", optional = true }
nb = "1.1.0"
paste = "1.0.14"
Expand Down Expand Up @@ -132,3 +133,15 @@ debug = [
"esp32s2?/impl-register-debug",
"esp32s3?/impl-register-debug",
]

log = ["dep:log"]
defmt = [
"dep:defmt",
"embassy-executor?/defmt",
"embassy-sync?/defmt",
"embassy-time?/defmt",
"embassy-futures?/defmt",
"embedded-hal-1?/defmt-03",
"embedded-io/defmt-03",
"embedded-io-async?/defmt-03",
]
4 changes: 4 additions & 0 deletions esp-hal-common/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const CHUNK_SIZE: usize = 4092;

/// DMA Errors
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaError {
InvalidAlignment,
OutOfDescriptors,
Expand All @@ -96,6 +97,7 @@ pub enum DmaError {
/// DMA Priorities
#[cfg(gdma)]
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaPriority {
Priority0 = 0,
Priority1 = 1,
Expand All @@ -113,13 +115,15 @@ pub enum DmaPriority {
/// The values need to match the TRM
#[cfg(pdma)]
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaPriority {
Priority0 = 0,
}

/// DMA capable peripherals
/// The values need to match the TRM
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaPeripheral {
Spi2 = 0,
#[cfg(any(pdma, esp32s3))]
Expand Down
4 changes: 2 additions & 2 deletions esp-hal-common/src/embassy/executor/xtensa/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ macro_rules! from_cpu {
fn enable(priority: interrupt::Priority) {
let mask = 1 << $irq;
if FROM_CPU_IRQ_USED.fetch_or(mask, Ordering::SeqCst) & mask != 0 {
panic!(concat!("FROM_CPU_", $irq, " is already used by a different executor."));
panic!("FROM_CPU_{} is already used by a different executor.", $irq);
}

interrupt::enable(peripherals::Interrupt::[<FROM_CPU_INTR $irq>], priority).unwrap();
unwrap!(interrupt::enable(peripherals::Interrupt::[<FROM_CPU_INTR $irq>], priority));
}

fn number() -> usize {
Expand Down
5 changes: 2 additions & 3 deletions esp-hal-common/src/embassy/executor/xtensa/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ impl Executor {
/// Create a new Executor.
pub fn new() -> Self {
#[cfg(multi_core)]
interrupt::enable(
unwrap!(interrupt::enable(
peripherals::Interrupt::FROM_CPU_INTR0,
interrupt::Priority::Priority1,
)
.unwrap();
));

Self {
inner: raw::Executor::new(usize::from_le_bytes([0, get_core() as u8, 0, 0]) as *mut ()),
Expand Down
15 changes: 12 additions & 3 deletions esp-hal-common/src/embassy/time_driver_systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ impl EmbassyTimer {
pub fn init(_clocks: &Clocks, _systimer: TimerType) {
use crate::{interrupt, interrupt::Priority, macros::interrupt};

interrupt::enable(peripherals::Interrupt::SYSTIMER_TARGET0, Priority::max()).unwrap();
interrupt::enable(peripherals::Interrupt::SYSTIMER_TARGET1, Priority::max()).unwrap();
interrupt::enable(peripherals::Interrupt::SYSTIMER_TARGET2, Priority::max()).unwrap();
unwrap!(interrupt::enable(
peripherals::Interrupt::SYSTIMER_TARGET0,
Priority::max()
));
unwrap!(interrupt::enable(
peripherals::Interrupt::SYSTIMER_TARGET1,
Priority::max()
));
unwrap!(interrupt::enable(
peripherals::Interrupt::SYSTIMER_TARGET2,
Priority::max()
));

#[interrupt]
fn SYSTIMER_TARGET0() {
Expand Down
10 changes: 8 additions & 2 deletions esp-hal-common/src/embassy/time_driver_timg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ impl EmbassyTimer {

timer.set_counter_active(true);

interrupt::enable(peripherals::Interrupt::TG0_T0_LEVEL, Priority::max()).unwrap();
unwrap!(interrupt::enable(
peripherals::Interrupt::TG0_T0_LEVEL,
Priority::max()
));
#[cfg(any(esp32, esp32s2, esp32s3))]
interrupt::enable(peripherals::Interrupt::TG0_T1_LEVEL, Priority::max()).unwrap();
unwrap!(interrupt::enable(
peripherals::Interrupt::TG0_T1_LEVEL,
Priority::max()
));

#[interrupt]
fn TG0_T0_LEVEL() {
Expand Down
Loading

0 comments on commit 7866896

Please sign in to comment.