From c0cfccffc7c44c88cb9580b1496569d3e9de1848 Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Mon, 15 Nov 2021 14:37:19 -0500 Subject: Update toolchain and defmt versions. --- Cargo.lock | 316 +++++++++++++++++++++----------- examples/Cargo.toml | 13 +- examples/src/bin/ble_l2cap_central.rs | 2 +- examples/src/example_common.rs | 2 - nrf-softdevice-defmt-rtt/Cargo.toml | 2 +- nrf-softdevice-defmt-rtt/src/channel.rs | 116 ++++++++++++ nrf-softdevice-defmt-rtt/src/lib.rs | 187 +++++-------------- nrf-softdevice/Cargo.toml | 10 +- rust-toolchain.toml | 2 +- 9 files changed, 385 insertions(+), 265 deletions(-) create mode 100644 nrf-softdevice-defmt-rtt/src/channel.rs diff --git a/Cargo.lock b/Cargo.lock index 47f9d92..b70aafa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,11 +54,12 @@ dependencies = [ [[package]] name = "atomic-polyfill" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a93ba5d6053837dbb76fd0ae26fd4f0c1859a008a783b0ce072b797c07f0f27" +checksum = "e686d748538a32325b28d6411dd8a939e7ad5128e5d0023cc4fd3573db456042" dependencies = [ - "cortex-m 0.7.3", + "critical-section", + "riscv-target", ] [[package]] @@ -69,9 +70,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "az" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "822d7d63e0c0260a050f6b1f0d316f5c79b9eab830aca526ed904e1011bd64ca" +checksum = "9d6dff4a1892b54d70af377bf7a17064192e822865791d812957f21e3108c325" [[package]] name = "bare-metal" @@ -88,12 +89,24 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" +[[package]] +name = "bit_field" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bytemuck" version = "1.7.2" @@ -137,34 +150,13 @@ dependencies = [ "volatile-register", ] -[[package]] -name = "cortex-m-rt" -version = "0.6.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6d8353767db816419630a76d5f1ad5b09610d22b67ceb59647df6a8abc667f8" -dependencies = [ - "cortex-m-rt-macros 0.1.8", - "r0", -] - [[package]] name = "cortex-m-rt" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "069533b58e25b635fac881eb6556616bd8f83a3e0ffe2b4b9619289ed14d465e" dependencies = [ - "cortex-m-rt-macros 0.7.0", -] - -[[package]] -name = "cortex-m-rt-macros" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4717562afbba06e760d34451919f5c3bf3ac15c7bb897e8b04862a7428378647" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "cortex-m-rt-macros", ] [[package]] @@ -180,13 +172,14 @@ dependencies = [ [[package]] name = "critical-section" -version = "0.2.1" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c1ce814a497d4fbc869a34a0da005fbd712d7034e4a48ee91e7f3c795a8b17" +checksum = "01e191a5a6f6edad9b679777ef6b6c0f2bdd4a333f2ecb8f61c3e28109a03d70" dependencies = [ "bare-metal 1.0.0", "cfg-if", "cortex-m 0.7.3", + "riscv", ] [[package]] @@ -195,8 +188,18 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.10.2", + "darling_macro 0.10.2", +] + +[[package]] +name = "darling" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12" +dependencies = [ + "darling_core 0.13.0", + "darling_macro 0.13.0", ] [[package]] @@ -209,7 +212,21 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.9.3", + "syn", +] + +[[package]] +name = "darling_core" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", "syn", ] @@ -219,28 +236,40 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ - "darling_core", + "darling_core 0.10.2", + "quote", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" +dependencies = [ + "darling_core 0.13.0", "quote", "syn", ] [[package]] name = "defmt" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15fe96f5d208164afa70583ff8f062e7697cbbb0b98e5076fbf8ac6da9edff0f" +checksum = "62fb5df4d2b06a2dbf6ba26b49031f5f45f1aafdfca4b9259719466d362f34a0" dependencies = [ + "bitflags", "defmt-macros", - "semver 1.0.4", ] [[package]] name = "defmt-macros" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bd2c3949cb76c25f48c363e61b97f05b317efe3c12fa45d54a6599c3949c85e" +checksum = "dede7fc0d15f4b8e15f3f023aefe6806066d7eb382123981e106fba05b35c5a3" dependencies = [ "defmt-parser", + "proc-macro-error", "proc-macro2", "quote", "syn", @@ -248,9 +277,9 @@ dependencies = [ [[package]] name = "defmt-parser" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc621c2b4f5f5635e34021c38af2ccb0c1dae38ba11ebee25258de8bb1cee9fe" +checksum = "8d1ce010e1a51aef925c98f12ed81a4e0e96ce0185a87c33f1b3b9c8f20749c7" [[package]] name = "derivative" @@ -266,7 +295,7 @@ dependencies = [ [[package]] name = "embassy" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy#1e1cd0506aa655456d7cbf7d6915b46abf7829e5" +source = "git+https://github.com/embassy-rs/embassy#271881533e104d4f1f1225a6251da2eea8269470" dependencies = [ "atomic-polyfill", "cortex-m 0.7.3", @@ -276,25 +305,27 @@ dependencies = [ "embassy-traits", "embedded-hal", "futures", + "heapless", "pin-project", ] [[package]] name = "embassy-hal-common" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy#1e1cd0506aa655456d7cbf7d6915b46abf7829e5" +source = "git+https://github.com/embassy-rs/embassy#271881533e104d4f1f1225a6251da2eea8269470" dependencies = [ "cortex-m 0.7.3", "embassy", + "num-traits", "usb-device", ] [[package]] name = "embassy-macros" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy#1e1cd0506aa655456d7cbf7d6915b46abf7829e5" +source = "git+https://github.com/embassy-rs/embassy#271881533e104d4f1f1225a6251da2eea8269470" dependencies = [ - "darling", + "darling 0.13.0", "proc-macro2", "quote", "syn", @@ -303,10 +334,11 @@ dependencies = [ [[package]] name = "embassy-nrf" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy#1e1cd0506aa655456d7cbf7d6915b46abf7829e5" +source = "git+https://github.com/embassy-rs/embassy#271881533e104d4f1f1225a6251da2eea8269470" dependencies = [ + "cfg-if", "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "critical-section", "defmt", "embassy", @@ -314,6 +346,8 @@ dependencies = [ "embassy-macros", "embedded-dma", "embedded-hal", + "embedded-storage", + "fixed", "futures", "nrf52840-pac", "rand_core", @@ -322,7 +356,7 @@ dependencies = [ [[package]] name = "embassy-traits" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy#1e1cd0506aa655456d7cbf7d6915b46abf7829e5" +source = "git+https://github.com/embassy-rs/embassy#271881533e104d4f1f1225a6251da2eea8269470" dependencies = [ "defmt", "embedded-hal", @@ -347,11 +381,17 @@ dependencies = [ "void", ] +[[package]] +name = "embedded-storage" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "723dce4e9f25b6e6c5f35628e144794e5b459216ed7da97b7c4b66cdb3fa82ca" + [[package]] name = "fixed" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c97cabfe1ce0db024d64e9f688469e80a8e2b36cb792b09ba33e1ee8d21d00ae" +checksum = "6d333a26ec13a023c6dff4b7584de4d323cfee2e508f5dd2bbee6669e4f7efdf" dependencies = [ "az", "bytemuck", @@ -367,9 +407,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "futures" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adc00f486adfc9ce99f77d717836f0c5aa84965eb0b4f051f4e83f7cab53f8b" +checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" dependencies = [ "futures-channel", "futures-core", @@ -381,9 +421,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ed2411805f6e4e3d9bc904c95d5d423b89b3b25dc0250aa74729de20629ff9" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" dependencies = [ "futures-core", "futures-sink", @@ -391,33 +431,33 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af51b1b4a7fdff033703db39de8802c673eb91855f2e0d47dcf3bf2c0ef01f99" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" [[package]] name = "futures-io" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b0e06c393068f3a6ef246c75cdca793d6a46347e75286933e5e75fd2fd11582" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" [[package]] name = "futures-sink" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f30aaa67363d119812743aa5f33c201a7a66329f97d1a887022971feea4b53" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" [[package]] name = "futures-task" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe54a98670017f3be909561f6ad13e810d9a51f3f061b902062ca3da80799f2" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" [[package]] name = "futures-util" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67eb846bfd58e44a8481a00049e82c43e0ccb5d61f8dc071057cb19249dd4d78" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" dependencies = [ "autocfg", "futures-core", @@ -457,9 +497,9 @@ dependencies = [ [[package]] name = "half" -version = "1.7.1" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "hash32" @@ -472,12 +512,13 @@ dependencies = [ [[package]] name = "heapless" -version = "0.7.5" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50530280e9a947b192e3a30a9d7bcead527b22da30ff7cbd334233d820aaf82a" +checksum = "9c1ad878e07405df82b695089e63d278244344f80e764074d0bdfe99b89460f3" dependencies = [ "atomic-polyfill", "hash32", + "spin", "stable_deref_trait", ] @@ -499,6 +540,15 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "822add9edb1860698b79522510da17bef885171f75aa395cff099d770c609c24" +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -534,7 +584,7 @@ name = "nrf-softdevice" version = "0.1.0" dependencies = [ "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "critical-section", "defmt", "embassy", @@ -573,7 +623,7 @@ version = "0.1.0" dependencies = [ "alloc-cortex-m", "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "defmt", "embassy", "embassy-nrf", @@ -592,7 +642,7 @@ name = "nrf-softdevice-macro" version = "0.1.0" dependencies = [ "Inflector", - "darling", + "darling 0.10.2", "proc-macro2", "quote", "syn", @@ -630,7 +680,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4d2636b974cd6bc0b7f321e86fb51014fa9ab3e46156cb870db2335b5909713" dependencies = [ "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "vcell", ] @@ -641,7 +691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c6dd53b0fb1b7a5bde99de9d9f61f6714e7708e9eedaad9d7ed0534c452d1b" dependencies = [ "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "vcell", ] @@ -652,7 +702,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "088b039a15924edec8a97c185e3f45b2da203c0a90696f342f1a9cba736085bf" dependencies = [ "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "vcell", ] @@ -663,7 +713,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "438e40c226811dc90f0ce34b7466ae6f4a012018f31bd4afe9c3d37cd8407951" dependencies = [ "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "vcell", ] @@ -674,7 +724,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76f5dec47cf294f40a53cc62b6d9032a5ffae998c045c517cce5acaf482350d7" dependencies = [ "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "vcell", ] @@ -685,7 +735,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd69bdb25903e18e098c040ef31dc863814437af010dea8bd55aa31f686cb461" dependencies = [ "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "vcell", ] @@ -696,10 +746,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "209c71d29ce1c0e9249b59ffff1ff5035c68b65070bf4c1315767fa4c93103ac" dependencies = [ "cortex-m 0.7.3", - "cortex-m-rt 0.7.0", + "cortex-m-rt", "vcell", ] +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "num_enum" version = "0.5.4" @@ -723,12 +782,11 @@ dependencies = [ [[package]] name = "panic-probe" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45b5c81d6b51f415b3ba40b30dc598dfffb29ad4cf4a8815989754850ce6c0dc" +checksum = "3ab1f00eac22bd18f8e5cae9555f2820b3a0c166b5b556ee3e203746ea6dcf3a" dependencies = [ - "cortex-m 0.6.7", - "cortex-m-rt 0.6.14", + "cortex-m 0.7.3", "defmt", ] @@ -765,28 +823,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "proc-macro2" -version = "1.0.28" +name = "proc-macro-error" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "unicode-xid", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", ] [[package]] -name = "quote" -version = "1.0.9" +name = "proc-macro-error-attr" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", + "quote", + "version_check", ] [[package]] -name = "r0" -version = "0.2.2" +name = "proc-macro2" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +dependencies = [ + "proc-macro2", +] [[package]] name = "rand_core" @@ -811,15 +887,42 @@ version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +[[package]] +name = "riscv" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6907ccdd7a31012b70faf2af85cd9e5ba97657cc3987c4f13f8e4d2c2a088aba" +dependencies = [ + "bare-metal 1.0.0", + "bit_field", + "riscv-target", +] + +[[package]] +name = "riscv-target" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88aa938cda42a0cf62a20cfe8d139ff1af20c2e681212b5b34adb5a58333f222" +dependencies = [ + "lazy_static", + "regex", +] + [[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", + "semver", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "semver" version = "0.9.0" @@ -829,18 +932,21 @@ dependencies = [ "semver-parser", ] -[[package]] -name = "semver" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" - [[package]] name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "spin" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" +dependencies = [ + "lock_api", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -853,11 +959,17 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" -version = "1.0.75" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" dependencies = [ "proc-macro2", "quote", @@ -866,9 +978,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" +checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" [[package]] name = "unicode-xid" diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 5fac497..995b6f4 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -6,17 +6,10 @@ version = "0.1.0" [features] default = [ - "defmt-default", "ble-l2cap", "ble-gatt-server", "ble-gatt-client", ] -defmt-default = [] -defmt-trace = [] -defmt-debug = [] -defmt-info = [] -defmt-warn = [] -defmt-error = [] ble-l2cap = ["nrf-softdevice/ble-l2cap"] ble-gatt-server = ["nrf-softdevice/ble-gatt-server"] @@ -28,10 +21,10 @@ embassy-traits = { version = "0.1.0", features = ["defmt"]} embassy-nrf = { version = "0.1.0", features = [ "defmt", "nrf52840", "gpiote", "time-driver-rtc1" ]} cortex-m = { version = "0.7.2" } cortex-m-rt = "0.7.0" -defmt = { version = "0.2.0", features = ["alloc"] } +defmt = { version = "0.3", features = ["alloc"] } nrf-softdevice-defmt-rtt = { path = "../nrf-softdevice-defmt-rtt", version = "0.1.0" } -panic-probe = { version = "0.2.0", features= ["print-defmt"] } -nrf-softdevice = { version = "0.1.0", path = "../nrf-softdevice", features = ["defmt", "defmt-trace", "nrf52840", "s140", "ble-peripheral", "ble-central", "critical-section-impl"] } +panic-probe = { version = "0.3", features= ["print-defmt"] } +nrf-softdevice = { version = "0.1.0", path = "../nrf-softdevice", features = ["defmt", "nrf52840", "s140", "ble-peripheral", "ble-central", "critical-section-impl"] } nrf-softdevice-s140 = { version = "0.1.1", path = "../nrf-softdevice-s140" } futures = { version = "0.3.5", default-features = false } fixed = "1.2.0" diff --git a/examples/src/bin/ble_l2cap_central.rs b/examples/src/bin/ble_l2cap_central.rs index 1637cf5..4a1817e 100644 --- a/examples/src/bin/ble_l2cap_central.rs +++ b/examples/src/bin/ble_l2cap_central.rs @@ -13,7 +13,7 @@ use core::ptr::NonNull; use core::slice; use cortex_m_rt::entry; use defmt::info; -use defmt::*; +use defmt::{unreachable, *}; use embassy::executor::Executor; use embassy::util::Forever; diff --git a/examples/src/example_common.rs b/examples/src/example_common.rs index ba6eef0..f402f7f 100644 --- a/examples/src/example_common.rs +++ b/examples/src/example_common.rs @@ -20,8 +20,6 @@ fn alloc_error(_layout: Layout) -> ! { panic!("Alloc error"); } -const HEAP_SIZE: usize = 32 * 1024; // in bytes - defmt::timestamp! {"{=u64}", { static COUNT: AtomicUsize = AtomicUsize::new(0); // NOTE(no-CAS) `timestamps` runs with interrupts disabled diff --git a/nrf-softdevice-defmt-rtt/Cargo.toml b/nrf-softdevice-defmt-rtt/Cargo.toml index 5d071be..e847a72 100644 --- a/nrf-softdevice-defmt-rtt/Cargo.toml +++ b/nrf-softdevice-defmt-rtt/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/knurling-rs/defmt" version = "0.1.0" [dependencies] -defmt = { version = "0.2.0" } +defmt = { version = "0.3" } nrf-softdevice = { path = "../nrf-softdevice", version = "0.1.0" } cortex-m = "0.6.4" critical-section = { version = "0.2.1" } diff --git a/nrf-softdevice-defmt-rtt/src/channel.rs b/nrf-softdevice-defmt-rtt/src/channel.rs new file mode 100644 index 0000000..ebe44bf --- /dev/null +++ b/nrf-softdevice-defmt-rtt/src/channel.rs @@ -0,0 +1,116 @@ +use core::{ + ptr, + sync::atomic::{AtomicUsize, Ordering}, +}; + +use crate::{MODE_BLOCK_IF_FULL, MODE_MASK, SIZE}; + +#[repr(C)] +pub(crate) struct Channel { + pub name: *const u8, + pub buffer: *mut u8, + pub size: usize, + pub write: AtomicUsize, + pub read: AtomicUsize, + /// Channel properties. + /// + /// Currently, only the lowest 2 bits are used to set the channel mode (see constants below). + pub flags: AtomicUsize, +} + +impl Channel { + pub fn write_all(&self, mut bytes: &[u8]) { + // the host-connection-status is only modified after RAM initialization while the device is + // halted, so we only need to check it once before the write-loop + let write = match self.host_is_connected() { + true => Channel::blocking_write, + false => Channel::nonblocking_write, + }; + + while !bytes.is_empty() { + let consumed = write(self, bytes); + if consumed != 0 { + bytes = &bytes[consumed..]; + } + } + } + + fn blocking_write(&self, bytes: &[u8]) -> usize { + if bytes.is_empty() { + return 0; + } + + let read = self.read.load(Ordering::Relaxed); + let write = self.write.load(Ordering::Acquire); + let available = if read > write { + read - write - 1 + } else if read == 0 { + SIZE - write - 1 + } else { + SIZE - write + }; + + if available == 0 { + return 0; + } + + let cursor = write; + let len = bytes.len().min(available); + + unsafe { + if cursor + len > SIZE { + // split memcpy + let pivot = SIZE - cursor; + ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), pivot); + ptr::copy_nonoverlapping(bytes.as_ptr().add(pivot), self.buffer, len - pivot); + } else { + // single memcpy + ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), len); + } + } + self.write + .store(write.wrapping_add(len) % SIZE, Ordering::Release); + + len + } + + fn nonblocking_write(&self, bytes: &[u8]) -> usize { + let write = self.write.load(Ordering::Acquire); + let cursor = write; + // NOTE truncate at SIZE to avoid more than one "wrap-around" in a single `write` call + let len = bytes.len().min(SIZE); + + unsafe { + if cursor + len > SIZE { + // split memcpy + let pivot = SIZE - cursor; + ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), pivot); + ptr::copy_nonoverlapping(bytes.as_ptr().add(pivot), self.buffer, len - pivot); + } else { + // single memcpy + ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), len); + } + } + self.write + .store(write.wrapping_add(len) % SIZE, Ordering::Release); + + len + } + + pub fn flush(&self) { + // return early, if host is disconnected + if !self.host_is_connected() { + return; + } + + // busy wait, until the read- catches up with the write-pointer + let read = || self.read.load(Ordering::Relaxed); + let write = || self.write.load(Ordering::Relaxed); + while read() != write() {} + } + + fn host_is_connected(&self) -> bool { + // we assume that a host is connected if we are in blocking-mode. this is what probe-run does. + self.flags.load(Ordering::Relaxed) & MODE_MASK == MODE_BLOCK_IF_FULL + } +} diff --git a/nrf-softdevice-defmt-rtt/src/lib.rs b/nrf-softdevice-defmt-rtt/src/lib.rs index 0d2cf95..90d4d6f 100644 --- a/nrf-softdevice-defmt-rtt/src/lib.rs +++ b/nrf-softdevice-defmt-rtt/src/lib.rs @@ -8,51 +8,69 @@ //! // src/main.rs or src/bin/my-app.rs //! use defmt_rtt as _; //! ``` +//! +//! # Blocking/Non-blocking +//! +//! `probe-run` puts RTT into blocking-mode, to avoid losing data. +//! +//! As an effect this implementation may block forever if `probe-run` disconnects on runtime. This +//! is because the RTT buffer will fill up and writing will eventually halt the program execution. +//! +//! `defmt::flush` would also block forever in that case. #![no_std] -use core::{ - ptr, - ptr::NonNull, - sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering}, -}; +mod channel; -// TODO make configurable -// NOTE use a power of 2 for best performance -const SIZE: usize = 1024; +use core::sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering}; + +use crate::channel::Channel; #[defmt::global_logger] struct Logger; -impl defmt::Write for Logger { - fn write(&mut self, bytes: &[u8]) { - unsafe { handle().write_all(bytes) } - } -} - +/// Global logger lock. static TAKEN: AtomicBool = AtomicBool::new(false); static INTERRUPTS_TOKEN: AtomicU8 = AtomicU8::new(0); +static mut ENCODER: defmt::Encoder = defmt::Encoder::new(); unsafe impl defmt::Logger for Logger { - fn acquire() -> Option> { + fn acquire() { let token = unsafe { critical_section::acquire() }; + if !TAKEN.load(Ordering::Relaxed) { // no need for CAS because interrupts are disabled TAKEN.store(true, Ordering::Relaxed); INTERRUPTS_TOKEN.store(token, Ordering::Relaxed); - Some(NonNull::from(&Logger as &dyn defmt::Write)) + // safety: accessing the `static mut` is OK because we have disabled interrupts. + unsafe { ENCODER.start_frame(do_write) } } else { unsafe { critical_section::release(token) }; - None } } - unsafe fn release(_: NonNull) { + unsafe fn flush() { + // SAFETY: if we get here, the global logger mutex is currently acquired + handle().flush(); + } + + unsafe fn release() { + // safety: accessing the `static mut` is OK because we have disabled interrupts. + ENCODER.end_frame(do_write); TAKEN.store(false, Ordering::Relaxed); critical_section::release(INTERRUPTS_TOKEN.load(Ordering::Relaxed)); } + + unsafe fn write(bytes: &[u8]) { + // safety: accessing the `static mut` is OK because we have disabled interrupts. + ENCODER.write(bytes, do_write); + } +} + +fn do_write(bytes: &[u8]) { + unsafe { handle().write_all(bytes) } } #[repr(C)] @@ -63,127 +81,15 @@ struct Header { up_channel: Channel, } -#[repr(C)] -struct Channel { - name: *const u8, - buffer: *mut u8, - size: usize, - write: AtomicUsize, - read: AtomicUsize, - flags: AtomicUsize, -} +const MODE_MASK: usize = 0b11; +/// Block the application if the RTT buffer is full, wait for the host to read data. +const MODE_BLOCK_IF_FULL: usize = 2; +/// Don't block if the RTT buffer is full. Truncate data to output as much as fits. +const MODE_NON_BLOCKING_TRIM: usize = 1; -const BLOCK_IF_FULL: usize = 2; -const NOBLOCK_TRIM: usize = 1; - -impl Channel { - fn write_all(&self, mut bytes: &[u8]) { - // NOTE `flags` is modified by the host after RAM initialization while the device is halted - // it cannot otherwise be modified so we don't need to check its state more often than - // just here - if self.flags.load(Ordering::Relaxed) == BLOCK_IF_FULL { - while !bytes.is_empty() { - let consumed = self.blocking_write(bytes); - if consumed != 0 { - bytes = &bytes[consumed..]; - } - } - } else { - while !bytes.is_empty() { - let consumed = self.nonblocking_write(bytes); - if consumed != 0 { - bytes = &bytes[consumed..]; - } - } - } - } - - fn blocking_write(&self, bytes: &[u8]) -> usize { - if bytes.is_empty() { - return 0; - } - - let read = self.read.load(Ordering::Relaxed); - let write = self.write.load(Ordering::Acquire); - let available = if read > write { - read - write - 1 - } else if read == 0 { - SIZE - write - 1 - } else { - SIZE - write - }; - - if available == 0 { - return 0; - } - - let cursor = write; - let len = bytes.len().min(available); - - unsafe { - if cursor + len > SIZE { - // split memcpy - let pivot = SIZE - cursor; - ptr::copy_nonoverlapping( - bytes.as_ptr(), - self.buffer.add(cursor.into()), - pivot.into(), - ); - ptr::copy_nonoverlapping( - bytes.as_ptr().add(pivot.into()), - self.buffer, - (len - pivot).into(), - ); - } else { - // single memcpy - ptr::copy_nonoverlapping( - bytes.as_ptr(), - self.buffer.add(cursor.into()), - len.into(), - ); - } - } - self.write - .store(write.wrapping_add(len) % SIZE, Ordering::Release); - - len - } - - fn nonblocking_write(&self, bytes: &[u8]) -> usize { - let write = self.write.load(Ordering::Acquire); - let cursor = write; - // NOTE truncate at SIZE to avoid more than one "wrap-around" in a single `write` call - let len = bytes.len().min(SIZE); - - unsafe { - if cursor + len > SIZE { - // split memcpy - let pivot = SIZE - cursor; - ptr::copy_nonoverlapping( - bytes.as_ptr(), - self.buffer.add(cursor.into()), - pivot.into(), - ); - ptr::copy_nonoverlapping( - bytes.as_ptr().add(pivot.into()), - self.buffer, - (len - pivot).into(), - ); - } else { - // single memcpy - ptr::copy_nonoverlapping( - bytes.as_ptr(), - self.buffer.add(cursor.into()), - len.into(), - ); - } - } - self.write - .store(write.wrapping_add(len) % SIZE, Ordering::Release); - - len - } -} +// TODO make configurable +// NOTE use a power of 2 for best performance +const SIZE: usize = 1024; // make sure we only get shared references to the header/channel (avoid UB) /// # Safety @@ -205,11 +111,12 @@ unsafe fn handle() -> &'static Channel { size: SIZE, write: AtomicUsize::new(0), read: AtomicUsize::new(0), - flags: AtomicUsize::new(NOBLOCK_TRIM), + flags: AtomicUsize::new(MODE_NON_BLOCKING_TRIM), }, }; - #[link_section = ".uninit.defmt-rtt.BUFFER"] + #[cfg_attr(target_os = "macos", link_section = ".uninit,defmt-rtt.BUFFER")] + #[cfg_attr(not(target_os = "macos"), link_section = ".uninit.defmt-rtt.BUFFER")] static mut BUFFER: [u8; SIZE] = [0; SIZE]; static NAME: &[u8] = b"defmt\0"; diff --git a/nrf-softdevice/Cargo.toml b/nrf-softdevice/Cargo.toml index 143e1d0..27ebf35 100644 --- a/nrf-softdevice/Cargo.toml +++ b/nrf-softdevice/Cargo.toml @@ -5,12 +5,6 @@ authors = ["Dario Nieuwenhuis "] edition = "2018" [features] -defmt-default = [] -defmt-trace = [] -defmt-debug = [] -defmt-info = [] -defmt-warn = [] -defmt-error = [] nrf52805 = ["nrf52805-pac"] nrf52810 = ["nrf52810-pac"] @@ -36,7 +30,7 @@ ble-gatt-client = ["ble-gatt"] critical-section-impl = ["critical-section/custom-impl"] [dependencies] -defmt = { version = "0.2.0", optional = true } +defmt = { version = "0.3", optional = true } log = { version = "0.4.11", optional = true } critical-section = { version = "0.2.1" } @@ -65,4 +59,4 @@ nrf-softdevice-macro = { version = "0.1.0", path = "../nrf-softdevice-macro" } [package.metadata.docs.rs] targets = ["thumbv7em-none-eabihf"] -features = ["nrf52840", "s140", "ble-central", "ble-peripheral", "ble-l2cap", "ble-gatt-server", "ble-gatt-client"] \ No newline at end of file +features = ["nrf52840", "s140", "ble-central", "ble-peripheral", "ble-l2cap", "ble-gatt-server", "ble-gatt-client"] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d1dcc3a..ed08935 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,6 +1,6 @@ # Before upgrading check that everything is available on all tier1 targets here: # https://rust-lang.github.io/rustup-components-history [toolchain] -channel = "nightly-2021-08-18" +channel = "nightly-2021-10-16" components = ["rust-src", "rustfmt"] targets = ["thumbv7em-none-eabihf"] -- cgit v1.2.3