-
Notifications
You must be signed in to change notification settings - Fork 2
/
hello.rs
60 lines (45 loc) · 1.33 KB
/
hello.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#![no_main]
#![no_std]
use nrf9160_rust_starter as _; // global logger + panicking-behavior + memory layout
use nrf9160_hal as hal;
use hal::gpio::Level;
use hal::uarte;
use core::fmt::Write;
#[cortex_m_rt::entry]
fn main() -> ! {
let p = hal::pac::Peripherals::take().unwrap();
let pins0 = hal::gpio::p0::Parts::new(p.P0_NS);
let pins = hal::uarte::Pins {
rxd: pins0.p0_05.into_floating_input().degrade(),
txd: pins0.p0_06.into_push_pull_output(Level::High).degrade(),
cts: None,
rts: None,
};
let device = p.UARTE0_NS;
// init 1
let mut uart = hal::Uarte::new(
device,
pins,
uarte::Parity::EXCLUDED,
uarte::Baudrate::BAUD115200,
);
write!(uart, "write 1\r\n").unwrap();
write!(uart, "write 2\r\n").unwrap();
// deinit 1
let (device, pins) = uart.free();
device.events_txstopped.reset();
device.tasks_stoptx.write(|w| w.tasks_stoptx().trigger());
while device.events_txstopped.read().bits() == 0 {
cortex_m::asm::nop();
}
device.enable.write(|w| w.enable().disabled());
// init 2
let mut uart = hal::Uarte::new(
device,
pins,
uarte::Parity::EXCLUDED,
uarte::Baudrate::BAUD115200,
);
write!(uart, "write 3\r\n").unwrap();
nrf9160_rust_starter::exit()
}