Skip to content

Commit ed3d2dc

Browse files
committed
added example code
1 parent fc623b7 commit ed3d2dc

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/serial.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,21 @@ uart_pins! {
350350
}
351351

352352
/// Serial abstraction
353+
///
354+
/// # Examples
355+
/// ```
356+
/// let dp = pac::Peripherals::take().unwrap();
357+
/// let rcc = dp.RCC.constrain();
358+
/// let ccdr = rcc.freeze();
359+
/// let serial = Serial::usart3(
360+
/// dp.USART3,
361+
/// serial::config::Config::default().baudrate(115200.bps()),
362+
/// ccdr.peripheral.USART3,
363+
/// &ccdr.clocks
364+
/// ).unwrap();
365+
/// // core::fmt::Write is implemented for tx.
366+
/// writeln!(tx, Test\r").unwrap();
367+
/// ```
353368
pub struct Serial<USART> {
354369
pub(crate) usart: USART,
355370
}

src/timer.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,21 @@ pub trait TimerExt<TIM> {
177177
}
178178

179179
/// Hardware timers
180+
///
181+
/// # Examples
182+
///
183+
/// ```rust
184+
/// let dp = pac::Peripherals::take().unwrap();
185+
/// let rcc = dp.RCC.constrain();
186+
/// let ccdr = rcc.freeze();
187+
/// let mut timer = Timer::tim1(dp.TIM1, ccdr.peripheral.TIM1, &ccdr.clocks);
188+
/// timer.start(1.hz());
189+
/// loop {
190+
/// // Do something here and then block for 1 second
191+
/// // do_something();
192+
/// block(timer.wait()).unwrap();
193+
/// }
194+
/// ```
180195
#[derive(Debug)]
181196
pub struct Timer<TIM> {
182197
clk: u32,

0 commit comments

Comments
 (0)