nojtag.rs 831 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //! Disables the JTAG ports to give access to pb3, pb4 and PA15
  2. #![deny(unsafe_code)]
  3. #![deny(warnings)]
  4. #![no_main]
  5. #![no_std]
  6. extern crate cortex_m_rt as rt;
  7. extern crate panic_semihosting;
  8. extern crate stm32f1xx_hal as hal;
  9. use hal::prelude::*;
  10. use hal::stm32f103xx;
  11. use rt::{entry, exception, ExceptionFrame};
  12. #[entry]
  13. fn main() -> ! {
  14. let p = stm32f103xx::Peripherals::take().unwrap();
  15. let mut rcc = p.RCC.constrain();
  16. let mut gpiob = p.GPIOB.split(&mut rcc.apb2);
  17. let mut afio = p.AFIO.constrain(&mut rcc.apb2);
  18. afio.mapr.disable_jtag();
  19. gpiob.pb4.into_push_pull_output(&mut gpiob.crl).set_low();
  20. loop {}
  21. }
  22. #[exception]
  23. fn HardFault(ef: &ExceptionFrame) -> ! {
  24. panic!("{:#?}", ef);
  25. }
  26. #[exception]
  27. fn DefaultHandler(irqn: i16) {
  28. panic!("Unhandled exception (IRQn = {})", irqn);
  29. }