diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7438b99..691bfb0d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,11 +25,11 @@ jobs: - name: Build book-and-slides run: | - ./training-slides/build.sh + cd ./training-slides && ./build.sh - name: Build example code run: | - ./example-code/build.sh + cd ./example-code && ./build.sh - name: Assemble Artifacts run: | @@ -37,6 +37,7 @@ jobs: mkdir -p ./rust-training-${{ env.slug }} mv ./training-slides/slides ./rust-training-${{ env.slug }}/training-slides-presentation mv ./training-slides/book ./rust-training-${{ env.slug }}/training-slides-book + cp -r ./example-code ./rust-training-${{ env.slug }} echo "Compressing ./rust-training-${{ env.slug }}.zip..." zip -r ./rust-training-${{ env.slug }}.zip ./rust-training-${{ env.slug }} diff --git a/example-code/build.sh b/example-code/build.sh index ae3b960b..6c5698d9 100755 --- a/example-code/build.sh +++ b/example-code/build.sh @@ -2,9 +2,15 @@ set -euo pipefail -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - # Check the example code -cargo build --all --manifest-path ${SCRIPT_DIR}/Cargo.toml +pushd ./native +cargo build --all +popd # And the C based example -make -C ${SCRIPT_DIR}/ffi/use-rust-in-c +pushd native/ffi/use-rust-in-c +make +popd +# And the nRF52 examples +pushd ./nrf52/bsp_demo +cargo build +popd diff --git a/example-code/Cargo.lock b/example-code/native/Cargo.lock similarity index 100% rename from example-code/Cargo.lock rename to example-code/native/Cargo.lock diff --git a/example-code/Cargo.toml b/example-code/native/Cargo.toml similarity index 81% rename from example-code/Cargo.toml rename to example-code/native/Cargo.toml index d5b4fec1..2e1b690a 100644 --- a/example-code/Cargo.toml +++ b/example-code/native/Cargo.toml @@ -1,2 +1,3 @@ [workspace] members = ["ffi/use-c-in-rust", "ffi/use-rust-in-c"] +resolver = "2" diff --git a/example-code/ffi/use-c-in-rust/Cargo.lock b/example-code/native/ffi/use-c-in-rust/Cargo.lock similarity index 100% rename from example-code/ffi/use-c-in-rust/Cargo.lock rename to example-code/native/ffi/use-c-in-rust/Cargo.lock diff --git a/example-code/ffi/use-c-in-rust/Cargo.toml b/example-code/native/ffi/use-c-in-rust/Cargo.toml similarity index 100% rename from example-code/ffi/use-c-in-rust/Cargo.toml rename to example-code/native/ffi/use-c-in-rust/Cargo.toml diff --git a/example-code/ffi/use-c-in-rust/build.rs b/example-code/native/ffi/use-c-in-rust/build.rs similarity index 100% rename from example-code/ffi/use-c-in-rust/build.rs rename to example-code/native/ffi/use-c-in-rust/build.rs diff --git a/example-code/ffi/use-c-in-rust/src/cool_library.c b/example-code/native/ffi/use-c-in-rust/src/cool_library.c similarity index 100% rename from example-code/ffi/use-c-in-rust/src/cool_library.c rename to example-code/native/ffi/use-c-in-rust/src/cool_library.c diff --git a/example-code/ffi/use-c-in-rust/src/main.rs b/example-code/native/ffi/use-c-in-rust/src/main.rs similarity index 100% rename from example-code/ffi/use-c-in-rust/src/main.rs rename to example-code/native/ffi/use-c-in-rust/src/main.rs diff --git a/example-code/ffi/use-rust-in-c/.gitignore b/example-code/native/ffi/use-rust-in-c/.gitignore similarity index 100% rename from example-code/ffi/use-rust-in-c/.gitignore rename to example-code/native/ffi/use-rust-in-c/.gitignore diff --git a/example-code/ffi/use-rust-in-c/Cargo.lock b/example-code/native/ffi/use-rust-in-c/Cargo.lock similarity index 100% rename from example-code/ffi/use-rust-in-c/Cargo.lock rename to example-code/native/ffi/use-rust-in-c/Cargo.lock diff --git a/example-code/ffi/use-rust-in-c/Cargo.toml b/example-code/native/ffi/use-rust-in-c/Cargo.toml similarity index 100% rename from example-code/ffi/use-rust-in-c/Cargo.toml rename to example-code/native/ffi/use-rust-in-c/Cargo.toml diff --git a/example-code/ffi/use-rust-in-c/Makefile b/example-code/native/ffi/use-rust-in-c/Makefile similarity index 100% rename from example-code/ffi/use-rust-in-c/Makefile rename to example-code/native/ffi/use-rust-in-c/Makefile diff --git a/example-code/ffi/use-rust-in-c/example.c b/example-code/native/ffi/use-rust-in-c/example.c similarity index 100% rename from example-code/ffi/use-rust-in-c/example.c rename to example-code/native/ffi/use-rust-in-c/example.c diff --git a/example-code/ffi/use-rust-in-c/example.h b/example-code/native/ffi/use-rust-in-c/example.h similarity index 100% rename from example-code/ffi/use-rust-in-c/example.h rename to example-code/native/ffi/use-rust-in-c/example.h diff --git a/example-code/ffi/use-rust-in-c/src/lib.rs b/example-code/native/ffi/use-rust-in-c/src/lib.rs similarity index 100% rename from example-code/ffi/use-rust-in-c/src/lib.rs rename to example-code/native/ffi/use-rust-in-c/src/lib.rs diff --git a/example-code/nrf52/bsp_demo/.cargo/config.toml b/example-code/nrf52/bsp_demo/.cargo/config.toml new file mode 100644 index 00000000..5c44e4ac --- /dev/null +++ b/example-code/nrf52/bsp_demo/.cargo/config.toml @@ -0,0 +1,8 @@ +[build] +target = "thumbv7em-none-eabihf" + +[target.thumbv7em-none-eabihf] +runner = "probe-run --chip nRF52840_xxAA" +rustflags = [ + "-C", "link-arg=-Tlink.x", +] diff --git a/example-code/nrf52/bsp_demo/Cargo.lock b/example-code/nrf52/bsp_demo/Cargo.lock new file mode 100644 index 00000000..1b6ae446 --- /dev/null +++ b/example-code/nrf52/bsp_demo/Cargo.lock @@ -0,0 +1,437 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aligned" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a785a543aea40f5e4e2e93bb2655d31bc21bb391fff65697150973e383f16bb" +dependencies = [ + "as-slice", +] + +[[package]] +name = "as-slice" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45403b49e3954a4b8428a0ac21a4b7afadccf92bfd96273f1a58cd4812496ae0" +dependencies = [ + "generic-array 0.12.4", + "generic-array 0.13.3", + "generic-array 0.14.7", + "stable_deref_trait", +] + +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + +[[package]] +name = "bare-metal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version 0.2.3", +] + +[[package]] +name = "bare-metal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + +[[package]] +name = "bsp_demo" +version = "0.1.0" +dependencies = [ + "cortex-m 0.6.7", + "cortex-m-rt", + "nrf52840-dk-bsp", +] + +[[package]] +name = "bytemuck" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" + +[[package]] +name = "cast" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" +dependencies = [ + "rustc_version 0.4.0", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cortex-m" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9075300b07c6a56263b9b582c214d0ff037b00d45ec9fde1cc711490c56f1bb9" +dependencies = [ + "aligned", + "bare-metal 0.2.5", + "bitfield", + "cortex-m 0.7.7", + "volatile-register", +] + +[[package]] +name = "cortex-m" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" +dependencies = [ + "bare-metal 0.2.5", + "bitfield", + "embedded-hal", + "volatile-register", +] + +[[package]] +name = "cortex-m-rt" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "454f278bf469e2de0a4d22ea019d169d8944f86957c8207a39e3f66c32be2fc6" +dependencies = [ + "cortex-m-rt-macros", + "r0", +] + +[[package]] +name = "cortex-m-rt-macros" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3aa52243e26f5922fa522b0814019e0c98fc567e2756d715dce7ad7a81f49" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "critical-section" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1706d332edc22aef4d9f23a6bb1c92360a403013c291af51247a737472dcae6" +dependencies = [ + "bare-metal 1.0.0", + "critical-section 1.1.2", +] + +[[package]] +name = "critical-section" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "embedded-dma" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c8c02e4347a0267ca60813c952017f4c5948c232474c6010a381a337f1bda4" +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-storage" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57bc460456ce2c829a36ff3bf0cf3d24190557747667e8ff51f31b9291c4f15" + +[[package]] +name = "fixed" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79386fdcec5e0fde91b1a6a5bcd89677d1f9304f7f986b154a1b9109038854d9" +dependencies = [ + "az", + "bytemuck", + "half", + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f797e67af32588215eaaab8327027ee8e71b9dd0b2b26996aedf20c030fce309" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "half" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872" +dependencies = [ + "cfg-if", + "crunchy", +] + +[[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 = "nrf-hal-common" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927d948c3642ccd6228656760df3ec590ec2c04fa5f4a9b414b23f85540de512" +dependencies = [ + "cast", + "cfg-if", + "cortex-m 0.7.7", + "embedded-dma", + "embedded-hal", + "embedded-storage", + "fixed", + "nb 1.1.0", + "nrf-usbd", + "nrf52840-pac", + "rand_core", + "void", +] + +[[package]] +name = "nrf-usbd" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "640e88d4c108743c667f03320d0c9ab24a20f183a7a1b18bde7891ee13fd92c5" +dependencies = [ + "bare-metal 1.0.0", + "cortex-m 0.7.7", + "critical-section 0.2.8", + "usb-device", + "vcell", +] + +[[package]] +name = "nrf52840-dk-bsp" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35ecc120bcf72945d249b0f75c740f658b79502202ffd2d45fd29b9ecf6084" +dependencies = [ + "cortex-m 0.7.7", + "embedded-hal", + "nrf52840-hal", +] + +[[package]] +name = "nrf52840-hal" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291537191c37e45acdf875ec3a26ff4093cb44b78636b0122401bc8068d469a9" +dependencies = [ + "embedded-hal", + "nrf-hal-common", + "nrf52840-pac", +] + +[[package]] +name = "nrf52840-pac" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b780a5afd2621774652f28c82837f6aa6d19cf0ad71c734fc1fe53298a2d73" +dependencies = [ + "bare-metal 0.2.5", + "cortex-m 0.6.7", + "cortex-m-rt", + "vcell", +] + +[[package]] +name = "proc-macro2" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +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 = "r0" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[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.18", +] + +[[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.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[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 = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "usb-device" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" + +[[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 = "volatile-register" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee8f19f9d74293faf70901bc20ad067dc1ad390d2cbf1e3f75f721ffee908b6" +dependencies = [ + "vcell", +] diff --git a/example-code/nrf52/bsp_demo/Cargo.toml b/example-code/nrf52/bsp_demo/Cargo.toml new file mode 100644 index 00000000..cd2e7cef --- /dev/null +++ b/example-code/nrf52/bsp_demo/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "bsp_demo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +cortex-m-rt = "0.6" +cortex-m = "0.6" +nrf52840-dk-bsp = { version = "0.2.0", features = [ "rt" ] } diff --git a/example-code/nrf52/bsp_demo/src/main.rs b/example-code/nrf52/bsp_demo/src/main.rs new file mode 100644 index 00000000..3a6a01f9 --- /dev/null +++ b/example-code/nrf52/bsp_demo/src/main.rs @@ -0,0 +1,25 @@ +#![no_std] +#![no_main] + +use nrf52840_dk_bsp::Board; +use cortex_m_rt::entry; +use core::fmt::Write; + +#[entry] +fn main() -> ! { + let mut nrf52 = Board::take().unwrap(); + loop { + writeln!(nrf52.cdc, "On!").unwrap(); + nrf52.leds.led_2.enable(); + writeln!(nrf52.cdc, "Off!").unwrap(); + nrf52.leds.led_2.disable(); + } +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop { + cortex_m::asm::udf(); + } +} + diff --git a/training-slides/src/SUMMARY.md b/training-slides/src/SUMMARY.md index 4cc55045..4a1c1839 100644 --- a/training-slides/src/SUMMARY.md +++ b/training-slides/src/SUMMARY.md @@ -78,6 +78,7 @@ Topics about using Rust on ARM Cortex-M Microcontrollers (and similar). Requires * [PACs and svd2rust](./pac-svd2rust.md) * [Writing Drivers](./writing-drivers.md) * [The Embedded HAL and its implementations](./embedded-hals.md) +* [Board Support Crates](./board-support.md) * [Using RTIC v1 (TBC)](./rtic-v1.md) # Ferrocene diff --git a/training-slides/src/board-support.md b/training-slides/src/board-support.md new file mode 100644 index 00000000..91946c66 --- /dev/null +++ b/training-slides/src/board-support.md @@ -0,0 +1,82 @@ +# Board Support Crates + +## Using a 'normal' PC + +* Did you tell your PC it had a mouse plugged in? +* Did you tell it what I/O address the video card was located at? +* No! It auto-discovers all of these things. + * USB, PCI-Express, SATA all have "plug-and-play" + +## Using an Embedded System + +* There is (almost always) no plug-and-play +* Your MCU can put different functions (UART, SPI, etc) on different pins +* The choice of which function goes on which pin was decided by the PCB designer +* You now have to tell the software how the PCB was laid out + * i.e UART0 TX is on Port 0, Pin 13 + +## A Board Support Crate + +* You can wrap this up into a *Board Support Crate* +* Especially useful if you are using a widely available dev-kit + * e.g. the nRF52840-DK, or the STM32 Discovery +* Still useful if the board design is an in-house one-off +* Create the drivers and does the pin assignments for you +* Helps make your application portable across different boards + +## Using a Board Support Crate + +[Link](../../example-code/nrf52/bsp_demo/) + +```rust [] ignore +#[entry] +fn main() -> ! { + let mut nrf52 = Board::take().unwrap(); + loop { + writeln!(nrf52.cdc, "On!").unwrap(); + nrf52.leds.led_2.enable(); + writeln!(nrf52.cdc, "Off!").unwrap(); + nrf52.leds.led_2.disable(); + } +} +``` + +Note: + +We don't have to configure the LED pins as outputs. We don't have to configure +the UART pins. The Board Support Crate did it all for us. + +## Making a Board Support Crate + +```rust [] ignore +pub struct Board { + /// The nRF52's pins which are not otherwise occupied on the nRF52840-DK + pub pins: Pins, + /// The nRF52840-DK UART which is wired to the virtual USB CDC port + pub cdc: Uarte, + /// The LEDs on the nRF52840-DK board + pub leds: Leds, + ... + /// nRF52 peripheral: PWM0 + pub PWM0: nrf52::PWM0, + ... +} + +impl Board { + fn take() -> Option { todo!() } + fn new(cp: CorePeripherals, p: Peripherals) -> Self { todo!() } +} +``` + +Note: + +Because constructing the `Board` struct consumed *all* the peripherals from the +PAC, it's important to re-export the ones the BSC didn't use so that +applications can construct their own drivers using them,. + +## More things to consider + +* Does the MCU start-up on a slow internal oscillator? +* Are there jumpers to control routing on the board? +* SD Cards: should you pick a driver, or let them choose? +* Radios: same question!