Embassy
embassy-rp

Crates

git

Versions

rp2040

Flavors

Module embassy_rp::multicore

source ·
Expand description

Multicore support

This module handles setup of the 2nd cpu core on the rp2040, which we refer to as core1. It provides functionality for setting up the stack, and starting core1.

The entrypoint for core1 can be any function that never returns, including closures.

Enable the critical-section-impl feature in embassy-rp when sharing data across cores using the embassy-sync primitives and CriticalSectionRawMutex.

Usage

use embassy_rp::multicore::Stack;
use static_cell::StaticCell;
use embassy_executor::Executor;

static mut CORE1_STACK: Stack<4096> = Stack::new();
static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
static EXECUTOR1: StaticCell<Executor> = StaticCell::new();


#[embassy_executor::task]
async fn core0_task() {
    // ...
}

#[embassy_executor::task]
async fn core1_task() {
    // ...
}

#[cortex_m_rt::entry]
fn main() -> ! {
    let p = embassy_rp::init(Default::default());

    embassy_rp::multicore::spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || {
        let executor1 = EXECUTOR1.init(Executor::new());
        executor1.run(|spawner| spawner.spawn(core1_task()).unwrap());
    });

    let executor0 = EXECUTOR0.init(Executor::new());
    executor0.run(|spawner| spawner.spawn(core0_task()).unwrap())
}

Structs

  • Data type for a properly aligned stack of N bytes

Functions