Skip to content

Commit 5101104

Browse files
committed
rtt
1 parent d97e4ab commit 5101104

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

examples/i2c_scanner.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,17 @@
66

77
use core::ops::Range;
88

9-
use panic_semihosting as _;
9+
use rtt_target::{rprint, rprintln, rtt_init_print};
1010

1111
use cortex_m_rt::entry;
12-
use cortex_m_semihosting::{hprint, hprintln};
1312

14-
use stm32f4xx_hal::{
15-
self as hal,
16-
gpio::GpioExt,
17-
i2c::{DutyCycle, I2c},
18-
pac,
19-
prelude::*,
20-
};
13+
use stm32f4xx_hal::{self as hal, gpio::GpioExt, i2c::I2c, pac, prelude::*};
2114

2215
const VALID_ADDR_RANGE: Range<u8> = 0x08..0x78;
2316

2417
#[entry]
2518
fn main() -> ! {
19+
rtt_init_print!();
2620
let dp = pac::Peripherals::take().unwrap();
2721

2822
let rcc = dp.RCC.constrain();
@@ -36,31 +30,39 @@ fn main() -> ! {
3630
let mut i2c = I2c::new(
3731
dp.I2C1,
3832
(scl, sda),
39-
hal::i2c::Mode::standard(100_000.Hz()),
33+
hal::i2c::Mode::standard(100.kHz()),
4034
&clocks,
4135
);
4236

43-
hprintln!("Start i2c scanning...");
44-
hprintln!();
37+
rprintln!("Start i2c scanning...");
38+
rprintln!();
4539

4640
for addr in 0x00_u8..0x80 {
4741
// Write the empty array and check the slave response.
4842
let byte: [u8; 1] = [0; 1];
4943
if VALID_ADDR_RANGE.contains(&addr) && i2c.write(addr, &byte).is_ok() {
50-
hprint!("{:02x}", addr);
44+
rprint!("{:02x}", addr);
5145
} else {
52-
hprint!("..");
46+
rprint!("..");
5347
}
5448
if addr % 0x10 == 0x0F {
55-
hprintln!();
49+
rprintln!();
5650
} else {
57-
hprint!(" ");
51+
rprint!(" ");
5852
}
5953
}
6054

61-
hprintln!();
62-
hprintln!("Done!");
55+
rprintln!();
56+
rprintln!("Done!");
6357

6458
#[allow(clippy::empty_loop)]
6559
loop {}
6660
}
61+
62+
use core::panic::PanicInfo;
63+
#[inline(never)]
64+
#[panic_handler]
65+
fn panic(info: &PanicInfo) -> ! {
66+
rprintln!("{}", info);
67+
loop {} // You might need a compiler fence in here.
68+
}

0 commit comments

Comments
 (0)