aboutsummaryrefslogtreecommitdiff
path: root/examples/rp
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-12-13 14:55:34 +0000
committerGitHub <[email protected]>2022-12-13 14:55:34 +0000
commit47747d3b73f392e53ead8ff49cd09fd017df3215 (patch)
tree9fb66fa2bb865d224ba2d98c5f1fa3bdf9e34b26 /examples/rp
parent36639e5262a79df6a3c5acf5b083d51943ca5f97 (diff)
parentc4d8f3579e4927446421730d52a409d724f2800c (diff)
Merge #1105
1105: embassy-rp: Add multicore support r=Dirbaio a=kalkyl This PR adds multicore support + critical-section impl using hardware spinlocks. Based on the rp2040-hal implementation. Co-authored-by: kalkyl <[email protected]> Co-authored-by: Henrik Alsér <[email protected]>
Diffstat (limited to 'examples/rp')
-rw-r--r--examples/rp/Cargo.toml5
-rw-r--r--examples/rp/src/bin/multicore.rs60
2 files changed, 63 insertions, 2 deletions
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml
index b07c471af..dfbc26426 100644
--- a/examples/rp/Cargo.toml
+++ b/examples/rp/Cargo.toml
@@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
9embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } 9embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
11embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 11embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
12embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "pio"] } 12embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "pio", "critical-section-impl"] }
13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
14embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } 14embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] }
15embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 15embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
@@ -18,7 +18,8 @@ embassy-usb-logger = { version = "0.1.0", path = "../../embassy-usb-logger" }
18defmt = "0.3" 18defmt = "0.3"
19defmt-rtt = "0.4" 19defmt-rtt = "0.4"
20 20
21cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } 21#cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
22cortex-m = { version = "0.7.6" }
22cortex-m-rt = "0.7.0" 23cortex-m-rt = "0.7.0"
23panic-probe = { version = "0.3", features = ["print-defmt"] } 24panic-probe = { version = "0.3", features = ["print-defmt"] }
24futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } 25futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] }
diff --git a/examples/rp/src/bin/multicore.rs b/examples/rp/src/bin/multicore.rs
new file mode 100644
index 000000000..376b2b61e
--- /dev/null
+++ b/examples/rp/src/bin/multicore.rs
@@ -0,0 +1,60 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Executor;
7use embassy_executor::_export::StaticCell;
8use embassy_rp::gpio::{Level, Output};
9use embassy_rp::multicore::{spawn_core1, Stack};
10use embassy_rp::peripherals::PIN_25;
11use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
12use embassy_sync::channel::Channel;
13use embassy_time::{Duration, Timer};
14use {defmt_rtt as _, panic_probe as _};
15
16static mut CORE1_STACK: Stack<4096> = Stack::new();
17static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
18static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
19static CHANNEL: Channel<CriticalSectionRawMutex, LedState, 1> = Channel::new();
20
21enum LedState {
22 On,
23 Off,
24}
25
26#[cortex_m_rt::entry]
27fn main() -> ! {
28 let p = embassy_rp::init(Default::default());
29 let led = Output::new(p.PIN_25, Level::Low);
30
31 spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || {
32 let executor1 = EXECUTOR1.init(Executor::new());
33 executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(led))));
34 });
35
36 let executor0 = EXECUTOR0.init(Executor::new());
37 executor0.run(|spawner| unwrap!(spawner.spawn(core0_task())));
38}
39
40#[embassy_executor::task]
41async fn core0_task() {
42 info!("Hello from core 0");
43 loop {
44 CHANNEL.send(LedState::On).await;
45 Timer::after(Duration::from_millis(100)).await;
46 CHANNEL.send(LedState::Off).await;
47 Timer::after(Duration::from_millis(400)).await;
48 }
49}
50
51#[embassy_executor::task]
52async fn core1_task(mut led: Output<'static, PIN_25>) {
53 info!("Hello from core 1");
54 loop {
55 match CHANNEL.recv().await {
56 LedState::On => led.set_high(),
57 LedState::Off => led.set_low(),
58 }
59 }
60}