Skip to content
Merged
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
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ embedded-hal = "0.2.3"
nb = "1.0.0"
void = { version = "1.0.2", default-features = false }
esp32c3-hal = { version = "0.4.0", optional = true }
esp32c2-hal = { version = "0.2.0", optional = true }
esp32-hal = { version = "0.7.0", optional = true, features = [ "rt" ] }
esp32s3-hal = { version = "0.4.0", optional = true, features = [ "rt" ] }
esp32s2-hal = { version = "0.4.0", optional = true, features = [ "rt" ] }
Expand All @@ -34,13 +35,14 @@ heapless = { version = "0.7.14", default-features = false }
riscv-target = { version = "0.1.2", optional = true }

[dev-dependencies]
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps" }
bleps-macros = { git = "https://github.com/bjoernQ/bleps", package = "bleps-macros" }
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "06e1f7b3810b7271d1004635842b691adaea4818" }
bleps-macros = { git = "https://github.com/bjoernQ/bleps", package = "bleps-macros", rev = "06e1f7b3810b7271d1004635842b691adaea4818" }

[target.xtensa-esp32-none-elf.dev-dependencies]
esp-println = { version = "0.3.1", features = [ "esp32", "log" ] }
esp-backtrace = { version = "0.4.0", features = [ "esp32", "panic-handler", "exception-handler", "print-uart" ] }

# change this for ESP32C3 / ESP32C2
[target.riscv32imc-unknown-none-elf.dev-dependencies]
esp-println = { version = "0.3.1", features = [ "esp32c3", "log" ] }
esp-backtrace = { version = "0.4.0", features = [ "esp32c3", "panic-handler", "exception-handler", "print-uart" ] }
Expand All @@ -57,6 +59,7 @@ xtensa-atomic-emulation-trap = "0.3.0"
[features]
default = [ "utils" ]
esp32c3 = [ "riscv-target", "riscv", "riscv-rt", "esp32c3-hal" ]
esp32c2 = [ "riscv-target", "riscv", "riscv-rt", "esp32c2-hal" ]
esp32 = [ "esp32-hal", "xtensa-lx-rt/esp32", "xtensa-lx/esp32" ]
esp32s3 = [ "esp32s3-hal", "xtensa-lx-rt/esp32s3", "xtensa-lx/esp32s3" ]
esp32s2 = [ "esp32s2-hal", "xtensa-lx-rt/esp32s2", "xtensa-lx/esp32s2" ]
Expand All @@ -69,3 +72,7 @@ wifi = []
ble = [ "esp32-hal?/bluetooth" ]
phy_enable_usb = []
ps_min_modem = []

# for now esp32c2 PAC is missing some interrupts
[patch.crates-io]
esp32c2 = { git = "https://github.com/esp-rs/esp-pacs", package = "esp32c2", rev = "1f7aee9" }
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ https://github.com/esp-rs/esp-wireless-drivers-3rdparty/ (commit f4caebff200e8f6
| `CARGO_PROFILE_RELEASE_OPT_LEVEL=1 cargo "+esp" run --example coex --release --target xtensa-esp32s3-none-elf --features "esp32s3,embedded-svc,wifi,ble"` | ESP32-S3|
| `cargo "+esp" run --example dhcp --release --target xtensa-esp32s2-none-elf --features "esp32s2,embedded-svc,wifi"` | ESP32-S2|
| `cargo "+esp" run --example static_ip --release --target xtensa-esp32s2-none-elf --features "esp32s2,embedded-svc,wifi"` | ESP32-S2|
| `cargo "+nightly" run --example dhcp --release --target riscv32imc-unknown-none-elf --features "esp32c2,embedded-svc,wifi"` | ESP32-C2|
| `cargo "+nightly" run --example static_ip --release --target riscv32imc-unknown-none-elf --features "esp32c2,embedded-svc,wifi"`| ESP32-C2|

Additionally you can specify these features
|Feature|Meaning|
Expand Down Expand Up @@ -91,6 +93,10 @@ On ESP32-C3 / ESP32-S3 when using Serial-JTAG you have to activate the feature `

Don't use this feature if your are _not_ using Serial-JTAG since it might reduce WiFi performance.

## Running examples on ESP32-C2

To run the examples on ESP32-C2 you need to modify Cargo-toml, section `target.riscv32imc-unknown-none-elf.dev-dependencies`

## What works?

- scanning for WiFi access points
Expand Down
64 changes: 64 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::PathBuf;

#[cfg(any(
feature = "esp32c3",
feature = "esp32c2",
feature = "esp32",
feature = "esp32s3",
feature = "esp32s2"
Expand Down Expand Up @@ -50,6 +51,10 @@ fn main() -> Result<(), String> {
return Err("BLE is not supported for ESP32-S2".into());
}

if cfg!(feature = "esp32c2") && cfg!(feature = "ble") {
return Err("BLE is not yet supported for ESP32-C2".into());
}

if features >= 2 {
println!("cargo:rustc-cfg=coex");
}
Expand All @@ -59,6 +64,64 @@ fn main() -> Result<(), String> {
Ok(())
}

#[cfg(feature = "esp32c2")]
fn handle_chip() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());

copy(
out,
include_bytes!("ld/esp32c2/rom_functions.x"),
"esp32c3_rom_functions.x",
);

copy(out, include_bytes!("libs/esp32c2/libbtbb.a"), "libbtbb.a");
copy(
out,
include_bytes!("libs/esp32c2/libcoexist.a"),
"libcoexist.a",
);
copy(out, include_bytes!("libs/esp32c2/libcore.a"), "libcore.a");
copy(
out,
include_bytes!("libs/esp32c2/libespnow.a"),
"libespnow.a",
);
copy(
out,
include_bytes!("libs/esp32c2/libnet80211.a"),
"libnet80211.a",
);
copy(out, include_bytes!("libs/esp32c2/libphy.a"), "libphy.a");
copy(out, include_bytes!("libs/esp32c2/libpp.a"), "libpp.a");
copy(
out,
include_bytes!("libs/esp32c2/libsmartconfig.a"),
"libsmartconfig.a",
);
copy(
out,
include_bytes!("libs/esp32c2/libwpa_supplicant.a"),
"libwpa_supplicant.a",
);

println!("cargo:rustc-link-lib={}", "btbb");
println!("cargo:rustc-link-lib={}", "coexist");
println!("cargo:rustc-link-lib={}", "core");
println!("cargo:rustc-link-lib={}", "espnow");
println!("cargo:rustc-link-lib={}", "net80211");
println!("cargo:rustc-link-lib={}", "phy");
println!("cargo:rustc-link-lib={}", "pp");
println!("cargo:rustc-link-lib={}", "smartconfig");
println!("cargo:rustc-link-lib={}", "wpa_supplicant");

println!("cargo:rustc-link-search={}", out.display());

// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=memory.x");
}

#[cfg(feature = "esp32c3")]
fn handle_chip() {
// Put the linker script somewhere the linker can find it
Expand Down Expand Up @@ -329,6 +392,7 @@ fn copy(path: &PathBuf, data: &[u8], name: &str) {

#[cfg(not(any(
feature = "esp32c3",
feature = "esp32c2",
feature = "esp32",
feature = "esp32s3",
feature = "esp32s2"
Expand Down
10 changes: 7 additions & 3 deletions examples/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#[cfg(feature = "esp32")]
use esp32_hal as hal;
#[cfg(feature = "esp32c2")]
use esp32c2_hal as hal;
#[cfg(feature = "esp32c3")]
use esp32c3_hal as hal;
#[cfg(feature = "esp32s2")]
Expand All @@ -28,10 +30,10 @@ use hal::Rng;
use hal::{pac::Peripherals, prelude::*, Rtc};
use smoltcp::wire::Ipv4Address;

#[cfg(any(feature = "esp32c3"))]
#[cfg(any(feature = "esp32c3", feature = "esp32c2"))]
use hal::system::SystemExt;

#[cfg(feature = "esp32c3")]
#[cfg(any(feature = "esp32c3", feature = "esp32c2"))]
use riscv_rt::entry;
#[cfg(any(feature = "esp32", feature = "esp32s3", feature = "esp32s2"))]
use xtensa_lx_rt::entry;
Expand All @@ -53,6 +55,8 @@ fn main() -> ! {

#[cfg(feature = "esp32c3")]
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock160MHz).freeze();
#[cfg(feature = "esp32c2")]
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock120MHz).freeze();
#[cfg(any(feature = "esp32", feature = "esp32s3", feature = "esp32s2"))]
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze();

Expand All @@ -68,7 +72,7 @@ fn main() -> ! {
let ethernet = create_network_interface(network_stack_storage!(storage));
let mut wifi_interface = esp_wifi::wifi_interface::Wifi::new(ethernet);

#[cfg(feature = "esp32c3")]
#[cfg(any(feature = "esp32c3", feature = "esp32c2"))]
{
use hal::systimer::SystemTimer;
let syst = SystemTimer::new(peripherals.SYSTIMER);
Expand Down
10 changes: 7 additions & 3 deletions examples/static_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#[cfg(feature = "esp32")]
use esp32_hal as hal;
#[cfg(feature = "esp32c2")]
use esp32c2_hal as hal;
#[cfg(feature = "esp32c3")]
use esp32c3_hal as hal;
#[cfg(feature = "esp32s2")]
Expand All @@ -27,10 +29,10 @@ use hal::clock::{ClockControl, CpuClock};
use hal::Rng;
use hal::{pac::Peripherals, prelude::*, Rtc};

#[cfg(any(feature = "esp32c3"))]
#[cfg(any(feature = "esp32c3", feature = "esp32c2"))]
use hal::system::SystemExt;

#[cfg(feature = "esp32c3")]
#[cfg(any(feature = "esp32c3", feature = "esp32c2"))]
use riscv_rt::entry;
#[cfg(any(feature = "esp32", feature = "esp32s3", feature = "esp32s2"))]
use xtensa_lx_rt::entry;
Expand All @@ -54,6 +56,8 @@ fn main() -> ! {

#[cfg(feature = "esp32c3")]
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock160MHz).freeze();
#[cfg(feature = "esp32c2")]
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock120MHz).freeze();
#[cfg(any(feature = "esp32", feature = "esp32s3", feature = "esp32s2"))]
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze();

Expand All @@ -69,7 +73,7 @@ fn main() -> ! {
let ethernet = create_network_interface(network_stack_storage!(storage));
let mut wifi_interface = esp_wifi::wifi_interface::Wifi::new(ethernet);

#[cfg(feature = "esp32c3")]
#[cfg(any(feature = "esp32c3", feature = "esp32c2"))]
{
use hal::systimer::SystemTimer;
let syst = SystemTimer::new(peripherals.SYSTIMER);
Expand Down
Loading