2 个版本
新版本 0.1.1 | 2024 年 8 月 22 日 |
---|---|
0.1.0 | 2024 年 8 月 20 日 |
#525 在 开发工具
每月 96 次下载
用于 panic-tracing-rtt
10KB
135 行
tracing-rtt
功能
- OpenOCD RTT
- 嵌入式时间
- 过滤器
用法
Cargo.toml
[dependencies]
tracing = { version = "0.1", default-features = false }
# tracing-rtt = { git = "https://github.com/caizhengxin/tracing-rtt.git", default-features = false, features = ["alloc"] }
tracing-rtt = { git = "https://github.com/caizhengxin/tracing-rtt.git", default-features = false, features = ["heapless"] }
或
[dependencies]
tracing = { version = "0.1", default-features = false }
tracing-rtt = { version = "0.1.0", default-features = false, features = ["heapless"] }
# tracing-rtt = { version = "0.1.0", default-features = false, features = ["alloc"] }
main.rs
#![no_std]
#![no_main]
use cortex_m_rt::entry;
use panic_tracing_rtt as _;
use cortex_m::Peripherals;
use stm32f4xx_hal::{
pac,
prelude::*,
rtc::Rtc,
};
use rand_core::RngCore;
// features = ["alloc"]
// use embedded_alloc::Heap;
// #[global_allocator]
// static HEAP: Heap = Heap::empty();
// pub fn embedded_heap_init() {
// use core::mem::MaybeUninit;
// const HEAP_SIZE: usize = 1024;
// static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
// unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
// }
#[entry]
fn main() -> ! {
// init heap
// embedded_heap_init();
// init RTT
tracing_rtt::init();
let mut dp = pac::Peripherals::take().unwrap();
let cp = Peripherals::take().unwrap();
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr
.use_hse(8.MHz())
.require_pll48clk()
// .sysclk(48.MHz())
.freeze();
let mut delay = cp.SYST.delay(&clocks);
let mut rng = dp.RNG.constrain(&clocks);
// let mut rtc = Rtc::new(dp.RTC, &mut dp.PWR);
let mut rtc = Rtc::new_lsi(dp.RTC, &mut dp.PWR);
// LED
let gpiofs = dp.GPIOF.split();
let mut led0 = gpiofs.pf9.into_push_pull_output();
let mut led1 = gpiofs.pf10.into_push_pull_output();
loop {
tracing::debug!("time: {} random: {}", rtc.get_datetime(), rng.next_u64());
led0.set_low();
led1.set_low();
delay.delay_ms(50);
led0.set_high();
led1.set_high();
delay.delay_ms(50);
}
}
示例
依赖项
~1MB
~16K SLoC