From f69f0546895336056468fde5dc459df637001d45 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Arcos Date: Fri, 5 Jan 2024 10:08:29 +0100 Subject: [PATCH] Add a defmt project (#33) * feat: Initial defmt chapter * feat: Add esp-backtrace information * feat: Remove .gitignore files * ci: Cover defmt project --- .github/workflows/ci.yml | 4 +- book/src/03_6_defmt.md | 52 +++ book/src/SUMMARY.md | 3 +- intro/blinky/.gitignore | 10 - intro/button-interrupt/.gitignore | 10 - intro/button/.gitignore | 10 - intro/defmt/.cargo/config.toml | 20 + intro/defmt/Cargo.lock | 702 ++++++++++++++++++++++++++++++ intro/defmt/Cargo.toml | 12 + intro/defmt/examples/defmt.rs | 29 ++ intro/defmt/rust-toolchain.toml | 5 + intro/defmt/src/main.rs | 23 + intro/hello-world/.gitignore | 10 - intro/http-client/.gitignore | 10 - intro/panic/.gitignore | 10 - 15 files changed, 848 insertions(+), 62 deletions(-) create mode 100644 book/src/03_6_defmt.md delete mode 100644 intro/blinky/.gitignore delete mode 100644 intro/button-interrupt/.gitignore delete mode 100644 intro/button/.gitignore create mode 100644 intro/defmt/.cargo/config.toml create mode 100644 intro/defmt/Cargo.lock create mode 100644 intro/defmt/Cargo.toml create mode 100644 intro/defmt/examples/defmt.rs create mode 100644 intro/defmt/rust-toolchain.toml create mode 100644 intro/defmt/src/main.rs delete mode 100644 intro/hello-world/.gitignore delete mode 100644 intro/http-client/.gitignore delete mode 100644 intro/panic/.gitignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 854d9d2..8f7a38e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,8 @@ jobs: path: "intro/panic" - name: "http-client" path: "intro/http-client" + - name: "defmt" + path: "intro/defmt" - name: "stack-overflow-detection" path: "advanced/stack-overflow-detection" steps: @@ -79,7 +81,7 @@ jobs: working-directory: ${{ matrix.project.path }} - name: Wokwi CI check - if: matrix.project.name != 'stack-overflow-detection' && github.actor == 'esp-rs' + if: (matrix.project.name != 'stack-overflow-detection' || matrix.project.name != 'defmt') && github.actor == 'esp-rs' uses: wokwi/wokwi-ci-action@v1 with: token: ${{ secrets.WOKWI_CLI_TOKEN }} diff --git a/book/src/03_6_defmt.md b/book/src/03_6_defmt.md new file mode 100644 index 0000000..096c887 --- /dev/null +++ b/book/src/03_6_defmt.md @@ -0,0 +1,52 @@ +# `defmt` +In this chapter, we will cover [`defmt`][defmt], a highly efficient logging framework, and how to use it in the `no_std` environment. + + +[defmt]: https://defmt.ferrous-systems.com/ + +## `defmt` Ecosystem + +[`esp-println`][esp-println], [`esp-backtrace`][esp-backtrace] and [`espflash`/`cargo-espflash`][espflash] provide mechanisms to use `defmt`: +- `espflash` has support for different [logging formats][espflash-logformat], one of them being `defmt`. + - `espflash` requires framming bytes as when using `defmt` it also needs to print non-`defmt` messages, like the bootloader prints. + - It's important to note that other `defmt`-enabled tools like `probe-rs` won't be able to parse these messages due to the extra framing bytes. + - Uses [rzcobs encoding](https://github.com/Dirbaio/rzcobs) +- Both `esp-println` and `esp-backtrace` have a `defmt-espflash` feature, which adds framming bytes so `espflash` knows that is a `defmt` message. + + +[esp-println]: https://github.com/esp-rs/esp-println +[esp-backtrace]: https://github.com/esp-rs/esp-backtrace +[espflash]: https://github.com/esp-rs/espflash +[espflash-logformat]: https://github.com/esp-rs/espflash/blob/main/espflash/README.md#logging-format + +# Setup + +✅ Go to `intro/defmt` directory. + +✅ Open the prepared project skeleton in `intro/defmt`. + +`intro/defmt/examples/defmt.rs` contains the solution. You can run it with the following command: + +```shell +cargo run --release --example defmt +``` + +## Exercise + +✅ Make sure the `defmt-espflash` feature of `esp-println` and `esp-backtrace` are enabled. + +✅ Update the [linking process](https://defmt.ferrous-systems.com/setup#linker-script) in the `.cargo/config.toml`. + +✅ Make sure, the [`defmt` crate](https://crates.io/crates/defmt) is added to the dependencies. + +✅ Make sure you are building `esp_println` and `esp_backtrace` +```rust,ignore +{{#include ../../intro/defmt/examples/defmt.rs:println_include}} +``` + +✅ Use the `defmt::println!` or any of the logging [`defmt` macros](https://docs.rs/defmt/latest/defmt/#macros) to print a message. +- If you want to use any of the logging macros like `info`, `debug` + - Enable the `log` feature of `esp-println` + - When building the app, [set `DEFMT_LOG`](https://defmt.ferrous-systems.com/filtering.html?highlight=DEFMT_LOG#defmt_log) level. + +✅ Add a `panic!` macro to trigger a panic with a `defmt` message. diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 0c86311..4ff55c8 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -12,5 +12,6 @@ - [Detect a button press](./03_3_button.md) - [Detect a button press with interrupt](./03_4_interrupt.md) - [HTTP Client](./03_5_http_client.md) + - [Using `defmt`](./03_6_defmt.md) - [Advanced level examples](./04_0_intro_advanced_examples.md) - - [Stack overflow protection with Debug Assist](./04_1_stack_overflow_protection.md) \ No newline at end of file + - [Stack overflow protection with Debug Assist](./04_1_stack_overflow_protection.md) diff --git a/intro/blinky/.gitignore b/intro/blinky/.gitignore deleted file mode 100644 index 73fab07..0000000 --- a/intro/blinky/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb diff --git a/intro/button-interrupt/.gitignore b/intro/button-interrupt/.gitignore deleted file mode 100644 index 73fab07..0000000 --- a/intro/button-interrupt/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb diff --git a/intro/button/.gitignore b/intro/button/.gitignore deleted file mode 100644 index 73fab07..0000000 --- a/intro/button/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb diff --git a/intro/defmt/.cargo/config.toml b/intro/defmt/.cargo/config.toml new file mode 100644 index 0000000..bb0c15f --- /dev/null +++ b/intro/defmt/.cargo/config.toml @@ -0,0 +1,20 @@ +[target.riscv32imc-unknown-none-elf] +runner = "espflash flash --monitor -L defmt" + +[build] +rustflags = [ + "-C", "link-arg=-Tlinkall.x", + + # Add `defmt`linking options + "-C", "link-arg=-Tdefmt.x", + + # Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.) + # NOTE: May negatively impact performance of produced code + "-C", "force-frame-pointers", + +] + +target = "riscv32imc-unknown-none-elf" + +[unstable] +build-std = ["core"] diff --git a/intro/defmt/Cargo.lock b/intro/defmt/Cargo.lock new file mode 100644 index 0000000..5678580 --- /dev/null +++ b/intro/defmt/Cargo.lock @@ -0,0 +1,702 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "basic-toml" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f2139706359229bfa8f19142ac1155b4b80beafb7a60471ac5dd109d4a19778" +dependencies = [ + "serde", +] + +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + +[[package]] +name = "bitfield" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "critical-section" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" + +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.42", +] + +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.42", +] + +[[package]] +name = "defmt" +version = "0.1.0" +dependencies = [ + "defmt 0.3.5", + "esp-backtrace", + "esp-println", + "esp32c3-hal", +] + +[[package]] +name = "defmt" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2d011b2fee29fb7d659b83c43fce9a2cb4df453e16d441a51448e448f3f98" +dependencies = [ + "bitflags 1.3.2", + "defmt-macros", +] + +[[package]] +name = "defmt-macros" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54f0216f6c5acb5ae1a47050a6645024e6edafc2ee32d421955eccfef12ef92e" +dependencies = [ + "defmt-parser", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.42", +] + +[[package]] +name = "defmt-parser" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "269924c02afd7f94bc4cecbfa5c379f6ffcf9766b3408fe63d22c728654eccd0" +dependencies = [ + "thiserror", +] + +[[package]] +name = "embassy-executor" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94598b92a396f27bd34a4ce2648c35d5fec7c7157c1a4e3160167ca39c3e116c" +dependencies = [ + "critical-section", + "embassy-executor-macros", + "embassy-time", +] + +[[package]] +name = "embassy-executor-macros" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab0f725ba52827eb44be22c85c52614c7402045968b26349de7f9df8421f74f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.42", +] + +[[package]] +name = "embassy-time" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34a2fc78331899dc7ba8fbcae2fcac3f5cd5301c0717689c546af2ce4162d4e4" +dependencies = [ + "cfg-if", + "critical-section", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0-rc.2", + "embedded-hal-async", + "futures-util", + "heapless", +] + +[[package]] +name = "embedded-dma" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "994f7e5b5cb23521c22304927195f236813053eb9c065dd2226a32ba64695446" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "embedded-hal" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff" +dependencies = [ + "nb 0.1.3", + "void", +] + +[[package]] +name = "embedded-hal" +version = "1.0.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e57ec6ad0bc8eb967cf9c9f144177f5e8f2f6f02dad0b8b683f9f05f6b22def" + +[[package]] +name = "embedded-hal-async" +version = "1.0.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b5ad4a01f9cb38117ef85f5cd32176d63875e7eab99c5b60e8492bfdc16dd63" +dependencies = [ + "embedded-hal 1.0.0-rc.2", +] + +[[package]] +name = "enumset" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "226c0da7462c13fb57e5cc9e0dc8f0635e7d27f276a3a7fd30054647f669007d" +dependencies = [ + "enumset_derive", +] + +[[package]] +name = "enumset_derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08b6c6ab82d70f08844964ba10c7babb716de2ecaeab9be5717918a5177d3af" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.42", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "esp-backtrace" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b0597e7f5d09d1431fb5a788f6fd794a4e1d7de2179e165c868ddb2804c78c" +dependencies = [ + "defmt 0.3.5", + "esp-println", +] + +[[package]] +name = "esp-hal-common" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30e9f181669edeb35ef6d6c5518c9941900dbf2133348673eebb4b33fb73ac62" +dependencies = [ + "basic-toml", + "bitfield", + "bitflags 2.4.1", + "cfg-if", + "critical-section", + "embassy-executor", + "embedded-dma", + "embedded-hal 0.2.7", + "enumset", + "esp-hal-procmacros", + "esp-riscv-rt", + "esp32c3", + "fugit", + "heapless", + "nb 1.1.0", + "paste", + "portable-atomic", + "serde", + "strum", + "void", +] + +[[package]] +name = "esp-hal-procmacros" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d4614e76646736f8adf18133d82d51f0da2b8899f38efb0a703b996a252b15e" +dependencies = [ + "darling", + "litrs", + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.42", +] + +[[package]] +name = "esp-println" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4c46223e9f05304d2733f935bf3c50af108b2ca24ff53a7aba21584d5bbbb9" +dependencies = [ + "critical-section", + "defmt 0.3.5", + "log", +] + +[[package]] +name = "esp-riscv-rt" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df05a8021fb80398c592703d180a6c31ec1dc050a6fb5b64c48c34d93caebc7e" +dependencies = [ + "riscv", + "riscv-rt-macros", +] + +[[package]] +name = "esp32c3" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "398875eca3b0a51216110bd988bc72f79e564a0039fc93d81c10113c3e5f1a55" +dependencies = [ + "critical-section", + "vcell", +] + +[[package]] +name = "esp32c3-hal" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22309e9d09d5b8df55a4ad915ea06fcec7b953815184cabbf97b64adc4398279" +dependencies = [ + "cfg-if", + "esp-hal-common", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "fugit" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17186ad64927d5ac8f02c1e77ccefa08ccd9eaa314d5a4772278aa204a22f7e7" +dependencies = [ + "gcd", +] + +[[package]] +name = "futures-core" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" + +[[package]] +name = "futures-task" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" + +[[package]] +name = "futures-util" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "gcd" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "litrs" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.1.0", +] + +[[package]] +name = "nb" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + +[[package]] +name = "proc-macro-crate" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +dependencies = [ + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "riscv" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa3145d2fae3778b1e31ec2e827b228bdc6abd9b74bb5705ba46dcb82069bc4f" +dependencies = [ + "bit_field", + "critical-section", + "embedded-hal 0.2.7", +] + +[[package]] +name = "riscv-rt-macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38509d7b17c2f604ceab3e5ff8ac97bb8cd2f544688c512be75c715edaf4daf" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.42", +] + +[[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.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.42", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.42", +] + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" + +[[package]] +name = "toml_edit" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "vcell" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "winnow" +version = "0.5.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" +dependencies = [ + "memchr", +] diff --git a/intro/defmt/Cargo.toml b/intro/defmt/Cargo.toml new file mode 100644 index 0000000..3176f59 --- /dev/null +++ b/intro/defmt/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "defmt" +version = "0.1.0" +authors = ["Sergio Gasquez "] +edition = "2021" +license = "MIT OR Apache-2.0" + +[dependencies] +hal = { package = "esp32c3-hal", version = "0.14.0" } +esp-backtrace = { version = "0.10.0", features = ["esp32c3", "panic-handler", "exception-handler", "print-uart", "defmt-espflash"] } +esp-println = { version = "0.8.0", features = ["esp32c3", "defmt-espflash", "log"] } +defmt = "0.3.5" diff --git a/intro/defmt/examples/defmt.rs b/intro/defmt/examples/defmt.rs new file mode 100644 index 0000000..c5e9694 --- /dev/null +++ b/intro/defmt/examples/defmt.rs @@ -0,0 +1,29 @@ +#![no_std] +#![no_main] + +// ANCHOR: println_include +use esp_backtrace as _; +use esp_println as _; +// ANCHOR_END: println_include +use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay}; + +#[entry] +fn main() -> ! { + let peripherals = Peripherals::take(); + let system = peripherals.SYSTEM.split(); + let clocks = ClockControl::max(system.clock_control).freeze(); + let mut delay = Delay::new(&clocks); + + defmt::trace!("trace"); + defmt::debug!("debug"); + defmt::info!("info"); + defmt::warn!("warn"); + defmt::error!("error"); + + // panic!("Very useful panic message"); + + loop { + defmt::println!("Loop..."); + delay.delay_ms(500u32); + } +} diff --git a/intro/defmt/rust-toolchain.toml b/intro/defmt/rust-toolchain.toml new file mode 100644 index 0000000..804e8a7 --- /dev/null +++ b/intro/defmt/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly" +components = ["rust-src"] +targets = ["riscv32imc-unknown-none-elf"] + diff --git a/intro/defmt/src/main.rs b/intro/defmt/src/main.rs new file mode 100644 index 0000000..b6b5088 --- /dev/null +++ b/intro/defmt/src/main.rs @@ -0,0 +1,23 @@ +#![no_std] +#![no_main] + +// Build the `esp_println` and `esp_backtrace` libs + +use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay}; + +#[entry] +fn main() -> ! { + let peripherals = Peripherals::take(); + let system = peripherals.SYSTEM.split(); + let clocks = ClockControl::max(system.clock_control).freeze(); + let mut delay = Delay::new(&clocks); + + // Print a log or a message using defmt + + // Use a panic! macro to trigger a panic + + loop { + defmt::println!("Loop..."); + delay.delay_ms(500u32); + } +} diff --git a/intro/hello-world/.gitignore b/intro/hello-world/.gitignore deleted file mode 100644 index 73fab07..0000000 --- a/intro/hello-world/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb diff --git a/intro/http-client/.gitignore b/intro/http-client/.gitignore deleted file mode 100644 index 73fab07..0000000 --- a/intro/http-client/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb diff --git a/intro/panic/.gitignore b/intro/panic/.gitignore deleted file mode 100644 index 73fab07..0000000 --- a/intro/panic/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb