diff --git a/doc/RTFM.md b/doc/RTFM.md index ec0df640a0701fbc06c9932f79dfae81dc4c1363..d217545f968416a33313dd7601d2fd4d68e474a3 100644 --- a/doc/RTFM.md +++ b/doc/RTFM.md @@ -205,6 +205,52 @@ or Let us study the `nested` example in detail. +```rust +fn main() { + let init: fn(stm32f40x::Peripherals, init::Resources) = init; + rtfm::atomic(unsafe { &mut rtfm::Threshold::new(0) }, |_t| unsafe { + let _late_resources = + init(stm32f40x::Peripherals::all(), init::Resources::new()); + let nvic = &*stm32f40x::NVIC.get(); + let prio_bits = stm32f40x::NVIC_PRIO_BITS; + let hw = ((1 << prio_bits) - 2u8) << (8 - prio_bits); + nvic.set_priority(stm32f40x::Interrupt::EXTI1, hw); + nvic.enable(stm32f40x::Interrupt::EXTI1); + let prio_bits = stm32f40x::NVIC_PRIO_BITS; + let hw = ((1 << prio_bits) - 1u8) << (8 - prio_bits); + nvic.set_priority(stm32f40x::Interrupt::EXTI0, hw); + nvic.enable(stm32f40x::Interrupt::EXTI0); + let prio_bits = stm32f40x::NVIC_PRIO_BITS; + let hw = ((1 << prio_bits) - 1u8) << (8 - prio_bits); + nvic.set_priority(stm32f40x::Interrupt::EXTI3, hw); + nvic.enable(stm32f40x::Interrupt::EXTI3); + let prio_bits = stm32f40x::NVIC_PRIO_BITS; + let hw = ((1 << prio_bits) - 3u8) << (8 - prio_bits); + nvic.set_priority(stm32f40x::Interrupt::EXTI2, hw); + nvic.enable(stm32f40x::Interrupt::EXTI2); + }); + let idle: fn() -> ! = idle; + idle(); +} +fn init(_p: init::Peripherals, _r: init::Resources) {} +#[inline(never)] +fn idle() -> ! { + let mut stdout = hio::hstdout().unwrap(); + stdout + .write_fmt(::core::fmt::Arguments::new_v1( + &["Hello, world!\n"], + &match () { + () => [], + }, + )) + .unwrap(); + rtfm::bkpt(); + rtfm::set_pending(Interrupt::EXTI3); + loop { + rtfm::wfi(); + } +} +```