Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(xtensa): add support for esp32s3 with xtensa arch #399

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 39 additions & 10 deletions laze-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ contexts:
- ?defmt
env:
RUSTFLAGS:
- "-Clink-arg=--nmagic"
- "-Clink-arg=${LINK_ARG_PREFIX}--no-eh-frame-hdr"
- --cfg builder=\"${builder}\"
- --cfg context=\"${builder}\"
- --cfg context=\"riot-rs\"
Expand Down Expand Up @@ -63,7 +61,7 @@ contexts:
pool: console
always: true
cmd: >-
cd ${relpath} && ${CARGO_ENV} cargo ${CARGO_ARGS} build --${PROFILE} ${FEATURES}
cd ${relpath} && ${CARGO_ENV} cargo ${CARGO_TOOLCHAIN} ${CARGO_ARGS} build --${PROFILE} ${FEATURES}
&& cp ${relroot}/${build-dir}/bin/${builder}/${app}/cargo/${RUSTC_TARGET}/${PROFILE}/${riot_binary} ${relroot}/${out}

- name: GIT_DOWNLOAD
Expand All @@ -77,13 +75,13 @@ contexts:

cargo:
cmd:
- cd ${relpath} && ${CARGO_ENV} cargo ${CARGO_ARGS}
- cd ${relpath} && ${CARGO_ENV} cargo ${CARGO_TOOLCHAIN} ${CARGO_ARGS}
build: false

run:
build: false
cmd:
- cd ${appdir} && ${CARGO_ENV} cargo ${CARGO_ARGS} run --${PROFILE} ${FEATURES}
- cd ${appdir} && ${CARGO_ENV} cargo ${CARGO_TOOLCHAIN} ${CARGO_ARGS} run --${PROFILE} ${FEATURES}

cargo-test:
cmd:
Expand All @@ -92,7 +90,7 @@ contexts:

debug:
cmd:
- cd ${appdir} && ${CARGO_ENV} cargo ${CARGO_ARGS} run --${PROFILE} ${FEATURES}
- cd ${appdir} && ${CARGO_ENV} cargo ${CARGO_TOOLCHAIN} ${CARGO_ARGS} run --${PROFILE} ${FEATURES}
build: false
ignore_ctrl_c: true

Expand All @@ -104,12 +102,12 @@ contexts:

bloat:
cmd:
- cd ${appdir} && ${CARGO_ENV} cargo ${CARGO_ARGS} bloat --${PROFILE} ${FEATURES}
- cd ${appdir} && ${CARGO_ENV} cargo ${CARGO_TOOLCHAIN} ${CARGO_ARGS} bloat --${PROFILE} ${FEATURES}
build: false

tree:
cmd:
- cd ${appdir} && ${CARGO_ENV} cargo ${CARGO_ARGS} tree ${FEATURES}
- cd ${appdir} && ${CARGO_ENV} cargo ${CARGO_TOOLCHAIN} ${CARGO_ARGS} tree ${FEATURES}
build: false

flash:
Expand Down Expand Up @@ -278,8 +276,6 @@ contexts:
- --cfg context=\"esp\"
# linkall first
- -Clink-arg=-Tlinkall.x
- -Clink-arg=-Tlinkme-esp-fixup.x
- -Clink-arg=-Tlinkme.x
# this might be needed for backtraces
# - -C force-frame-pointers
CARGO_ARGS:
Expand All @@ -288,6 +284,8 @@ contexts:

- name: esp32c3
parent: esp
selects:
- riscv
env:
RUSTFLAGS:
- --cfg context=\"esp32c3\"
Expand All @@ -296,12 +294,25 @@ contexts:

- name: esp32c6
parent: esp
selects:
- riscv
env:
RUSTFLAGS:
- --cfg context=\"esp32c6\"
RUSTC_TARGET: riscv32imac-unknown-none-elf
CARGO_TARGET_PREFIX: CARGO_TARGET_RISCV32IMAC_UNKNOWN_NONE_ELF

- name: esp32s3
parent: esp
selects:
- xtensa
env:
CARGO_TOOLCHAIN: +esp
RUSTFLAGS:
- --cfg context=\"esp32s3\"
RUSTC_TARGET: xtensa-esp32s3-none-elf
CARGO_TARGET_PREFIX: CARGO_TARGET_XTENSA_ESP32S3_NONE_ELF

- name: stm32
help: STM32 support (based on embassy-stm32)
parent: riot-rs
Expand Down Expand Up @@ -358,6 +369,8 @@ modules:
global:
OBJCOPY: arm-none-eabi-objcopy
RUSTFLAGS:
- -Clink-arg=--nmagic
- -Clink-arg=${LINK_ARG_PREFIX}--no-eh-frame-hdr
- -Clink-arg=-Tlinkme.x
- -Clink-arg=-Tlink.x
- -Clink-arg=-Tdevice.x
Expand Down Expand Up @@ -414,6 +427,18 @@ modules:
RUSTFLAGS:
- --cfg armv7m

- name: xtensa
env:
global:
RUSTFLAGS:
- --cfg context=\"xtensa\"

- name: riscv
env:
global:
RUSTFLAGS:
- --cfg context=\"riscv\"

- name: rp-link-arg
help: helper module that ensures link-rp.x is added behind cortex-m ld scripts
env:
Expand Down Expand Up @@ -630,6 +655,7 @@ modules:
- nrf
- rp
- stm32
- esp

- name: wifi-esp
context:
Expand Down Expand Up @@ -776,6 +802,9 @@ builders:
- name: espressif-esp32-c6-devkitc-1
parent: esp32c6

- name: espressif-esp32-s3-wroom-1
parent: esp32s3

- name: nrf5340dk
parent: nrf5340

Expand Down
3 changes: 3 additions & 0 deletions src/riot-rs-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ defmt = { workspace = true, optional = true }

[target.'cfg(context = "cortex-m")'.dependencies]
cortex-m = { workspace = true, features = ["critical-section-single-core"] }

[target.'cfg(context = "esp")'.dependencies]
esp-hal = { workspace = true }
28 changes: 28 additions & 0 deletions src/riot-rs-bench/src/esp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use esp_hal::{
peripherals,
timer::systimer::{SystemTimer, Unit as _},
};

use crate::Error;

#[allow(missing_docs)]
pub fn benchmark<F: Fn() -> ()>(iterations: usize, f: F) -> Result<usize, Error> {
let mut systimer_periph = unsafe { peripherals::SYSTIMER::steal() };
let timer = SystemTimer::new(&mut systimer_periph);

// Reset counter of unit0, which is read in `SystemTimer::now()`.
timer.unit0.set_count(0);

while SystemTimer::now() == 0 {}

let before = SystemTimer::now();

for _ in 0..iterations {
f();
}

SystemTimer::now()
.checked_sub(before)
.map(|total| total as usize / iterations)
.ok_or(Error::SystemTimerWrapped)
}
6 changes: 4 additions & 2 deletions src/riot-rs-bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ cfg_if::cfg_if! {
if #[cfg(context = "cortex-m")] {
mod cortexm;
use cortexm as bench;
}
else if #[cfg(context = "riot-rs")] {
} else if #[cfg(context = "esp")] {
mod esp;
use esp as bench;
} else if #[cfg(context = "riot-rs")] {
// When run with laze but the architecture is not supported
compile_error!("benchmarking is not supported for this architecture");
} else {
Expand Down
1 change: 1 addition & 0 deletions src/riot-rs-boards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ riot-rs-rt = { path = "../riot-rs-rt" }

ai-c3 = { optional = true, path = "ai-c3" }
espressif-esp32-c6-devkitc-1 = { optional = true, path = "espressif-esp32-c6-devkitc-1" }
espressif-esp32-s3-wroom-1 = { optional = true, path = "espressif-esp32-s3-wroom-1" }
dwm1001 = { optional = true, path = "dwm1001" }
microbit = { optional = true, path = "microbit" }
microbit-v2 = { optional = true, path = "microbit-v2" }
Expand Down
10 changes: 10 additions & 0 deletions src/riot-rs-boards/espressif-esp32-s3-wroom-1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "espressif-esp32-s3-wroom-1"
version = "0.1.0"
authors = ["Elena Frank <[email protected]>"]
license.workspace = true
edition = "2021"

[dependencies]
riot-rs-rt = { workspace = true, features = ["_esp32s3"] }
riot-rs-debug.workspace = true
7 changes: 7 additions & 0 deletions src/riot-rs-boards/espressif-esp32-s3-wroom-1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![no_std]

use riot_rs_debug::log::debug;

pub fn init() {
debug!("espressif-esp32-s3-wroom-1::init()");
}
2 changes: 2 additions & 0 deletions src/riot-rs-boards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ cfg_if! {
pub use ai_c3 as board;
} else if #[cfg(feature = "espressif-esp32-c6-devkitc-1")] {
pub use espressif_esp32_c6_devkitc_1 as board;
} else if #[cfg(feature = "espressif-esp32-s3-wroom-1")] {
pub use espressif_esp32_s3_wroom_1 as board;
} else if #[cfg(feature = "nrf52dk")] {
pub use nrf52dk as board;
} else if #[cfg(feature = "dwm1001")] {
Expand Down
3 changes: 3 additions & 0 deletions src/riot-rs-debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ esp-println = { workspace = true, features = ["esp32c3"] }
[target.'cfg(context = "esp32c6")'.dependencies]
esp-println = { workspace = true, features = ["esp32c6"] }

[target.'cfg(context = "esp32s3")'.dependencies]
esp-println = { workspace = true, features = ["esp32s3"] }

[features]
debug-console = []
defmt = ["dep:defmt", "esp-println?/defmt-espflash"]
9 changes: 9 additions & 0 deletions src/riot-rs-esp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ esp-wifi = { workspace = true, default-features = false, features = [
"esp32c6",
], optional = true }

[target.'cfg(context = "esp32s3")'.dependencies]
esp-hal = { workspace = true, features = ["esp32s3"] }
esp-hal-embassy = { workspace = true, default-features = false, features = [
"esp32s3",
] }
esp-wifi = { workspace = true, default-features = false, features = [
"esp32s3",
], optional = true }

[features]
## Enables GPIO interrupt support.
external-interrupts = ["riot-rs-embassy-common/external-interrupts"]
Expand Down
3 changes: 2 additions & 1 deletion src/riot-rs-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ silent-panic = []
_panic-handler = []

# internal
# These two features are used by `build.rs`, which doesn't "see" context
# These features are used by `build.rs`, which doesn't "see" context
# variables.
_esp32c3 = []
_esp32c6 = []
_esp32s3 = []

[dev-dependencies]
riot-rs-boards = { path = "../riot-rs-boards" }
8 changes: 0 additions & 8 deletions src/riot-rs-rt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,5 @@ fn main() {
std::fs::copy("isr_stack.ld.in", out.join("isr_stack.x")).unwrap();
std::fs::copy("linkme.x", out.join("linkme.x")).unwrap();

if env::var_os("CARGO_FEATURE__ESP32C3").is_some() {
std::fs::copy("linkme-esp32c3-fixup.x", out.join("linkme-esp-fixup.x")).unwrap();
}

if env::var_os("CARGO_FEATURE__ESP32C6").is_some() {
std::fs::copy("linkme-esp32c6-fixup.x", out.join("linkme-esp-fixup.x")).unwrap();
}

println!("cargo:rustc-link-search={}", out.display());
}
1 change: 0 additions & 1 deletion src/riot-rs-rt/linkme-esp32c3-fixup.x

This file was deleted.

1 change: 0 additions & 1 deletion src/riot-rs-rt/linkme-esp32c6-fixup.x

This file was deleted.

3 changes: 3 additions & 0 deletions src/riot-rs-threads/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ esp-hal = { workspace = true, features = ["esp32c3"] }
[target.'cfg(context = "esp32c6")'.dependencies]
esp-hal = { workspace = true, features = ["esp32c6"] }

[target.'cfg(context = "esp32s3")'.dependencies]
esp-hal = { workspace = true, features = ["esp32s3"] }

[target.'cfg(context = "cortex-m")'.dependencies]
# cortex-m specifics
cortex-m.workspace = true
Expand Down
9 changes: 5 additions & 4 deletions src/riot-rs-threads/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ cfg_if::cfg_if! {
if #[cfg(context = "cortex-m")] {
mod cortex_m;
pub use cortex_m::Cpu;
}
else if #[cfg(any(context = "esp32c3", context = "esp32c6"))] {
} else if #[cfg(context = "riscv")] {
mod riscv;
pub use riscv::Cpu;
}
else {
} else if #[cfg(context = "xtensa")] {
mod xtensa;
pub use xtensa::Cpu;
} else {
pub struct Cpu;
impl Arch for Cpu {
type ThreadData = ();
Expand Down
Loading
Loading