Skip to content

Commit

Permalink
start adding embassy example
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Sep 12, 2024
1 parent cad9683 commit b9d5243
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 8 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[workspace]
resolver = "2"
members = [
"va416xx",
"va416xx-hal",
"vorago-peb1",
"bootloader",
"flashloader",
"examples/simple",
"va416xx",
"va416xx-hal",
"vorago-peb1"
"examples/embassy",
"examples/rtic",
]
exclude = [
"flashloader/slot-a-blinky",
Expand Down
22 changes: 22 additions & 0 deletions examples/embassy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "embassy"
version = "0.1.0"
edition = "2021"

[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
embedded-hal = "1"
rtt-target = { version = "0.5" }
panic-rtt-target = { version = "0.1" }

embassy-sync = { version = "0.6.0" }
embassy-time = { version = "0.3.2", features = ["tick-hz-32_768"] }

[dependencies.embassy-executor]
version = "0.6.0"
features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"]

[dependencies.va416xx-hal]
path = "../../va416xx-hal"
features = ["va41630"]
23 changes: 23 additions & 0 deletions examples/embassy/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![no_std]
#![no_main]
use embassy_executor::Spawner;
use embassy_time::Timer;
use embedded_hal::digital::StatefulOutputPin;
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use va416xx_hal::{gpio::PinsG, pac};

// main is itself an async function.
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
rtt_init_print!();
rprintln!("VA416xx RTT Demo");

let mut dp = pac::Peripherals::take().unwrap();
let portg = PinsG::new(&mut dp.sysconfig, dp.portg);
let mut led = portg.pg5.into_readable_push_pull_output();
loop {
Timer::after_millis(200).await;
led.toggle().ok();
}
}
24 changes: 24 additions & 0 deletions examples/rtic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "rtic"
version = "0.1.0"
edition = "2021"

[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
embedded-hal = "1"
rtt-target = { version = "0.5" }
rtic-sync = { version = "1.3", features = ["defmt-03"] }
panic-rtt-target = { version = "0.1.3" }

[dependencies.va416xx-hal]
path = "../../va416xx-hal"
features = ["va41630"]

[dependencies.rtic]
version = "2"
features = ["thumbv7-backend"]

[dependencies.rtic-monotonics]
version = "2"
features = ["cortex-m-systick"]
File renamed without changes.
57 changes: 57 additions & 0 deletions examples/rtic/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! RTIC minimal blinky
#![no_main]
#![no_std]

#[rtic::app(device = pac, dispatchers = [U1, U2, U3])]
mod app {
use cortex_m::asm;
use embedded_hal::digital::StatefulOutputPin;
use panic_rtt_target as _;
use rtic_monotonics::systick::prelude::*;
use rtic_monotonics::Monotonic;
use rtt_target::{rprintln, rtt_init_default};
use va416xx_hal::{
gpio::{OutputReadablePushPull, Pin, PinsG, PG5},
pac,
};

#[local]
struct Local {
led: Pin<PG5, OutputReadablePushPull>,
}

#[shared]
struct Shared {}

rtic_monotonics::systick_monotonic!(Mono, 10_000);

#[init]
fn init(_ctx: init::Context) -> (Shared, Local) {
rtt_init_default!();
rprintln!("-- Vorago RTIC template --");
let mut dp = pac::Peripherals::take().unwrap();
let portg = PinsG::new(&mut dp.sysconfig, dp.portg);
let led = portg.pg5.into_readable_push_pull_output();
blinky::spawn().ok();
(Shared {}, Local { led })
}

// `shared` cannot be accessed from this context
#[idle]
fn idle(_cx: idle::Context) -> ! {
loop {
asm::nop();
}
}

#[task(
priority = 3,
local=[led],
)]
async fn blinky(cx: blinky::Context) {
loop {
cx.local.led.toggle().ok();
Mono::delay(200.millis()).await;
}
}
}
3 changes: 1 addition & 2 deletions examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ version = "0.1.0"
edition = "2021"

[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
panic-rtt-target = { version = "0.1.3" }
rtt-target = { version = "0.5" }
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
rtic-sync = { version = "1.3", features = ["defmt-03"] }
embedded-hal = "1"
embedded-hal-nb = "1"
nb = "1"
Expand Down
2 changes: 0 additions & 2 deletions flashloader/image-loader.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python3
from spacepackets.ecss import RequestId
from spacepackets.ecss.defs import PusService
from spacepackets.ecss.tm import PusTm
import toml
import struct
import logging
import argparse
import threading
import time
import enum
from tmtccmd.com.serial_base import SerialCfg
Expand Down
2 changes: 1 addition & 1 deletion flashloader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ mod app {
.unwrap();
Mono::delay(2.millis()).await;
}
Mono::delay(30.millis()).await;
Mono::delay(50.millis()).await;
}
}

Expand Down

0 comments on commit b9d5243

Please sign in to comment.