Skip to content

Commit

Permalink
Merge pull request #25 from suapapa/main
Browse files Browse the repository at this point in the history
Enhanced ESP32 series support
  • Loading branch information
AdinAck authored Dec 15, 2024
2 parents 5283950 + d747637 commit 2a92f01
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 32 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install Deps
run: sudo apt -y install libudev-dev
- name: ci
- name: CI
run: ./ci.sh
ci-esp:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install Deps
run: sudo apt -y install libudev-dev
- name: CI
run: ./ci-esp.sh
10 changes: 6 additions & 4 deletions ci-esp.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cd $test_dir

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

# esp toolchain
Expand All @@ -32,9 +33,10 @@ fi
. $HOME/export-esp.sh

# compile
cd ../test-esp32c3; cargo build --release
cd ../test-esp32s3; cargo build --release
cd $test_dir/test-esp32c3; cargo build --release
cd $test_dir/test-esp32s2; cargo build --release
cd $test_dir/test-esp32s3; cargo build --release

# clean up
cd ../..
# rm -r ci
cd $cwd
# rm -r $test_dir/ci
1 change: 1 addition & 0 deletions src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl FromStr for Chip {
("stm32wl", (STM, Thumbv7e)),
// ESP32
("esp32c3", (ESP(Variant::C3), Risc32Imc)),
("esp32s2", (ESP(Variant::S2), XTensaS2)),
("esp32s3", (ESP(Variant::S3), XTensaS3)),
];

Expand Down
2 changes: 2 additions & 0 deletions src/chip/family/esp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use std::fmt::Display;
#[derive(Clone, Debug)]
pub enum Variant {
C3,
S2,
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::S2 => "esp32s2",
Self::S3 => "esp32s3",
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/chip/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub enum Target {
Thumbv7e,
Thumbv7f,
Thumbv8,
XTensaS2,
XTensaS3,
Risc32Imc,
}
Expand All @@ -19,6 +20,7 @@ impl Display for Target {
Self::Thumbv7e => "thumbv7em-none-eabi",
Self::Thumbv7f => "thumbv7em-none-eabihf",
Self::Thumbv8 => "thumbv8m.main-none-eabihf",
Self::XTensaS2 => "xtensa-esp32s2-none-elf",
Self::XTensaS3 => "xtensa-esp32s3-none-elf",
Self::Risc32Imc => "riscv32imc-unknown-none-elf",
})
Expand Down
3 changes: 2 additions & 1 deletion src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ impl Init {
target = chip.target,
rustflags = match variant {
Variant::C3 => "rustflags = [\n\"-C\", \"force-frame-pointers\",\n]",
Variant::S3 => "rustflags = [\n\"-C\", \"link-arg=-nostartfiles\",\n]",
Variant::S2 | Variant::S3 =>
"rustflags = [\n\"-C\", \"link-arg=-nostartfiles\",\n]",
}
),
_ => format!(
Expand Down
2 changes: 1 addition & 1 deletion src/templates/config.toml.esp.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runner = "espflash flash --monitor"


[env]
ESP_LOGLEVEL="INFO"
ESP_LOG="INFO"

[build]
{rustflags}
Expand Down
36 changes: 12 additions & 24 deletions src/templates/main.rs.esp.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,29 @@ use embassy_executor::Spawner;
use embassy_time::Timer;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::{Io, Level, Output},
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
self,
clock::CpuClock,
gpio::{Level, Output},
timer::timg::TimerGroup,
};
use esp_hal_embassy::main;
use esp_println::println;
use static_cell::StaticCell;

#[main]
async fn main(_spawner: Spawner) {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);

let clocks = ClockControl::max(system.clock_control).freeze();

esp_println::logger::init_logger_from_env();

let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks, None);

let timer = {
static TIMER: StaticCell<[OneShotTimer<ErasedTimer>; 1]> = StaticCell::new();

TIMER.init([OneShotTimer::new(timg0.timer0.into())])
};

esp_hal_embassy::init(&clocks, timer);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::max();
let peripherals = esp_hal::init(config);

let mut led = Output::new(io.pins.gpio17, Level::Low);
let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(timg0.timer0);

let mut led = Output::new(peripherals.GPIO17, Level::High);
loop {
println!("Hello, World!");
led.toggle();
Timer::after_millis(1_000).await;
}
}
}

0 comments on commit 2a92f01

Please sign in to comment.