Skip to content

Commit

Permalink
some refactoring and add ESP32 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AdinAck committed Jul 13, 2024
1 parent dd9001c commit 96a0658
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 106 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Inflector = "0.11.4"
clap = { version = "4.4.11", features = ["derive"] }
indicatif = "0.17.7"
open = "5.0.1"
probe-rs = "0.21.1"
probe-rs = "0.24.0"
termimad = "0.29.1"
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Get up and running with Embassy in seconds.

# Features
- Supports STM32* and NRF*
- Supports STM32*, NRF*, and ESP32(C3/S3)
- Generates project structure
- Toolchain
- Probing
Expand Down Expand Up @@ -57,3 +57,8 @@ cargo embassy init my_project --chip nrf52840
```sh
cargo embassy init my_project --chip nrf52832_xxAA --softdevice s132
```

**Create a new Embassy project for the ESP32S3**
```sh
cargo embassy init my_project --chip esp32s3
```
6 changes: 6 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ $cwd/target/release/cargo-embassy embassy init test-stm32g4 --chip stm32g431rb -
$cwd/target/release/cargo-embassy embassy init test-nrf52840 --chip nrf52840
$cwd/target/release/cargo-embassy embassy init test-nrf52832 --chip nrf52832-xxab --softdevice s132

# esp32
$cwd/target/release/cargo-embassy embassy init test-esp32c3 --chip esp32c3
$cwd/target/release/cargo-embassy embassy init test-esp32s3 --chip esp32s3

# compile
cd test-stm32g0; cargo build; cargo build --no-default-features --release
cd ../test-stm32g4; cargo build; cargo build --no-default-features --release
cd ../test-nrf52840; cargo build; cargo build --no-default-features --release
cd ../test-nrf52832; cargo build; cargo build --no-default-features --release
cd ../test-esp32c3; cargo build --release
cd ../test-esp32s3; cargo build --release

# clean up
cd ../..
Expand Down
48 changes: 27 additions & 21 deletions src/chip.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod family;
pub mod target;

use family::esp::Variant;

use crate::error::{Error, InvalidChip};
use std::str::FromStr;

Expand Down Expand Up @@ -29,25 +31,28 @@ impl FromStr for Chip {
("nrf52840", (NRF(MemRegion::NRF52840), Thumbv7f)),
// TODO: nrf53x and nrf91x
// STM
("stm32c0", (STM32, Thumbv6)),
("stm32f0", (STM32, Thumbv6)),
("stm32f1", (STM32, Thumbv7)),
("stm32f2", (STM32, Thumbv7)),
("stm32f3", (STM32, Thumbv7e)),
("stm32f4", (STM32, Thumbv7e)),
("stm32f7", (STM32, Thumbv7e)),
("stm32g0", (STM32, Thumbv6)),
("stm32g4", (STM32, Thumbv7e)),
("stm32h5", (STM32, Thumbv8)),
("stm32h7", (STM32, Thumbv7e)),
("stm32l0", (STM32, Thumbv6)),
("stm32l1", (STM32, Thumbv7)),
("stm32l4", (STM32, Thumbv7e)),
("stm32l5", (STM32, Thumbv8)),
("stm32u5", (STM32, Thumbv8)),
("stm32wb", (STM32, Thumbv7e)),
("stm32wba", (STM32, Thumbv8)),
("stm32wl", (STM32, Thumbv7e)),
("stm32c0", (STM, Thumbv6)),
("stm32f0", (STM, Thumbv6)),
("stm32f1", (STM, Thumbv7)),
("stm32f2", (STM, Thumbv7)),
("stm32f3", (STM, Thumbv7e)),
("stm32f4", (STM, Thumbv7e)),
("stm32f7", (STM, Thumbv7e)),
("stm32g0", (STM, Thumbv6)),
("stm32g4", (STM, Thumbv7e)),
("stm32h5", (STM, Thumbv8)),
("stm32h7", (STM, Thumbv7e)),
("stm32l0", (STM, Thumbv6)),
("stm32l1", (STM, Thumbv7)),
("stm32l4", (STM, Thumbv7e)),
("stm32l5", (STM, Thumbv8)),
("stm32u5", (STM, Thumbv8)),
("stm32wb", (STM, Thumbv7e)),
("stm32wba", (STM, Thumbv8)),
("stm32wl", (STM, Thumbv7e)),
// ESP32
("esp32c3", (ESP(Variant::C3), Risc32Imc)),
("esp32s3", (ESP(Variant::S3), XTensaS3)),
];

let (family, target) = chips
Expand All @@ -59,10 +64,11 @@ impl FromStr for Chip {
})?;

Ok(Self {
name: match family {
STM32 => chip.to_string(),
name: match &family {
STM => chip.to_string(),
// FRAGILE: "_" is used to coerce probe-rs chip search
NRF(_) => chip.split('_').next().unwrap().to_string(),
ESP(variant) => variant.to_string(),
},
family,
target,
Expand Down
8 changes: 6 additions & 2 deletions src/chip/family.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
pub mod esp;
pub mod mem_region;

use esp::Variant;
use mem_region::MemRegion;
use std::fmt::Display;

#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone)]
pub enum Family {
STM32,
STM,
NRF(MemRegion),
ESP(Variant),
}

impl Display for Family {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::STM32 => "stm32",
Self::STM => "stm32",
Self::NRF(_) => "nrf",
Self::ESP(_) => "esp",
})
}
}
16 changes: 16 additions & 0 deletions src/chip/family/esp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::fmt::Display;

#[derive(Clone, Debug)]
pub enum Variant {
C3,
S3,
}

impl Display for Variant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::C3 => "esp32c3",
Self::S3 => "esp32s3",
})
}
}
8 changes: 5 additions & 3 deletions src/chip/target.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use clap::ValueEnum;
use std::fmt::Display;

#[derive(Debug, Clone, ValueEnum)]
#[value()]
#[derive(Debug, Clone)]
pub enum Target {
Thumbv6,
Thumbv7,
Thumbv7e,
Thumbv7f,
Thumbv8,
XTensaS3,
Risc32Imc,
}

impl Display for Target {
Expand All @@ -19,6 +19,8 @@ impl Display for Target {
Self::Thumbv7e => "thumbv7em-none-eabi",
Self::Thumbv7f => "thumbv7em-none-eabihf",
Self::Thumbv8 => "thumbv8m.main-none-eabihf",
Self::XTensaS3 => "xtensa-esp32s3-none-elf",
Self::Risc32Imc => "riscv32imc-unknown-none-elf",
})
}
}
2 changes: 1 addition & 1 deletion src/cli/init_args/panic_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::ValueEnum;

#[derive(Debug, Clone, Default, ValueEnum)]
#[derive(Debug, Clone, Default, PartialEq, ValueEnum)]
#[value()]
pub enum PanicHandler {
#[default]
Expand Down
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub enum Error {
CreateFile(String),
CreateFolder(String),
ErroneousSoftdevice,
ErroneousPanicHandler,
InvalidChip(InvalidChip),
}

Expand Down
Loading

0 comments on commit 96a0658

Please sign in to comment.