Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- [#xxx]: Pre-relase cleanup
Comment thread
Urhengulas marked this conversation as resolved.
Outdated
- [#695]: `defmt-rtt`: Refactor rtt [3/2]
- [#689]: `defmt-rtt`: Update to critical-section 1.0
- [#692]: `defmt-macros`: Wrap const fn in const item to ensure compile-time-evaluation.
Expand All @@ -21,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [#679]: `CI`: Add changelog enforcer
- [#678]: Satisfy clippy

[#xxx]: https://github.com/knurling-rs/defmt/pull/xxx
Comment thread
Urhengulas marked this conversation as resolved.
Outdated
[#695]: https://github.com/knurling-rs/defmt/pull/695
[#692]: https://github.com/knurling-rs/defmt/pull/692
[#690]: https://github.com/knurling-rs/defmt/pull/690
Expand Down
9 changes: 8 additions & 1 deletion firmware/defmt-rtt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ fn main() {

std::fs::write(
out_file_path,
format!("pub(crate) const BUF_SIZE: usize = {};", size),
format!(
"/// RTT buffer size (default: 1024).
///
/// Can be customized by setting the `DEFMT_RTT_BUFFER_SIZE` environment variable.
/// Use a power of 2 for best performance.
pub(crate) const BUF_SIZE: usize = {};",
size
),
)
.unwrap();
}
15 changes: 6 additions & 9 deletions firmware/defmt-rtt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,11 @@
#![no_std]

mod channel;
mod consts;

use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

use crate::channel::Channel;

mod consts;

/// RTT buffer size. Default: 1024; can be customized by setting the `DEFMT_RTT_BUFFER_SIZE` environment variable.
/// Use a power of 2 for best performance.
use crate::consts::BUF_SIZE;
use crate::{channel::Channel, consts::BUF_SIZE};

#[defmt::global_logger]
struct Logger;
Expand All @@ -58,11 +53,12 @@ unsafe impl defmt::Logger for Logger {
// safety: Must be paired with corresponding call to release(), see below
let restore = unsafe { critical_section::acquire() };

// safety: accessing the `static mut` is OK because we have acquired a critical section.
if TAKEN.load(Ordering::Relaxed) {
panic!("defmt logger taken reentrantly")
}

// no need for CAS because interrupts are disabled
// safety: accessing the `static mut` is OK because we have acquired a critical section.
TAKEN.store(true, Ordering::Relaxed);

// safety: accessing the `static mut` is OK because we have acquired a critical section.
Expand All @@ -73,14 +69,15 @@ unsafe impl defmt::Logger for Logger {
}

unsafe fn flush() {
// SAFETY: if we get here, the global logger mutex is currently acquired
// safety: accessing the `&'static _` is OK because we have acquired a critical section.
handle().flush();
}

unsafe fn release() {
// safety: accessing the `static mut` is OK because we have acquired a critical section.
ENCODER.end_frame(do_write);

// safety: accessing the `static mut` is OK because we have acquired a critical section.
TAKEN.store(false, Ordering::Relaxed);

// safety: accessing the `static mut` is OK because we have acquired a critical section.
Expand Down
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmt-parser = { path = "../parser", features = ["unstable"], version = "=0.3.1"
proc-macro-error = "1"
proc-macro2 = "1"
quote = "1"
syn = { version = "1.0.100", features = ["full"] }
syn = { version = "1", features = ["full"] }

[dev_dependencies]
maplit = "1"
Expand Down