esp_hal

Module cpu_control

Source
Expand description

§Control CPU Cores (ESP32)

§Overview

This module provides essential functionality for controlling and managing the APP (second) CPU core on the ESP32 chip. It is used to start and stop program execution on the APP core.

§Examples

static mut APP_CORE_STACK: Stack<8192> = Stack::new();


let counter = Mutex::new(RefCell::new(0));

let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);
let cpu1_fnctn = || {
    cpu1_task(&delay, &counter);
};
let _guard = cpu_control
    .start_app_core(
        unsafe { &mut *addr_of_mut!(APP_CORE_STACK) },
        cpu1_fnctn
    ).unwrap();

loop {
    delay.delay(1.secs());
    let count = critical_section::with(|cs| *counter.borrow_ref(cs));
}

// Where `cpu1_task()` may be defined as:
fn cpu1_task(
    delay: &Delay,
    counter: &critical_section::Mutex<RefCell<i32>>,
) -> ! {
    loop {
        delay.delay(500.millis());

        critical_section::with(|cs| {
            let mut val = counter.borrow_ref_mut(cs);
            *val = val.wrapping_add(1);
        });
    }
}

Structs§

  • Will park the APP (second) core when dropped
  • Control CPU Cores
  • Data type for a properly aligned stack of N bytes

Enums§

  • Represents errors that can occur while working with the core.