exception.rs 849 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //! Overriding an exception handler
  2. //!
  3. //! You can override an exception handler using the [`#[exception]`][1] attribute.
  4. //!
  5. //! [1]: https://rust-embedded.github.io/cortex-m-rt/0.6.1/cortex_m_rt_macros/fn.exception.html
  6. //!
  7. //! ---
  8. #![deny(unsafe_code)]
  9. #![no_main]
  10. #![no_std]
  11. use panic_halt as _;
  12. use cortex_m::peripheral::syst::SystClkSource;
  13. use cortex_m::Peripherals;
  14. use cortex_m_rt::{entry, exception};
  15. use cortex_m_semihosting::hprint;
  16. #[entry]
  17. fn main() -> ! {
  18. let p = Peripherals::take().unwrap();
  19. let mut syst = p.SYST;
  20. // configures the system timer to trigger a SysTick exception every second
  21. syst.set_clock_source(SystClkSource::Core);
  22. syst.set_reload(8_000_000); // period = 1s
  23. syst.enable_counter();
  24. syst.enable_interrupt();
  25. loop {}
  26. }
  27. #[exception]
  28. fn SysTick() {
  29. hprint!(".").unwrap();
  30. }