aboutsummaryrefslogtreecommitdiff
path: root/examples/rp235x/src/bin/multicore.rs
diff options
context:
space:
mode:
authorCurly <[email protected]>2025-02-23 07:33:58 -0800
committerCurly <[email protected]>2025-02-23 07:33:58 -0800
commit3932835998802fc3abf7cce4f736e072858ebfd1 (patch)
tree5dd714b99bc74a03556c58809237c88691c293bb /examples/rp235x/src/bin/multicore.rs
parentc3c67db93e627a4fafe5e1a1123e5cbb4abafe47 (diff)
rename `rp23` (?) folder to `rp235x`; fix `ci.sh` to use `rp235x` folder
Diffstat (limited to 'examples/rp235x/src/bin/multicore.rs')
-rw-r--r--examples/rp235x/src/bin/multicore.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/examples/rp235x/src/bin/multicore.rs b/examples/rp235x/src/bin/multicore.rs
new file mode 100644
index 000000000..7cb546c91
--- /dev/null
+++ b/examples/rp235x/src/bin/multicore.rs
@@ -0,0 +1,66 @@
1//! This example shows how to send messages between the two cores in the RP2040 chip.
2//!
3//! The LED on the RP Pico W board is connected differently. See wifi_blinky.rs.
4
5#![no_std]
6#![no_main]
7
8use defmt::*;
9use embassy_executor::Executor;
10use embassy_rp::gpio::{Level, Output};
11use embassy_rp::multicore::{spawn_core1, Stack};
12use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
13use embassy_sync::channel::Channel;
14use embassy_time::Timer;
15use static_cell::StaticCell;
16use {defmt_rtt as _, panic_probe as _};
17
18static mut CORE1_STACK: Stack<4096> = Stack::new();
19static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
20static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
21static CHANNEL: Channel<CriticalSectionRawMutex, LedState, 1> = Channel::new();
22
23enum LedState {
24 On,
25 Off,
26}
27
28#[cortex_m_rt::entry]
29fn main() -> ! {
30 let p = embassy_rp::init(Default::default());
31 let led = Output::new(p.PIN_25, Level::Low);
32
33 spawn_core1(
34 p.CORE1,
35 unsafe { &mut *core::ptr::addr_of_mut!(CORE1_STACK) },
36 move || {
37 let executor1 = EXECUTOR1.init(Executor::new());
38 executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(led))));
39 },
40 );
41
42 let executor0 = EXECUTOR0.init(Executor::new());
43 executor0.run(|spawner| unwrap!(spawner.spawn(core0_task())));
44}
45
46#[embassy_executor::task]
47async fn core0_task() {
48 info!("Hello from core 0");
49 loop {
50 CHANNEL.send(LedState::On).await;
51 Timer::after_millis(100).await;
52 CHANNEL.send(LedState::Off).await;
53 Timer::after_millis(400).await;
54 }
55}
56
57#[embassy_executor::task]
58async fn core1_task(mut led: Output<'static>) {
59 info!("Hello from core 1");
60 loop {
61 match CHANNEL.receive().await {
62 LedState::On => led.set_high(),
63 LedState::Off => led.set_low(),
64 }
65 }
66}