Skip to content

Commit

Permalink
Scripts: Added SAMV71 example runner and migrated all examples to RTT
Browse files Browse the repository at this point in the history
  • Loading branch information
SteelPh0enix committed Aug 22, 2023
1 parent 812ecbb commit c4ae88f
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 29 deletions.
11 changes: 8 additions & 3 deletions examples/samv71-basic-execution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ version = "0.1.0"
aerugo = { version = "0.1.0", path = "../..", features = [
"use-aerugo-cortex-m",
] }
cortex-m = "0.7.7"
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.3"
cortex-m-semihosting = "0.5.0"
panic-semihosting = "0.6.0"
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
rtt-target = "0.4.0"

[profile.release]
codegen-units = 1
lto = true
debug = true
22 changes: 15 additions & 7 deletions examples/samv71-basic-execution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

extern crate cortex_m;
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;
extern crate panic_rtt_target;
extern crate rtt_target as rtt;

use aerugo::{
time::MillisDurationU32, InitApi, RuntimeApi, SystemHardwareConfig, TaskletConfig,
TaskletStorage, AERUGO,
};
use cortex_m_semihosting::hprintln;
use rt::entry;
use rtt::rprintln;

#[derive(Default)]
struct DummyTaskContext {
Expand All @@ -20,21 +21,23 @@ struct DummyTaskContext {
fn dummy_task(_: (), context: &mut DummyTaskContext, _: &dyn RuntimeApi) {
context.acc = context.acc.wrapping_add(1);
if context.acc % 250 == 0 {
hprintln!("I'm running!");
rprintln!("I'm running!");
}
}

static DUMMY_TASK_STORAGE: TaskletStorage<(), DummyTaskContext, 0> = TaskletStorage::new();

#[entry]
fn main() -> ! {
hprintln!("Hello, world! Initializing Aerugo...");
init_rtt();

rprintln!("Hello, world! Initializing Aerugo...");

AERUGO.initialize(SystemHardwareConfig {
watchdog_timeout: MillisDurationU32::secs(5),
});

hprintln!("Creating tasks...");
rprintln!("Creating tasks...");
let dummy_task_config = TaskletConfig {
name: "DummyTask",
..Default::default()
Expand All @@ -54,13 +57,18 @@ fn main() -> ! {
.create_handle()
.expect("Unable to create handle to dummy task!");

hprintln!("Subscribing tasks...");
rprintln!("Subscribing tasks...");

AERUGO
.subscribe_tasklet_to_cyclic(&dummy_task_handle, None)
.expect("Unable to subscribe dummy task to cyclic execution!");

hprintln!("Starting the system!");
rprintln!("Starting the system!");

AERUGO.start();
}

#[inline(never)]
fn init_rtt() {
rtt::rtt_init_print!();
}
3 changes: 2 additions & 1 deletion examples/samv71-fizz-buzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
rtt-target = "0.4.0"

[profile.release]
debug = true
codegen-units = 1
lto = true
debug = true
7 changes: 6 additions & 1 deletion examples/samv71-fizz-buzz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl From<EventId> for FizzBuzzEvents {

#[entry]
fn main() -> ! {
rtt::rtt_init_print!();
init_rtt();

rprintln!("Hello, world! Initializing Aerugo...");

Expand Down Expand Up @@ -255,3 +255,8 @@ fn main() -> ! {

AERUGO.start();
}

#[inline(never)]
fn init_rtt() {
rtt::rtt_init_print!();
}
11 changes: 8 additions & 3 deletions examples/samv71-hal-timer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ aerugo = { version = "0.1.0", path = "../..", features = [
"use-aerugo-cortex-m",
"rt",
] }
cortex-m = { version = "0.7.7" }
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
cortex-m-rt = { version = "0.7.3", features = ["device"] }
cortex-m-semihosting = "0.5.0"
panic-semihosting = "0.6.0"
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
rtt-target = "0.4.0"

[features]
rt = ["aerugo/rt"]

[profile.release]
codegen-units = 1
lto = true
debug = true
28 changes: 18 additions & 10 deletions examples/samv71-hal-timer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

extern crate cortex_m;
extern crate cortex_m_rt as rt;
extern crate panic_rtt_target;
extern crate rtt_target as rtt;

use core::cell::RefCell;

Expand All @@ -12,14 +14,13 @@ use aerugo::hal::drivers::timer::{
use aerugo::hal::PMC;
use cortex_m::interrupt::free as irq_free;
use cortex_m::interrupt::Mutex;
use panic_semihosting as _;

use aerugo::{
hal::drivers::timer::Timer, time::MillisDurationU32, InitApi, RuntimeApi, SystemHardwareConfig,
TaskletConfig, TaskletStorage, AERUGO,
};
use cortex_m_semihosting::hprintln;
use rt::entry;
use rtt::rprintln;

static TIMER_CHANNEL: Mutex<RefCell<Option<Channel<TC1, Ch0, Waveform>>>> =
Mutex::new(RefCell::new(None));
Expand All @@ -32,7 +33,7 @@ struct DummyTaskContext {
fn dummy_task(_: (), context: &mut DummyTaskContext, _: &'static dyn RuntimeApi) {
context.acc = context.acc.wrapping_add(1);
if context.acc % 1000 == 0 {
hprintln!("I'm running!");
rprintln!("I'm running!");

irq_free(|cs| {
// This is safe, because TIMER_CHANNEL is set before the scheduler starts.
Expand All @@ -42,7 +43,7 @@ fn dummy_task(_: (), context: &mut DummyTaskContext, _: &'static dyn RuntimeApi)
.as_ref()
.unwrap()
.counter_value();
hprintln!("TC1 CH0: {}", timer_value);
rprintln!("TC1 CH0: {}", timer_value);
})
}
}
Expand All @@ -65,15 +66,15 @@ fn init_timer(timer: &mut Timer<TC1>) {
ch0.trigger();

let status = ch0.read_and_clear_status().clock_enabled;
hprintln!("Clock is {}", if status { "enabled" } else { "disabled" });
rprintln!("Clock is {}", if status { "enabled" } else { "disabled" });

irq_free(|cs| {
TIMER_CHANNEL.borrow(cs).replace(Some(ch0));
});
}

fn init_tasks() {
hprintln!("Creating tasks...");
rprintln!("Creating tasks...");
let dummy_task_config = TaskletConfig {
name: "DummyTask",
..Default::default()
Expand All @@ -93,7 +94,7 @@ fn init_tasks() {
.create_handle()
.expect("Unable to create handle to dummy task!");

hprintln!("Subscribing tasks...");
rprintln!("Subscribing tasks...");

AERUGO
.subscribe_tasklet_to_cyclic(&dummy_task_handle, None)
Expand All @@ -102,13 +103,15 @@ fn init_tasks() {

#[entry]
fn main() -> ! {
hprintln!("Hello, world! Initializing Aerugo...");
init_rtt();

rprintln!("Hello, world! Initializing Aerugo...");

AERUGO.initialize(SystemHardwareConfig {
watchdog_timeout: MillisDurationU32::secs(5),
});

hprintln!("Doing stuff with timers...");
rprintln!("Doing stuff with timers...");
let peripherals = AERUGO
.peripherals()
.expect("peripherals are not initialized")
Expand All @@ -122,6 +125,11 @@ fn main() -> ! {

init_tasks();

hprintln!("Starting the system!");
rprintln!("Starting the system!");
AERUGO.start();
}

#[inline(never)]
fn init_rtt() {
rtt::rtt_init_print!();
}
3 changes: 2 additions & 1 deletion examples/samv71-system-time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
rtt-target = "0.4.0"

[profile.release]
debug = true
codegen-units = 1
lto = true
debug = true
13 changes: 10 additions & 3 deletions examples/samv71-system-time/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ struct DummyTaskContext {
fn dummy_task(_: (), context: &mut DummyTaskContext, api: &'static dyn RuntimeApi) {
context.acc = context.acc.wrapping_add(1);
if context.acc % 300 == 0 {
let time = api.get_system_time().duration_since_epoch().to_secs();
rprintln!("Current time is {}s", time);
let time = api.get_system_time().duration_since_epoch();
let time_seconds = time.to_secs();
let time_millis = time.to_millis() % 1000;
rprintln!("Current time is {}s {}ms", time_seconds, time_millis);
}
}

static DUMMY_TASK_STORAGE: TaskletStorage<(), DummyTaskContext, 0> = TaskletStorage::new();

#[entry]
fn main() -> ! {
rtt::rtt_init_print!();
init_rtt();

rprintln!("Hello, world! Initializing Aerugo...");

Expand Down Expand Up @@ -68,3 +70,8 @@ fn main() -> ! {

AERUGO.start();
}

#[inline(never)]
fn init_rtt() {
rtt::rtt_init_print!();
}
Loading

0 comments on commit c4ae88f

Please sign in to comment.