|
26 | 26 | //!
|
27 | 27 | //! ```
|
28 | 28 | //!
|
| 29 | +//! #![deny(warnings)] |
| 30 | +//! #![feature(const_fn)] |
29 | 31 | //! #![no_std]
|
30 | 32 | //!
|
31 | 33 | //! extern crate cortex_m;
|
| 34 | +//! extern crate cortex_m_semihosting; |
32 | 35 | //! #[macro_use(exception, interrupt)]
|
33 | 36 | //! extern crate stm32f103xx;
|
34 | 37 | //!
|
35 |
| -//! use cortex_m::interrupt; |
| 38 | +//! use core::cell::RefCell; |
| 39 | +//! use core::fmt::Write; |
| 40 | +//! |
| 41 | +//! use cortex_m::interrupt::{self, Mutex}; |
| 42 | +//! use cortex_m::peripheral::SystClkSource; |
| 43 | +//! use cortex_m_semihosting::hio::{self, HStdout}; |
| 44 | +//! use stm32f103xx::Interrupt; |
| 45 | +//! |
| 46 | +//! static HSTDOUT: Mutex<RefCell<Option<HStdout>>> = |
| 47 | +//! Mutex::new(RefCell::new(None)); |
36 | 48 | //!
|
37 | 49 | //! fn main() {
|
38 | 50 | //! interrupt::free(|cs| {
|
39 |
| -//! let _gpioa = stm32f103xx::GPIOA.borrow(cs); |
40 |
| -//! // do something with GPIOA |
| 51 | +//! let hstdout = HSTDOUT.borrow(cs); |
| 52 | +//! if let Ok(fd) = hio::hstdout() { |
| 53 | +//! *hstdout.borrow_mut() = Some(fd); |
| 54 | +//! } |
| 55 | +//! |
| 56 | +//! let nvic = stm32f103xx::NVIC.borrow(cs); |
| 57 | +//! nvic.enable(Interrupt::TIM2); |
| 58 | +//! |
| 59 | +//! let syst = stm32f103xx::SYST.borrow(cs); |
| 60 | +//! syst.set_clock_source(SystClkSource::Core); |
| 61 | +//! syst.set_reload(8_000_000); // 1s |
| 62 | +//! syst.enable_counter(); |
| 63 | +//! syst.enable_interrupt(); |
41 | 64 | //! });
|
42 | 65 | //! }
|
43 | 66 | //!
|
44 |
| -//! exception!(SYS_TICK, tick, locals: { |
45 |
| -//! ticks: u32 = 0; |
46 |
| -//! }); |
| 67 | +//! exception!(SYS_TICK, tick); |
| 68 | +//! |
| 69 | +//! fn tick() { |
| 70 | +//! interrupt::free(|cs| { |
| 71 | +//! let hstdout = HSTDOUT.borrow(cs); |
| 72 | +//! if let Some(hstdout) = hstdout.borrow_mut().as_mut() { |
| 73 | +//! writeln!(*hstdout, "Tick").ok(); |
| 74 | +//! } |
| 75 | +//! |
| 76 | +//! let nvic = stm32f103xx::NVIC.borrow(cs); |
47 | 77 | //!
|
48 |
| -//! fn tick(l: &mut SYS_TICK::Locals) { |
49 |
| -//! l.ticks += 1; |
50 |
| -//! // .. |
| 78 | +//! nvic.set_pending(Interrupt::TIM2); |
| 79 | +//! }); |
51 | 80 | //! }
|
52 | 81 | //!
|
53 | 82 | //! interrupt!(TIM2, tock, locals: {
|
|
56 | 85 | //!
|
57 | 86 | //! fn tock(l: &mut TIM2::Locals) {
|
58 | 87 | //! l.tocks += 1;
|
59 |
| -//! // .. |
| 88 | +//! |
| 89 | +//! interrupt::free(|cs| { |
| 90 | +//! let hstdout = HSTDOUT.borrow(cs); |
| 91 | +//! if let Some(hstdout) = hstdout.borrow_mut().as_mut() { |
| 92 | +//! writeln!(*hstdout, "Tock ({})", l.tocks).ok(); |
| 93 | +//! } |
| 94 | +//! }); |
60 | 95 | //! }
|
61 | 96 | //! ```
|
62 | 97 | // Auto-generated. Do not modify.
|
0 commit comments