Skip to content

Commit d240c0b

Browse files
committed
Merge branch '✨-rza1' into 🦆
2 parents c67ec15 + cc6614c commit d240c0b

File tree

31 files changed

+1329
-73
lines changed

31 files changed

+1329
-73
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"src/constance_port_riscv_test_driver",
1414
"src/constance_port_std",
1515
"src/constance_portkit",
16+
"src/constance_support_rza1",
1617
"src/constance_test_runner",
1718
"src/constance_test_suite",
1819
]

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ cd examples/basic_nucleo_f401re
129129
cargo embed --release
130130
```
131131

132+
See [this document](examples/basic_gr_peach/README.md) for how to run the example application on [the GR-PEACH development board].
133+
134+
[the GR-PEACH development board]: https://www.renesas.com/us/en/products/gadget-renesas/boards/gr-peach.html#overview
135+
132136
## Prerequisites
133137

134138
You need a Nightly Rust compiler. This project is heavily reliant on unstable features, so it might or might not work with a newer compiler version. See the file `rust-toolchain` to find out which compiler version this project is currently tested with.
@@ -150,10 +154,13 @@ In this case, you need to run `rustup target add thumbv7m-none-eabi`.
150154
- [rustup], which will automatically install the version of Nightly Rust compiler specified by `rust-toolchain`
151155
- [QEMU](https://www.qemu.org/) 4.2 or later to test the Arm-M/-A port.
152156
- libusb 1.x to test the Arm-M/-A port.
157+
- [OpenOCD](http://openocd.org) to test the Arm-A port on GR-PEACH.
158+
- `JLinkExe`<sup>†</sup> from [J-Link Software] to test the RISC-V port on RED-V.
153159

154160
[rustup]: https://rustup.rs/
161+
[J-Link Software]: https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack
155162

156-
[Nix] users can use the provided `shell.nix` file to install all required software.
163+
[Nix] users can use the provided `shell.nix` file to install all required software except for those marked with <sup>†</sup>.
157164

158165
[Nix]: https://nixos.org/nix/
159166

@@ -163,6 +170,7 @@ In this case, you need to run `rustup target add thumbv7m-none-eabi`.
163170
- The Armv7-M port and NUCLEO-F401RE: `cargo run -p constance_test_runner -- -t nucleo_f401re`
164171
- The Armv7-M port and Arm MPS2+ AN385 (QEMU emulation): `cargo run -p constance_test_runner -- -t qemu_mps2_an385`
165172
- The Armv6-M port and Arm MPS2+ AN385 (QEMU emulation): `cargo run -p constance_test_runner -- -t qemu_mps2_an385_v6m`
173+
- The Armv7-A port and GR-PEACH: `cargo run -p constance_test_runner -- -t gr_peach`
166174
- The Armv7-A port and Arm RealView Platform Baseboard Explore for Cortex-A9 (QEMU emulation): `cargo run -p constance_test_runner -- -t qemu_realview_pbx_a9`
167175
- The RISC-V port and SiFive E (QEMU emulation): `cargo run -p constance_test_runner -- -t qemu_sifive_e`
168176
- The RISC-V port and RED-V (SPI flash XIP): `cargo run -p constance_test_runner -- -t red_v`
@@ -173,4 +181,5 @@ The `-b` option instructs `constance_test_runner` to run benchmark tests. Note t
173181

174182
- Hosted platform: `cargo bench -p constance_port_std`
175183
- The Armv7-M port and NUCLEO-F401RE: `cargo run -p constance_test_runner -- -t nucleo_f401re -b`
184+
- The Armv7-A port and GR-PEACH: `cargo run -p constance_test_runner -- -t gr_peach -b`
176185
- The RISC-V port and RED-V (SPI flash XIP): `cargo run -p constance_test_runner -- -t red_v -b`

examples/basic_gr_peach/.gdbinit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target remote :3333
2+
mon reset halt
3+
4+
# Enable the on-chip RAM
5+
mon mwb 0xFCFE0400 0xff
6+
mon mwb 0xFCFE0404 0xff
7+
mon mwb 0xFCFE0408 0xff
8+
9+
load

examples/basic_gr_peach/Cargo.toml

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

77
[dependencies]
8+
constance_support_rza1 = { path = "../../src/constance_support_rza1", features = ["semver-exempt"] }
89
constance_port_arm = { path = "../../src/constance_port_arm" }
910
constance = { path = "../../src/constance" }
1011

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

examples/basic_gr_peach/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
This directory contains an example Constance application for [GR-PEACH].
2+
3+
[GR-PEACH]: https://www.renesas.com/us/en/products/gadget-renesas/boards/gr-peach.html#overview
4+
5+
You need the following software to perform the steps described in this document:
6+
7+
- [OpenOCD]
8+
- `arm-none-eabi-gdb`
9+
- [rustup] or the correct version of the Rust toolchain
10+
- The Armv7-A build of the Rust standard library (can be [installed] by `rustup target add armv7a-none-eabi`)
11+
12+
[OpenOCD]: http://openocd.org
13+
[rustup]: https://rustup.rs
14+
[installed]: https://rust-lang.github.io/rustup/cross-compilation.html
15+
16+
We are going to load this application onto the target using OpenOCD and GDB. In one terminal window, start an instance of OpenOCD using the supplied configuration file:
17+
18+
```shell
19+
openocd -f opencd.cfg
20+
```
21+
22+
In another terminal window, compile and load the application by doing the following:
23+
24+
```shell
25+
cargo build --release
26+
arm-none-eabi-gdb -iex 'target remote localhost:3333' ../../target/armv7a-none-eabi/release/basic_gr_peach
27+
```
28+
29+
GDB automatically executes the commands in the `.gdbinit` file to download the image to the target's on-chip memory and direct PC to the entry point. Now, open a serial terminal application, configure the baud rate to 115200, and enter `c` in GDB. You should see the following output in the serial terminal:
30+
31+
```text
32+
UART is ready
33+
COTTAGE = Objects { task1: Task(1), task2: Task(2) }
34+
time = 5.178ms
35+
time = 1.006644s
36+
time = 2.007444s
37+
...
38+
```

examples/basic_gr_peach/openocd.cfg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
source [find interface/cmsis-dap.cfg]
2+
source [find target/swj-dp.tcl]
3+
4+
set _CHIPNAME rza1
5+
swj_newdap $_CHIPNAME cpu -expected-id 0x3ba02477
6+
7+
set _TARGETNAME $_CHIPNAME.cpu
8+
target create $_TARGETNAME cortex_a -chain-position $_TARGETNAME
9+
10+
adapter_khz 1000
11+
reset_config trst_and_srst
12+
debug_level 0
13+
gdb_target_description enable
14+
gdb_breakpoint_override hard
15+
init
16+
halt
17+
cortex_a dbginit

examples/basic_gr_peach/src/main.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
#![no_std]
88
#![no_main]
99
#![cfg(target_os = "none")]
10+
#![recursion_limit = "1000"] // probably because of large interrupt numbers
1011

1112
// -----------------------------------------------------------------------
1213

1314
use constance_port_arm as port;
15+
use constance_support_rza1 as support_rza1;
1416

1517
port::use_port!(unsafe struct System);
1618
port::use_startup!(unsafe System);
1719
port::use_gic!(unsafe impl PortInterrupts for System);
20+
support_rza1::use_os_timer!(unsafe impl PortTimer for System);
1821

1922
impl port::ThreadingOptions for System {}
2023

@@ -35,26 +38,19 @@ impl port::GicOptions for System {
3538
const GIC_CPU_BASE: usize = 0xe8202000;
3639
}
3740

38-
impl constance::kernel::PortTimer for System {
39-
// TODO
40-
const MAX_TICK_COUNT: constance::kernel::UTicks = 0xffffffff;
41-
const MAX_TIMEOUT: constance::kernel::UTicks = 0x80000000;
42-
unsafe fn tick_count() -> constance::kernel::UTicks {
43-
0
44-
}
41+
impl support_rza1::OsTimerOptions for System {
42+
const FREQUENCY: u64 = 33_333_000;
4543
}
4644

47-
impl port::Timer for System {}
48-
4945
// -----------------------------------------------------------------------
5046

5147
use constance::{
5248
kernel::{cfg::CfgBuilder, StartupHook, Task},
5349
prelude::*,
5450
};
5551

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

5955
#[derive(Debug)]
6056
struct Objects {
@@ -67,28 +63,25 @@ const COTTAGE: Objects = constance::build!(System, configure_app => Objects);
6763
const fn configure_app(b: &mut CfgBuilder<System>) -> Objects {
6864
b.num_task_priority_levels(4);
6965

70-
// Initialize RTT (Real-Time Transfer) with a single up channel and set
71-
// it as the print channel for the printing macros
66+
System::configure_os_timer(b);
67+
68+
// Initialize the serial port
7269
StartupHook::build()
7370
.start(|_| {
74-
let channels = rtt_target::rtt_init! {
75-
up: {
76-
0: {
77-
size: 1024
78-
mode: NoBlockSkip
79-
name: "Terminal"
80-
}
81-
}
82-
};
83-
84-
unsafe {
85-
rtt_target::set_print_channel_cs(
86-
channels.up.0,
87-
&((|arg, f| f(arg)) as rtt_target::CriticalSectionFunc),
88-
)
89-
};
90-
91-
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");
9285
})
9386
.finish(b);
9487

@@ -103,14 +96,14 @@ const fn configure_app(b: &mut CfgBuilder<System>) -> Objects {
10396
}
10497

10598
fn task1_body(_: usize) {
106-
rtt_target::rprintln!("COTTAGE = {:?}", COTTAGE);
99+
support_rza1::sprintln!("COTTAGE = {:?}", COTTAGE);
107100

108101
COTTAGE.task2.activate().unwrap();
109102
}
110103

111104
fn task2_body(_: usize) {
112105
loop {
113-
rtt_target::rprintln!("time = {:?}", System::time().unwrap());
106+
support_rza1::sprintln!("time = {:?}", System::time().unwrap());
114107
System::sleep(constance::time::Duration::from_secs(1)).unwrap();
115108
}
116109
}

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)