-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use defmt-rtt and panic-probe for evk boards
The evk boards have a built in debug probe. When running firmware with probe-rs defmt-rtt provides a very fast channel of low cost debug println's that everyone finds really helpful. Using panic-probe with defmt-rtt has a second benefit in allowing for programs to inform probe-rs the firmware has exited cleanly. This can be used for writing samples and tests that exit. This also makes the imxrt-log defmt feature optional to the boards otherwise the two implementations of the defmt logger cause duplicate symbols to show up. Tested on an 1010evk and 1060evk.
- Loading branch information
Showing
9 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//! Demonstrates defmt logging using RTT with RTIC. | ||
#![no_std] | ||
#![no_main] | ||
|
||
#[rtic::app(device = board, peripherals = false, dispatchers = [BOARD_SWTASK0])] | ||
mod app { | ||
|
||
// | ||
// Configure the demo below. | ||
// | ||
|
||
/// How frequently (milliseconds) should we make a log message? | ||
/// | ||
/// Decrease this constant to log more frequently. | ||
const MAKE_LOG_INTERVAL_MS: u32 = board::PIT_FREQUENCY / 1_000 * 250; | ||
|
||
use imxrt_hal as hal; | ||
// | ||
// End configurations. | ||
// | ||
|
||
#[local] | ||
struct Local { | ||
/// Toggle when we make a log. | ||
led: board::Led, | ||
/// This timer tells us how frequently to generate | ||
/// logs. It's always used. | ||
make_log: hal::pit::Pit<2>, | ||
} | ||
|
||
#[shared] | ||
struct Shared {} | ||
|
||
#[init] | ||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { | ||
let mut cortex_m = cx.core; | ||
let ( | ||
board::Common { | ||
pit: (_, _, mut make_log, _), | ||
.. | ||
}, | ||
board::Specifics { led, .. }, | ||
) = board::new(); | ||
cortex_m.DCB.enable_trace(); | ||
cortex_m::peripheral::DWT::unlock(); | ||
cortex_m.DWT.enable_cycle_counter(); | ||
|
||
make_log.set_load_timer_value(MAKE_LOG_INTERVAL_MS); | ||
make_log.set_interrupt_enable(true); | ||
make_log.enable(); | ||
|
||
(Shared {}, Local { led, make_log }, init::Monotonics()) | ||
} | ||
|
||
#[task(binds = BOARD_PIT, local = [led, make_log, counter: u32 = 0], priority = 1)] | ||
fn pit_interrupt(cx: pit_interrupt::Context) { | ||
let pit_interrupt::LocalResources { | ||
make_log, | ||
led, | ||
counter, | ||
} = cx.local; | ||
|
||
// Is it time for us to send a new log message? | ||
if make_log.is_elapsed() { | ||
led.toggle(); | ||
while make_log.is_elapsed() { | ||
make_log.clear_elapsed(); | ||
} | ||
|
||
let count = cycles(|| { | ||
defmt::println!("Hello from defmt over RTT! The counter is {=u32}", counter) | ||
}); | ||
|
||
defmt::println!( | ||
"That last message took {=u32} cycles to be copied into the logging buffer", | ||
count | ||
); | ||
|
||
*counter += 1; | ||
} | ||
} | ||
|
||
/// Count the clock cycles required to execute `f` | ||
fn cycles<F: FnOnce()>(f: F) -> u32 { | ||
let start = cortex_m::peripheral::DWT::cycle_count(); | ||
f(); | ||
let end = cortex_m::peripheral::DWT::cycle_count(); | ||
end - start | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters