Skip to content

Commit 8c13384

Browse files
committed
feat(examples): use UART output in basic_gr_peach
1 parent f0c6134 commit 8c13384

File tree

5 files changed

+36
-43
lines changed

5 files changed

+36
-43
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/basic_gr_peach/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ authors = ["yvt <i@yvt.jp>"]
55
edition = "2018"
66

77
[dependencies]
8-
constance_support_rza1 = { path = "../../src/constance_support_rza1" }
8+
constance_support_rza1 = { path = "../../src/constance_support_rza1", features = ["semver-exempt"] }
99
constance_port_arm = { path = "../../src/constance_port_arm" }
1010
constance = { path = "../../src/constance" }
1111

1212
rtt-target = { version = "0.2.0" }
13+
rza1 = { version = "0.2.0", features = ["cpg", "gpio", "scif"] }

examples/basic_gr_peach/src/main.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ use constance::{
4949
prelude::*,
5050
};
5151

52-
// Install a global panic handler that uses RTT
53-
mod panic_rtt_target;
52+
// Install a global panic handler that uses the serial port
53+
mod panic_serial;
5454

5555
#[derive(Debug)]
5656
struct Objects {
@@ -65,28 +65,23 @@ const fn configure_app(b: &mut CfgBuilder<System>) -> Objects {
6565

6666
System::configure_os_timer(b);
6767

68-
// Initialize RTT (Real-Time Transfer) with a single up channel and set
69-
// it as the print channel for the printing macros
68+
// Initialize the serial port
7069
StartupHook::build()
7170
.start(|_| {
72-
let channels = rtt_target::rtt_init! {
73-
up: {
74-
0: {
75-
size: 1024
76-
mode: NoBlockSkip
77-
name: "Terminal"
78-
}
79-
}
80-
};
81-
82-
unsafe {
83-
rtt_target::set_print_channel_cs(
84-
channels.up.0,
85-
&((|arg, f| f(arg)) as rtt_target::CriticalSectionFunc),
86-
)
87-
};
88-
89-
rtt_target::rprintln!("RTT is ready");
71+
use support_rza1::serial::ScifExt;
72+
73+
#[allow(non_snake_case)]
74+
let rza1::Peripherals {
75+
CPG, GPIO, SCIF2, ..
76+
} = unsafe { rza1::Peripherals::steal() };
77+
78+
SCIF2.enable_clock(&CPG);
79+
SCIF2.configure_pins(&GPIO);
80+
SCIF2.configure_uart(115200);
81+
82+
support_rza1::stdout::set_stdout(SCIF2.into_nb_writer());
83+
84+
support_rza1::sprintln!("UART is ready");
9085
})
9186
.finish(b);
9287

@@ -101,14 +96,14 @@ const fn configure_app(b: &mut CfgBuilder<System>) -> Objects {
10196
}
10297

10398
fn task1_body(_: usize) {
104-
rtt_target::rprintln!("COTTAGE = {:?}", COTTAGE);
99+
support_rza1::sprintln!("COTTAGE = {:?}", COTTAGE);
105100

106101
COTTAGE.task2.activate().unwrap();
107102
}
108103

109104
fn task2_body(_: usize) {
110105
loop {
111-
rtt_target::rprintln!("time = {:?}", System::time().unwrap());
106+
support_rza1::sprintln!("time = {:?}", System::time().unwrap());
112107
System::sleep(constance::time::Duration::from_secs(1)).unwrap();
113108
}
114109
}

examples/basic_gr_peach/src/panic_rtt_target.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use constance_support_rza1::sprintln;
2+
use core::panic::PanicInfo;
3+
4+
// Install a global panic handler that uses the serial port
5+
#[inline(never)]
6+
#[panic_handler]
7+
fn panic(info: &PanicInfo) -> ! {
8+
// Disable IRQ
9+
unsafe { llvm_asm!("cpsid i"::::"volatile") };
10+
11+
sprintln!("{}", info);
12+
13+
loop {}
14+
}

0 commit comments

Comments
 (0)