Finally compiles
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
[build]
|
||||||
|
target = "xtensa-esp32s3-espidf"
|
||||||
|
|
||||||
|
[target.xtensa-esp32s3-espidf]
|
||||||
|
linker = "ldproxy"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["std", "panic_abort"]
|
||||||
|
|
||||||
|
[env]
|
||||||
|
MCU = "esp32s3"
|
||||||
|
ESP_IDF_VERSION = "v5.3.1"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/.vscode
|
||||||
|
/.embuild
|
||||||
|
/target
|
||||||
|
/Cargo.lock
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
[package]
|
||||||
|
name = "hello-eth"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "hello-eth"
|
||||||
|
harness = false
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-idf-svc = { version = "0.51", features = ["std"] }
|
||||||
|
anyhow = "1"
|
||||||
|
log = "0.4"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embuild = "0.33"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)
|
||||||
|
# You might have to increase this further if you allocate large stack variables in the main task
|
||||||
|
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
|
||||||
|
|
||||||
|
# Increase a bit these stack sizes as they are also a bit too small by default
|
||||||
|
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096
|
||||||
|
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096
|
||||||
|
|
||||||
|
# You might have to increase this further if you spawn your own Rust threads
|
||||||
|
# that allocate large stack variables; or better yet - use
|
||||||
|
# `std::thread::Builder::new().stack_size(XXX)` for spawning
|
||||||
|
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=4096
|
||||||
|
|
||||||
|
CONFIG_ETH_SPI_ETHERNET_W5500=y
|
||||||
|
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000
|
||||||
|
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use esp_idf_svc::eth::{BlockingEth, EspEth, EthDriver, SpiEthChipset};
|
||||||
|
use esp_idf_svc::eventloop::EspSystemEventLoop;
|
||||||
|
use esp_idf_svc::hal::peripherals::Peripherals;
|
||||||
|
use esp_idf_svc::hal::prelude::*;
|
||||||
|
use esp_idf_svc::hal::spi::{config::DriverConfig, SpiDriver};
|
||||||
|
use esp_idf_svc::http::server::{Configuration as HttpServerConfig, EspHttpServer};
|
||||||
|
use esp_idf_svc::http::Method;
|
||||||
|
use esp_idf_svc::io::Write;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
fn main() -> anyhow::Result<()> {
|
||||||
|
esp_idf_svc::sys::link_patches();
|
||||||
|
esp_idf_svc::log::EspLogger::initialize_default();
|
||||||
|
|
||||||
|
let peripherals = Peripherals::take()?;
|
||||||
|
let sysloop = EspSystemEventLoop::take()?;
|
||||||
|
let pins = peripherals.pins;
|
||||||
|
|
||||||
|
let spi_driver = SpiDriver::new(
|
||||||
|
peripherals.spi2,
|
||||||
|
pins.gpio13, // SCLK
|
||||||
|
pins.gpio11, // MOSI (sdo)
|
||||||
|
Some(pins.gpio12), // MISO (sdi)
|
||||||
|
&DriverConfig::new(),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let eth_driver = EthDriver::new_spi(
|
||||||
|
spi_driver,
|
||||||
|
pins.gpio10, // INT
|
||||||
|
Some(pins.gpio14), // CS
|
||||||
|
Some(pins.gpio9), // RST
|
||||||
|
SpiEthChipset::W5500,
|
||||||
|
20.MHz().into(),
|
||||||
|
Some(&[0x02, 0x00, 0x00, 0x12, 0x34, 0x56]), // locally-administered MAC
|
||||||
|
None, // phy addr — default
|
||||||
|
sysloop.clone(),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let eth = EspEth::wrap(eth_driver)?;
|
||||||
|
let mut eth = BlockingEth::wrap(eth, sysloop)?;
|
||||||
|
|
||||||
|
info!("Starting eth...");
|
||||||
|
eth.start()?;
|
||||||
|
info!("Waiting for DHCP lease...");
|
||||||
|
eth.wait_netif_up()?;
|
||||||
|
|
||||||
|
let ip_info = eth.eth().netif().get_ip_info()?;
|
||||||
|
info!("Got IP: {:?}", ip_info);
|
||||||
|
|
||||||
|
let mut server = EspHttpServer::new(&HttpServerConfig::default())?;
|
||||||
|
server.fn_handler("/", Method::Get, |req| {
|
||||||
|
let html = "<html><body><h1>Hello World</h1></body></html>";
|
||||||
|
req.into_ok_response()?.write_all(html.as_bytes())?;
|
||||||
|
anyhow::Ok(())
|
||||||
|
})?;
|
||||||
|
|
||||||
|
info!("Server up. Browse to http://{}/", ip_info.ip);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
thread::sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user