working example with fixed flake
This commit is contained in:
49
.gitignore
vendored
Normal file
49
.gitignore
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# === Rust / Cargo ===
|
||||||
|
/target/
|
||||||
|
/**/target/
|
||||||
|
/**/*.rlib
|
||||||
|
**/*.d
|
||||||
|
**/*.rlib
|
||||||
|
**/*.rmeta
|
||||||
|
|
||||||
|
# === Nix / Flakes ===
|
||||||
|
result
|
||||||
|
.nix-result
|
||||||
|
.nix-gcRoots
|
||||||
|
.direnv
|
||||||
|
.envrc
|
||||||
|
.nix-hidden
|
||||||
|
|
||||||
|
# === Editor / IDE ===
|
||||||
|
# VSCode
|
||||||
|
.vscode/
|
||||||
|
# IntelliJ / CLion / RustRover
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
# Emacs
|
||||||
|
*~
|
||||||
|
.#*
|
||||||
|
# Vim
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# === Logs and Dumps ===
|
||||||
|
*.log
|
||||||
|
*.out
|
||||||
|
*.err
|
||||||
|
|
||||||
|
# === OS Junk ===
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# === ESP build junk ===
|
||||||
|
esp-idf/
|
||||||
|
.espressif/
|
||||||
|
*.elf
|
||||||
|
*.bin
|
||||||
|
*.uf2
|
||||||
|
*.app
|
||||||
|
*.map
|
||||||
|
|
||||||
|
|
||||||
|
flake.lock
|
||||||
28
flake.nix
28
flake.nix
@@ -25,21 +25,25 @@
|
|||||||
espup
|
espup
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
echo ">>> ESP32 DevShell (esp-hal only)"
|
echo ">>> ESP32 DevShell (esp-hal only)"
|
||||||
|
|
||||||
if [ ! -d "$HOME/.espup" ]; then
|
if [ ! -d "$HOME/.espup" ]; then
|
||||||
echo "Running espup install..."
|
echo "Running espup install..."
|
||||||
espup install
|
espup install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Activate Xtensa Rust toolchain
|
# Activate Xtensa Rust toolchain
|
||||||
export RUSTUP_TOOLCHAIN=esp
|
export RUSTUP_TOOLCHAIN=esp
|
||||||
export PATH=$HOME/.rustup/toolchains/esp/bin:$PATH
|
export PATH=$HOME/.rustup/toolchains/esp/bin:$PATH
|
||||||
|
|
||||||
echo "Xtensa Rust toolchain ready."
|
# Add GCC/binutils path for xtensa-esp32-elf-gcc
|
||||||
rustc --version
|
export PATH=$HOME/.rustup/toolchains/esp/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin:$PATH
|
||||||
'';
|
|
||||||
|
echo "Xtensa Rust toolchain ready."
|
||||||
|
rustc --version
|
||||||
|
which xtensa-esp32-elf-gcc || echo "⚠️ xtensa-esp32-elf-gcc not found in PATH"
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
16
test1/.cargo/config.toml
Normal file
16
test1/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOG="info"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
"-Z", "stack-protector=all",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
19
test1/.gitignore
vendored
Normal file
19
test1/.gitignore
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1457
test1/Cargo.lock
generated
Normal file
1457
test1/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
81
test1/Cargo.toml
Normal file
81
test1/Cargo.toml
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "test1"
|
||||||
|
rust-version = "1.86"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "test1"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
|
esp-hal = { version = "=1.0.0-rc.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"log-04",
|
||||||
|
"unstable",
|
||||||
|
] }
|
||||||
|
log = "0.4.27"
|
||||||
|
|
||||||
|
embassy-net = { version = "0.7.0", features = [
|
||||||
|
"dhcpv4",
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"tcp",
|
||||||
|
"udp",
|
||||||
|
] }
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
esp-alloc = "0.8.0"
|
||||||
|
esp-backtrace = { version = "0.17.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"exception-handler",
|
||||||
|
"panic-handler",
|
||||||
|
"println",
|
||||||
|
] }
|
||||||
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||||
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
|
"log",
|
||||||
|
"task-arena-size-20480",
|
||||||
|
] }
|
||||||
|
embassy-time = { version = "0.4.0", features = ["log"] }
|
||||||
|
esp-hal-embassy = { version = "0.9.0", features = ["esp32", "log-04"] }
|
||||||
|
esp-wifi = { version = "0.15.0", features = [
|
||||||
|
"builtin-scheduler",
|
||||||
|
"esp-alloc",
|
||||||
|
"esp32",
|
||||||
|
"log-04",
|
||||||
|
"smoltcp",
|
||||||
|
"wifi",
|
||||||
|
] }
|
||||||
|
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"multicast",
|
||||||
|
"proto-dhcpv4",
|
||||||
|
"proto-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"socket-dns",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-udp",
|
||||||
|
] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
52
test1/build.rs
Normal file
52
test1/build.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
fn main() {
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_wifi_preempt_enable"
|
||||||
|
| "esp_wifi_preempt_yield_task"
|
||||||
|
| "esp_wifi_preempt_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
2
test1/rust-toolchain.toml
Normal file
2
test1/rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
54
test1/src/bin/main.rs
Normal file
54
test1/src/bin/main.rs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![deny(
|
||||||
|
clippy::mem_forget,
|
||||||
|
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
|
||||||
|
holding buffers for the duration of a data transfer."
|
||||||
|
)]
|
||||||
|
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_time::{Duration, Timer};
|
||||||
|
use esp_backtrace as _;
|
||||||
|
use esp_hal::clock::CpuClock;
|
||||||
|
use esp_hal::timer::timg::TimerGroup;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||||
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
#[esp_hal_embassy::main]
|
||||||
|
async fn main(spawner: Spawner) {
|
||||||
|
// generator version: 0.5.0
|
||||||
|
|
||||||
|
esp_println::logger::init_logger_from_env();
|
||||||
|
|
||||||
|
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||||
|
let peripherals = esp_hal::init(config);
|
||||||
|
|
||||||
|
esp_alloc::heap_allocator!(size: 64 * 1024);
|
||||||
|
|
||||||
|
let timer0 = TimerGroup::new(peripherals.TIMG1);
|
||||||
|
esp_hal_embassy::init(timer0.timer0);
|
||||||
|
|
||||||
|
info!("Embassy initialized!");
|
||||||
|
|
||||||
|
let rng = esp_hal::rng::Rng::new(peripherals.RNG);
|
||||||
|
let timer1 = TimerGroup::new(peripherals.TIMG0);
|
||||||
|
let wifi_init =
|
||||||
|
esp_wifi::init(timer1.timer0, rng).expect("Failed to initialize WIFI/BLE controller");
|
||||||
|
let (mut _wifi_controller, _interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI)
|
||||||
|
.expect("Failed to initialize WIFI controller");
|
||||||
|
|
||||||
|
// TODO: Spawn some tasks
|
||||||
|
let _ = spawner;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
info!("Hello world!");
|
||||||
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
||||||
|
}
|
||||||
1
test1/src/lib.rs
Normal file
1
test1/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
Reference in New Issue
Block a user