main.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #![cfg_attr(test, allow(unused_imports))]
  2. #![cfg_attr(not(test), no_std)]
  3. #![cfg_attr(not(test), no_main)]
  4. // pick a panicking behavior
  5. #[cfg(not(test))]
  6. use panic_halt as _; // you can put a breakpoint on `rust_begin_unwind` to catch panics
  7. // use panic_abort as _; // requires nightly
  8. // use panic_itm as _; // logs messages over ITM; requires ITM support
  9. // use panic_semihosting as _; // logs messages to the host stderr; requires a debugger
  10. // use cortex_m::asm;
  11. use cortex_m_rt::entry;
  12. // use stm32l4::stm32l4x2;
  13. use stm32l4xx_hal::{prelude::*, pac, rcc};
  14. use cortex_m_semihosting::{debug, hprintln};
  15. #[cfg(not(test))]
  16. #[entry]
  17. fn main() -> ! {
  18. // asm::nop(); // To not have main optimize to abort in release mode, remove when you add code
  19. hprintln!("Hello, world!").unwrap();
  20. let peripherals = pac::Peripherals::take().unwrap();
  21. let _core = cortex_m::Peripherals::take().unwrap();
  22. let gpioa = &peripherals.GPIOA;
  23. gpioa.odr.modify(|_, w| w.odr0().set_bit());
  24. loop {
  25. // your code goes here
  26. }
  27. }
  28. fn add(a: i32, b: i32) -> i32 {
  29. a + b
  30. }
  31. #[cfg(test)]
  32. mod test {
  33. use super::*;
  34. #[test]
  35. fn foo() {
  36. println!("tests work!");
  37. assert!(2 == add(1,1));
  38. }
  39. }