Port ESP32-C3 changes to ESP32-C6 branch

This commit is contained in:
Eli Hastings 2025-02-24 16:30:43 +00:00 committed by Henrik Tjäder
parent 0efb77300e
commit ef09e4b65f
13 changed files with 916 additions and 454 deletions

File diff suppressed because it is too large Load diff

View file

@ -7,18 +7,19 @@ license = "MIT OR Apache-2.0"
[workspace]
[dependencies]
rtic = {path = "../../rtic/"}
esp-hal = { version = "0.16.1", features = ["esp32c6", "direct-vectoring", "interrupt-preemption"] }
esp-backtrace = { version = "0.11.0", features = [
rtic = { path = "../../rtic/" }
rtic-monotonics = {path = "../../rtic-monotonics/"}
esp-hal = { version = "0.23.1", features = ["esp32c6"] }
esp-backtrace = { version = "0.15.1", features = [
"esp32c6",
"panic-handler",
"exception-handler",
"println",
] }
esp32c6 = {version = "0.12.0", features = ["critical-section"]}
esp-println = { version = "0.9.0", default-features=false, features = ["esp32c6", "uart"] }
esp32c6 = {version = "0.18.0", features = ["critical-section"]}
esp-println = { version = "0.13.1", features = ["esp32c6", "auto"] }
[features]
test-critical-section = []
riscv-esp32c6-backend = ["rtic/riscv-esp32c6-backend"]
riscv-esp32c6-backend = ["rtic/riscv-esp32c6-backend", "rtic-monotonics/esp32c6-systimer"]

View file

@ -1,4 +1,4 @@
### ESP32-C3 RTIC template
### ESP32-C6 RTIC template
This crate showcases a simple RTIC application for the ESP32-C6.
## Prerequisites
@ -20,7 +20,7 @@ This crate uses the most convenient option in ``cargo-espflash`` and ``espflash`
should do the trick.
# Expected behavior
The program
The example ``sw_and_hw``
- Prints ``init``
- Enters a high prio task
- During the execution of the high prio task, the button should be non-functional
@ -31,3 +31,9 @@ The program
- Exits the low prio task
- Prints ``idle``
The example ``monotonic``
- Prints ``init``
- Spawns the ``foo``, ``bar``, ``baz`` tasks (because of hardware interrupt latency dispatch, the order here may vary).
- Each task prints ``hello from $TASK`` on entry
- The tasks wait for 1, 2, 3 seconds respectively
- Once the wait period is over, each task exits printing ``bye from $TASK`` (now in the proper order).

View file

@ -0,0 +1,51 @@
#![no_main]
#![no_std]
use esp_backtrace as _;
#[rtic::app(device = esp32c6, dispatchers = [])]
mod app {
use rtic_monotonics::esp32c6::prelude::*;
esp32c6_systimer_monotonic!(Mono);
use esp_hal as _;
use esp_println::println;
#[shared]
struct Shared {}
#[local]
struct Local {}
#[init]
fn init(cx: init::Context) -> (Shared, Local) {
println!("init");
let timer = cx.device.SYSTIMER;
Mono::start(timer);
foo::spawn().unwrap();
bar::spawn().unwrap();
baz::spawn().unwrap();
(Shared {}, Local {})
}
#[task]
async fn foo(_cx: foo::Context) {
println!("hello from foo");
Mono::delay(2_u64.secs()).await;
println!("bye from foo");
}
#[task]
async fn bar(_cx: bar::Context) {
println!("hello from bar");
Mono::delay(3_u64.secs()).await;
println!("bye from bar");
}
#[task]
async fn baz(_cx: baz::Context) {
println!("hello from baz");
Mono::delay(4_u64.secs()).await;
println!("bye from baz");
}
}

View file

@ -4,27 +4,23 @@
#[rtic::app(device = esp32c6, dispatchers=[FROM_CPU_INTR0, FROM_CPU_INTR1])]
mod app {
use esp_backtrace as _;
use esp_hal::{
gpio::{Event, Gpio9, Input, PullUp, IO},
peripherals::Peripherals,
prelude::*,
};
use esp_hal::gpio::{Event, Input, Pull};
use esp_println::println;
#[shared]
struct Shared {}
#[local]
struct Local {
button: Gpio9<Input<PullUp>>,
button: Input<'static>,
}
// do nothing in init
#[init]
fn init(_: init::Context) -> (Shared, Local) {
println!("init");
let peripherals = Peripherals::take();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let mut button = io.pins.gpio9.into_pull_up_input();
let peripherals = esp_hal::init(esp_hal::Config::default());
let mut button = Input::new(peripherals.GPIO9, Pull::Up);
button.listen(Event::FallingEdge);
foo::spawn().unwrap();
(Shared {}, Local { button })
@ -41,17 +37,18 @@ mod app {
bar::spawn().unwrap(); //enqueue low prio task
println!("Inside high prio task, press button now!");
let mut x = 0;
while x < 5000000 {
while x < 50000000 {
x += 1; //burn cycles
esp_hal::riscv::asm::nop();
}
println!("Leaving high prio task.");
}
#[task(priority = 2)]
async fn bar(_: bar::Context) {
println!("Inside low prio task, press button now!");
let mut x = 0;
while x < 5000000 {
while x < 50000000 {
x += 1; //burn cycles
esp_hal::riscv::asm::nop();
}

View file

@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2023-11-14"
components = ["rust-src"]
targets = ["riscv32imc-unknown-none-elf"]
targets = ["riscv32imac-unknown-none-elf"]