diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile new file mode 100644 index 00000000..c7fdf763 --- /dev/null +++ b/.gitpod.Dockerfile @@ -0,0 +1,31 @@ +# Note: gitpod/workspace-base image references older version of CMake, it's necessary to install newer one +FROM gitpod/workspace-base +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 +ARG CONTAINER_USER=gitpod +ARG CONTAINER_GROUP=gitpod +ARG NIGHTLY_VERSION=nightly-2022-03-10 +ARG ESP_IDF_VERSION=v4.4.1 +ARG ESP_BOARD=esp32c3 +RUN sudo install-packages git curl gcc clang ninja-build libudev-dev \ + python3 python3-pip libusb-1.0-0 libssl-dev pkg-config libtinfo5 libpython2.7 +USER ${CONTAINER_USER} +WORKDIR /home/${CONTAINER_USER} +ENV PATH=${PATH}:/home/${CONTAINER_USER}/.cargo/bin +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ + --default-toolchain ${NIGHTLY_VERSION} -y \ + && $HOME/.cargo/bin/rustup component add rust-src --toolchain ${NIGHTLY_VERSION} \ + && $HOME/.cargo/bin/rustup target add riscv32imc-unknown-none-elf \ + && $HOME/.cargo/bin/cargo install cargo-espflash ldproxy +RUN mkdir -p ${HOME}/.espressif/frameworks/ \ + && git clone --branch ${ESP_IDF_VERSION} -q --depth 1 --shallow-submodules \ + --recursive https://github.com/espressif/esp-idf.git \ + ${HOME}/.espressif/frameworks/esp-idf \ + && python3 ${HOME}/.espressif/frameworks/esp-idf/tools/idf_tools.py install cmake \ + && ${HOME}/.espressif/frameworks/esp-idf/install.sh ${ESP_BOARD} \ + && rm -rf .espressif/dist \ + && rm -rf .espressif/frameworks/esp-idf/docs \ + && rm -rf .espressif/frameworks/esp-idf/examples \ + && rm -rf .espressif/frameworks/esp-idf/tools/esp_app_trace \ + && rm -rf .espressif/frameworks/esp-idf/tools/test_idf_size +ENV IDF_TOOLS_PATH=/home/${CONTAINER_USER}/.espressif diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000..a0cb8ee5 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,17 @@ +image: + file: .gitpod.Dockerfile +tasks: + - name: Setup environment variables for ESP-IDF + command: | + source /home/gitpod/.espressif/frameworks/esp-idf-v4.4/export.sh > /dev/null 2>&1 +vscode: + extensions: + - matklad.rust-analyzer + - tamasfe.even-better-toml + - vadimcn.vscode-lldb + - anwar.resourcemonitor + - yzhang.markdown-all-in-one + - serayuzgur.crates +ports: + - port: 9012 + visibility: public \ No newline at end of file diff --git a/README.md b/README.md index 91ef4cd4..1e49e9f3 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ with the Espressif ESP32-C3. We suggest you start by [reading the book](https://espressif-trainings.ferrous-systems.com). + +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/ferrous-systems/espressif-trainings) + ## Contents There is: diff --git a/common/lib/esp32-c3-dkc02-bsc/Cargo.lock b/common/lib/esp32-c3-dkc02-bsc/Cargo.lock index 226588ab..4ef8c9b6 100644 --- a/common/lib/esp32-c3-dkc02-bsc/Cargo.lock +++ b/common/lib/esp32-c3-dkc02-bsc/Cargo.lock @@ -26,6 +26,15 @@ version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" +[[package]] +name = "atomic-polyfill" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14bf7b4f565e5e717d7a7a65b2a05c0b8c96e4db636d6f780f03b15108cdd1b" +dependencies = [ + "critical-section", +] + [[package]] name = "atty" version = "0.2.14" @@ -45,15 +54,18 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bare-metal" -version = "1.0.0" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version 0.2.3", +] [[package]] -name = "base64" -version = "0.12.3" +name = "bare-metal" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" +checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" [[package]] name = "bindgen" @@ -84,6 +96,12 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + [[package]] name = "bitflags" version = "1.3.2" @@ -105,6 +123,12 @@ version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439989e6b8c38d1b6570a384ef1e49c8848128f5a97f3914baef02920842712f" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "cc" version = "1.0.72" @@ -161,6 +185,30 @@ dependencies = [ "cc", ] +[[package]] +name = "cortex-m" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd20d4ac4aa86f4f75f239d59e542ef67de87cce2c282818dc6e84155d3ea126" +dependencies = [ + "bare-metal 0.2.5", + "bitfield", + "embedded-hal 0.2.7", + "volatile-register", +] + +[[package]] +name = "critical-section" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95da181745b56d4bd339530ec393508910c909c784e8962d15d722bacf0bcbcd" +dependencies = [ + "bare-metal 1.0.0", + "cfg-if", + "cortex-m", + "riscv", +] + [[package]] name = "crossbeam-channel" version = "0.5.5" @@ -208,9 +256,9 @@ dependencies = [ [[package]] name = "cstr_core" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644828c273c063ab0d39486ba42a5d1f3a499d35529c759e763a9c6cb8a0fb08" +checksum = "dd98742e4fdca832d40cab219dc2e3048de17d873248f83f17df47c1bea70956" dependencies = [ "cty", "memchr", @@ -295,50 +343,40 @@ dependencies = [ [[package]] name = "embedded-hal" -version = "1.0.0-alpha.7" +version = "1.0.0-alpha.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93cc714edeae73aa1ff259af4498595360b2992e0e9c59801873ed198a7f2216" +checksum = "c3babfc7fd332142a0b11aebf592992f211f4e01b6222fb04b03aba1bd80018d" dependencies = [ "nb 1.0.0", ] [[package]] -name = "embedded-svc" -version = "0.19.1" +name = "embedded-io" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeac0cf436604eced307910b6676bac59f328c07875b8f8d7c65bc5ecee9dbf4" +checksum = "36673b79844ff4ec0e3f00aeca0b2cfff564ff6739ab9801d13f45a8ec6cc1c7" dependencies = [ - "anyhow", - "enumset", "futures", - "http-auth-basic", - "log", - "no-std-net", - "num_enum", - "serde", - "serde_json", - "strum 0.23.0", - "strum_macros 0.23.1", ] [[package]] -name = "embuild" -version = "0.28.4" +name = "embedded-svc" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76f3d7e8ed0354738a5e220441e9866cf6ce0750e446aded4c11315ae279bb8" +checksum = "b52805b9b97351bb74d61d513e226bddb81e6e5117bca61d1d4371d4c795d7cc" dependencies = [ "anyhow", - "bitflags", - "dirs", + "embedded-io", + "enumset", + "futures", + "heapless", "log", + "no-std-net", + "num_enum", "serde", "serde_json", - "shlex", "strum 0.23.0", "strum_macros 0.23.1", - "thiserror", - "toml", - "xmas-elf", ] [[package]] @@ -404,32 +442,33 @@ dependencies = [ [[package]] name = "esp-idf-hal" -version = "0.35.1" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c9745ec647d871638d95dd5a17e0e9cafade6b64679b3a4399d935b16887173" +checksum = "cc998eadd4eb0b3da435b72b5f4ac29b16b8937224bc08d49e5701038a1ab2d6" dependencies = [ "anyhow", "embedded-hal 0.2.7", - "embedded-hal 1.0.0-alpha.7", + "embedded-hal 1.0.0-alpha.8", "embedded-svc", - "embuild 0.28.4", + "embuild", "esp-idf-sys", "nb 0.1.3", ] [[package]] name = "esp-idf-svc" -version = "0.39.1" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "075259b99be1d75c7274399f11cbcb67415c88f7e3d822c6531fed78fcb8716d" +checksum = "98f380bf76e2fc822680a7f424051e11877e82f74fb946ed7400f9dc596bcec3" dependencies = [ "anyhow", "cstr_core", "embedded-svc", - "embuild 0.28.4", + "embuild", "enumset", "esp-idf-hal", "esp-idf-sys", + "heapless", "log", "uncased", ] @@ -442,7 +481,7 @@ checksum = "b239e46fe930f21ed36a25de1b6d29a0e22b65166f3a8e44624095a671f2f56c" dependencies = [ "anyhow", "bindgen", - "embuild 0.29.3", + "embuild", "paste", "regex", "strum 0.24.1", @@ -470,7 +509,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "382a36a399c646e7823b2fc9be785910b32c49a676c535bc63abb9acceee284c" dependencies = [ - "bare-metal", + "bare-metal 1.0.0", "riscv", "vcell", ] @@ -556,11 +595,15 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -604,6 +647,29 @@ dependencies = [ "walkdir", ] +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "heapless" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f6733da246dc2af610133c8be0667170fd68e8ca5630936b520300eee8846f9" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version 0.4.0", + "serde", + "spin", + "stable_deref_trait", +] + [[package]] name = "heck" version = "0.3.3" @@ -628,15 +694,6 @@ dependencies = [ "libc", ] -[[package]] -name = "http-auth-basic" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df69b6a68474b935f436fb9c84139f32de4f7759810090d1a3a5e592553f7ee0" -dependencies = [ - "base64", -] - [[package]] name = "humantime" version = "2.1.0" @@ -710,6 +767,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "lock_api" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -960,7 +1026,7 @@ name = "riscv" version = "0.7.0" source = "git+https://github.com/rust-embedded/riscv?rev=396fb9b#396fb9b8daeb11e8632e53ccc42590385a1eeb87" dependencies = [ - "bare-metal", + "bare-metal 1.0.0", "bit_field", "embedded-hal 0.2.7", "riscv-target", @@ -982,6 +1048,24 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.12", +] + [[package]] name = "rustversion" version = "1.0.6" @@ -1009,6 +1093,27 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "serde" version = "1.0.136" @@ -1046,6 +1151,30 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "spin" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +dependencies = [ + "lock_api", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "strsim" version = "0.8.0" @@ -1199,9 +1328,9 @@ dependencies = [ [[package]] name = "uncased" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0" +checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" dependencies = [ "version_check", ] @@ -1248,6 +1377,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "volatile-register" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee8f19f9d74293faf70901bc20ad067dc1ad390d2cbf1e3f75f721ffee908b6" +dependencies = [ + "vcell", +] + [[package]] name = "walkdir" version = "2.3.2" diff --git a/common/lib/esp32-c3-dkc02-bsc/Cargo.toml b/common/lib/esp32-c3-dkc02-bsc/Cargo.toml index dbd01543..0cb1dc25 100644 --- a/common/lib/esp32-c3-dkc02-bsc/Cargo.toml +++ b/common/lib/esp32-c3-dkc02-bsc/Cargo.toml @@ -9,9 +9,9 @@ edition = "2021" [dependencies] esp32c3 = "=0.3.0" esp-idf-sys = { version = "=0.31.5" } -esp-idf-svc = { version="=0.39.1", features = ["experimental", "alloc"] } -esp-idf-hal = "=0.35.1" -embedded-svc = "=0.19" +esp-idf-svc = { version="=0.42.1", features = ["experimental", "alloc"] } +esp-idf-hal = "=0.38" +embedded-svc = "=0.22" rgb = "0.8" log = "0.4" anyhow = "1" diff --git a/common/lib/esp32-c3-dkc02-bsc/src/wifi.rs b/common/lib/esp32-c3-dkc02-bsc/src/wifi.rs index 73d7ed14..b5accc5b 100644 --- a/common/lib/esp32-c3-dkc02-bsc/src/wifi.rs +++ b/common/lib/esp32-c3-dkc02-bsc/src/wifi.rs @@ -11,6 +11,7 @@ use esp_idf_svc::{ netif::EspNetifStack, nvs::EspDefaultNvs, sysloop::EspSysLoopStack, wifi::EspWifi, }; use log::info; +use std::time::Duration; #[allow(unused)] pub struct Wifi { @@ -21,11 +22,11 @@ pub struct Wifi { } pub fn wifi(ssid: &str, psk: &str) -> anyhow::Result { - let mut auth_method = AuthMethod::WPA2Personal; - if ssid.len() == 0 { + let mut auth_method = AuthMethod::WPA2Personal; // Todo: add this setting - router dependent + if ssid.is_empty() { anyhow::bail!("missing WiFi name") } - if psk.len() == 0 { + if psk.is_empty() { auth_method = AuthMethod::None; info!("Wifi password is empty"); } @@ -63,22 +64,32 @@ pub fn wifi(ssid: &str, psk: &str) -> anyhow::Result { ssid: ssid.into(), password: psk.into(), channel, - auth_method: auth_method, + auth_method, ..Default::default() }))?; info!("getting Wifi status"); + wifi.wait_status_with_timeout(Duration::from_secs(2100), |status| { + !status.is_transitional() + }) + .map_err(|err| anyhow::anyhow!("Unexpected Wifi status (Transitional state): {:?}", err))?; + let status = wifi.get_status(); if let wifi::Status( - ClientStatus::Started(ClientConnectionStatus::Connected(ClientIpStatus::Done(_))), + ClientStatus::Started(ClientConnectionStatus::Connected(ClientIpStatus::Done( + _ip_settings, + ))), _, ) = status { - info!("Wifi connected!"); + info!("Wifi connected"); } else { - bail!("Unexpected Wifi status: {:?}", status); + bail!( + "Could not connect to Wifi - Unexpected Wifi status: {:?}", + status + ); } let wifi = Wifi { diff --git a/intro/hardware-check/Cargo.toml b/intro/hardware-check/Cargo.toml index d5cc4087..b3813be0 100644 --- a/intro/hardware-check/Cargo.toml +++ b/intro/hardware-check/Cargo.toml @@ -18,6 +18,7 @@ native = ["esp-idf-sys/native"] [dependencies] esp-idf-sys = { version = "=0.31.5", features = ["binstart"] } +esp-idf-svc = { version="=0.42.1", features = ["experimental", "alloc"] } esp32-c3-dkc02-bsc = { path = "../../common/lib/esp32-c3-dkc02-bsc" } log = "0.4" anyhow = "1" diff --git a/intro/hardware-check/src/main.rs b/intro/hardware-check/src/main.rs index c7db94ee..3e4a177e 100644 --- a/intro/hardware-check/src/main.rs +++ b/intro/hardware-check/src/main.rs @@ -33,8 +33,9 @@ fn main() -> anyhow::Result<()> { use bsc::led::RGB8; esp_idf_sys::link_patches(); + esp_idf_svc::log::EspLogger::initialize_default(); - println!("Hello, world!"); + info!("Hello, world!"); // Start the LED off yellow let mut led = bsc::led::WS2812RMT::new()?;