initial commit
This commit is contained in:
commit
2ec6d250fe
9 changed files with 1038 additions and 0 deletions
8
.cargo/config.toml
Normal file
8
.cargo/config.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# [target.thumbv7em-none-eabihf]
|
||||||
|
# runner = "probe-rs run --chip STM32L476RGTx"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
target = "thumbv6m-none-eabi"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
DEFMT_LOG = "trace"
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
*~
|
||||||
|
\#*#
|
||||||
|
.#*#
|
||||||
|
|
||||||
|
target/
|
635
Cargo.lock
generated
Normal file
635
Cargo.lock
generated
Normal file
|
@ -0,0 +1,635 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bare-metal"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
|
||||||
|
dependencies = [
|
||||||
|
"rustc_version",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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.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 = "bxcan"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40ac3d0c0a542d0ab5521211f873f62706a7136df415676f676d347e5a41dd80"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"embedded-hal 0.2.7",
|
||||||
|
"nb 1.1.0",
|
||||||
|
"vcell",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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 = "cortex-m"
|
||||||
|
version = "0.7.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9"
|
||||||
|
dependencies = [
|
||||||
|
"bare-metal",
|
||||||
|
"bitfield",
|
||||||
|
"critical-section",
|
||||||
|
"embedded-hal 0.2.7",
|
||||||
|
"volatile-register",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cortex-m-rt"
|
||||||
|
version = "0.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee84e813d593101b1723e13ec38b6ab6abbdbaaa4546553f5395ed274079ddb1"
|
||||||
|
dependencies = [
|
||||||
|
"cortex-m-rt-macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cortex-m-rt-macros"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0f6f3e36f203cfedbc78b357fb28730aa2c6dc1ab060ee5c2405e843988d3c7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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.48",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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.48",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "document-features"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ef5282ad69563b5fc40319526ba27e0e7363d552a896f0297d54f767717f9b95"
|
||||||
|
dependencies = [
|
||||||
|
"litrs",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-embedded-hal"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
dependencies = [
|
||||||
|
"embassy-futures",
|
||||||
|
"embassy-sync",
|
||||||
|
"embassy-time",
|
||||||
|
"embedded-hal 0.2.7",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
"embedded-hal-async",
|
||||||
|
"embedded-storage",
|
||||||
|
"embedded-storage-async",
|
||||||
|
"nb 1.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-executor"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
dependencies = [
|
||||||
|
"cortex-m",
|
||||||
|
"critical-section",
|
||||||
|
"document-features",
|
||||||
|
"embassy-executor-macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-executor-macros"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
dependencies = [
|
||||||
|
"darling",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.48",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-futures"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-hal-internal"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
dependencies = [
|
||||||
|
"cortex-m",
|
||||||
|
"critical-section",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-net-driver"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-stm32"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
dependencies = [
|
||||||
|
"bit_field",
|
||||||
|
"bxcan",
|
||||||
|
"cfg-if",
|
||||||
|
"cortex-m",
|
||||||
|
"cortex-m-rt",
|
||||||
|
"critical-section",
|
||||||
|
"document-features",
|
||||||
|
"embassy-embedded-hal",
|
||||||
|
"embassy-futures",
|
||||||
|
"embassy-hal-internal",
|
||||||
|
"embassy-net-driver",
|
||||||
|
"embassy-sync",
|
||||||
|
"embassy-time",
|
||||||
|
"embassy-usb-driver",
|
||||||
|
"embedded-hal 0.2.7",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
"embedded-hal-async",
|
||||||
|
"embedded-hal-nb",
|
||||||
|
"embedded-io",
|
||||||
|
"embedded-io-async",
|
||||||
|
"embedded-storage",
|
||||||
|
"embedded-storage-async",
|
||||||
|
"futures",
|
||||||
|
"nb 1.1.0",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rand_core",
|
||||||
|
"sdio-host",
|
||||||
|
"stm32-fmc",
|
||||||
|
"stm32-metapac",
|
||||||
|
"vcell",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-sync"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"critical-section",
|
||||||
|
"embedded-io-async",
|
||||||
|
"futures-util",
|
||||||
|
"heapless",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-time"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"critical-section",
|
||||||
|
"document-features",
|
||||||
|
"embedded-hal 0.2.7",
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
"embedded-hal-async",
|
||||||
|
"futures-util",
|
||||||
|
"heapless",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embassy-usb-driver"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/embassy?rev=3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885#3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
|
||||||
|
[[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"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-hal-async"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-hal-nb"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-hal 1.0.0",
|
||||||
|
"nb 1.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-io"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-io-async"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-io",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-storage"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-storage-async"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1763775e2323b7d5f0aa6090657f5e21cfa02ede71f5dc40eead06d64dcd15cc"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-storage",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fnv"
|
||||||
|
version = "1.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-channel"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-core"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.48",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-sink"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-task"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-util"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-macro",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"pin-project-lite",
|
||||||
|
"pin-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hash32"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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 = "ident_case"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "litrs"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
|
||||||
|
|
||||||
|
[[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 = "num-traits"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "panic-halt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
|
||||||
|
|
||||||
|
[[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 = "proc-macro2"
|
||||||
|
version = "1.0.76"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sdio-host"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f93c025f9cfe4c388c328ece47d11a54a823da3b5ad0370b22d95ad47137f85a"
|
||||||
|
|
||||||
|
[[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-parser"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spidump"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"cortex-m",
|
||||||
|
"cortex-m-rt",
|
||||||
|
"embassy-executor",
|
||||||
|
"embassy-futures",
|
||||||
|
"embassy-stm32",
|
||||||
|
"embassy-sync",
|
||||||
|
"embassy-time",
|
||||||
|
"panic-halt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "stable_deref_trait"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "stm32-fmc"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "830ed60f33e6194ecb377f5d6ab765dc0e37e7b65e765f1fa87df13336658d63"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-hal 0.2.7",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "stm32-metapac"
|
||||||
|
version = "14.0.0"
|
||||||
|
source = "git+https://github.com/embassy-rs/stm32-data-generated?tag=stm32-data-656ecf6714fa34fdfb3b3e2f2cd034bffed3f303#40f18bcbe50d1d4106805b14004b81a39371e7c7"
|
||||||
|
dependencies = [
|
||||||
|
"cortex-m",
|
||||||
|
"cortex-m-rt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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.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.48"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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 = "void"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "volatile-register"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de437e2a6208b014ab52972a27e59b33fa2920d3e00fe05026167a1c509d19cc"
|
||||||
|
dependencies = [
|
||||||
|
"vcell",
|
||||||
|
]
|
33
Cargo.toml
Normal file
33
Cargo.toml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
[package]
|
||||||
|
name = "spidump"
|
||||||
|
version = "0.0.0"
|
||||||
|
publish = false
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
|
||||||
|
cortex-m-rt = "0.7.3"
|
||||||
|
panic-halt = "0.2"
|
||||||
|
|
||||||
|
[dependencies.embassy-futures]
|
||||||
|
git = "https://github.com/embassy-rs/embassy"
|
||||||
|
rev = "3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
|
||||||
|
[dependencies.embassy-executor]
|
||||||
|
git = "https://github.com/embassy-rs/embassy"
|
||||||
|
rev = "3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
features = ["arch-cortex-m", "executor-thread"]
|
||||||
|
|
||||||
|
[dependencies.embassy-time]
|
||||||
|
git = "https://github.com/embassy-rs/embassy"
|
||||||
|
rev = "3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
features = ["generic-queue"]
|
||||||
|
|
||||||
|
[dependencies.embassy-stm32]
|
||||||
|
git = "https://github.com/embassy-rs/embassy"
|
||||||
|
rev = "3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
||||||
|
features = ["exti", "stm32f103c8", "time", "time-driver-tim2", "unstable-pac"]
|
||||||
|
|
||||||
|
[dependencies.embassy-sync]
|
||||||
|
git = "https://github.com/embassy-rs/embassy"
|
||||||
|
rev = "3bc6e414f7b1d4b4d138c7e90f7f9e85a7ca2885"
|
32
build.rs
Normal file
32
build.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
//! This build script copies the `memory.x` file from the crate root into
|
||||||
|
//! a directory where the linker can always find it at build time.
|
||||||
|
//! For many projects this is optional, as the linker always searches the
|
||||||
|
//! project root directory -- wherever `Cargo.toml` is. However, if you
|
||||||
|
//! are using a workspace or have a more complicated build setup, this
|
||||||
|
//! build script becomes required. Additionally, by requesting that
|
||||||
|
//! Cargo re-run the build script whenever `memory.x` is changed,
|
||||||
|
//! updating `memory.x` ensures a rebuild of the application with the
|
||||||
|
//! new memory settings.
|
||||||
|
|
||||||
|
use std::{env, fs::File, io::Write, path::PathBuf};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Put `memory.x` in our output directory and ensure it's
|
||||||
|
// on the linker search path.
|
||||||
|
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||||
|
File::create(out.join("memory.x"))
|
||||||
|
.unwrap()
|
||||||
|
.write_all(include_bytes!("memory.x"))
|
||||||
|
.unwrap();
|
||||||
|
println!("cargo:rustc-link-search={}", out.display());
|
||||||
|
|
||||||
|
// By default, Cargo will re-run a build script whenever
|
||||||
|
// any file in the project changes. By specifying `memory.x`
|
||||||
|
// here, we ensure the build script is only re-run when
|
||||||
|
// `memory.x` is changed.
|
||||||
|
println!("cargo:rerun-if-changed=memory.x");
|
||||||
|
|
||||||
|
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||||
|
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||||
|
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||||
|
}
|
7
memory.x
Normal file
7
memory.x
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
/* STM32L476RG */
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
FLASH : ORIGIN = 0x08000000, LENGTH = 1024K
|
||||||
|
RAM : ORIGIN = 0x20000000, LENGTH = 96K
|
||||||
|
/* RAM2 : ORIGIN = 0x10000000, LENGTH = 32K */
|
||||||
|
}
|
38
rustfmt.toml
Normal file
38
rustfmt.toml
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
edition = "2021"
|
||||||
|
max_width = 90
|
||||||
|
newline_style = "Unix"
|
||||||
|
unstable_features = true
|
||||||
|
|
||||||
|
# skip generated files
|
||||||
|
format_generated_files = false
|
||||||
|
|
||||||
|
# always use tabs.
|
||||||
|
hard_tabs = true
|
||||||
|
tab_spaces = 4
|
||||||
|
|
||||||
|
# commas inbetween but not after
|
||||||
|
match_block_trailing_comma = true
|
||||||
|
trailing_comma = "Never"
|
||||||
|
|
||||||
|
# fix my imports for me
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
#group_imports = "One"
|
||||||
|
|
||||||
|
# format everything
|
||||||
|
format_code_in_doc_comments = true
|
||||||
|
format_macro_matchers = true
|
||||||
|
|
||||||
|
# don't keep outdated syntax
|
||||||
|
use_field_init_shorthand = true
|
||||||
|
use_try_shorthand = true
|
||||||
|
|
||||||
|
# condense Struct { _, _ } to Struct { .. }
|
||||||
|
condense_wildcard_suffixes = true
|
||||||
|
|
||||||
|
# prefer foo(Bar { \n }) over foo(\nBar { \n }\n)
|
||||||
|
overflow_delimited_expr = true
|
||||||
|
|
||||||
|
# I wish there was a way to allow 0..n but not a + 1..b + 2
|
||||||
|
# However, the later looks so terible that I use spaces everywhere
|
||||||
|
# https://github.com/rust-lang/rustfmt/issues/3367
|
||||||
|
spaces_around_ranges = true
|
58
src/main.rs
Normal file
58
src/main.rs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![allow(clippy::unnecessary_literal_unwrap)] // "false positive"
|
||||||
|
#![warn(rust_2018_idioms)]
|
||||||
|
#![forbid(elided_lifetimes_in_paths)]
|
||||||
|
|
||||||
|
mod spi_slave;
|
||||||
|
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_stm32::{
|
||||||
|
bind_interrupts,
|
||||||
|
gpio::{self, Output},
|
||||||
|
peripherals::USART1,
|
||||||
|
time::{mhz, Hertz},
|
||||||
|
usart::{self, Uart},
|
||||||
|
Config, dma::NoDma
|
||||||
|
};
|
||||||
|
use panic_halt as _;
|
||||||
|
use spi_slave::SpiSlave;
|
||||||
|
|
||||||
|
bind_interrupts!(struct Irqs {
|
||||||
|
USART1 => usart::InterruptHandler<USART1>;
|
||||||
|
});
|
||||||
|
|
||||||
|
fn config() -> Config {
|
||||||
|
let mut config = Config::default();
|
||||||
|
config.rcc.hse = Some(mhz(8));
|
||||||
|
let sysclk = Some(mhz(72));
|
||||||
|
config.rcc.sys_ck = sysclk;
|
||||||
|
config.rcc.hclk = sysclk;
|
||||||
|
config.rcc.pclk1 = Some(Hertz(sysclk.unwrap().0 / 2));
|
||||||
|
config.rcc.pclk2 = sysclk;
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) {
|
||||||
|
let p = embassy_stm32::init(config());
|
||||||
|
|
||||||
|
let uart1_cfg = usart::Config::default();
|
||||||
|
let mut uart1 = Uart::new(
|
||||||
|
p.USART1, p.PA10, p.PA9, Irqs, p.DMA1_CH4, NoDma, uart1_cfg
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let spi1_cfg = spi_slave::Config::default();
|
||||||
|
let mut spi1 = SpiSlave::new(
|
||||||
|
p.SPI1, p.PA5, p.PA7, p.PA6, p.PA4, p.DMA1_CH3, p.DMA1_CH2, spi1_cfg
|
||||||
|
);
|
||||||
|
|
||||||
|
let _led = Output::new(p.PC13, gpio::Level::Low, gpio::Speed::Low);
|
||||||
|
|
||||||
|
let mut buf = [0u8; 4];
|
||||||
|
loop {
|
||||||
|
spi1.read(&mut buf).await.unwrap();
|
||||||
|
uart1.write(&buf).await.unwrap();
|
||||||
|
}
|
||||||
|
}
|
222
src/spi_slave.rs
Normal file
222
src/spi_slave.rs
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
use embassy_futures::join::join;
|
||||||
|
use embassy_stm32::{
|
||||||
|
dma::Transfer,
|
||||||
|
gpio::{self, low_level::AFType, AnyPin},
|
||||||
|
into_ref,
|
||||||
|
pac::spi::vals,
|
||||||
|
spi::{
|
||||||
|
self, BitOrder, CsPin, Error, Instance, MisoPin, Mode, MosiPin, Phase, Polarity,
|
||||||
|
RxDma, SckPin, TxDma
|
||||||
|
},
|
||||||
|
Peripheral, PeripheralRef
|
||||||
|
};
|
||||||
|
|
||||||
|
/// SPI configuration.
|
||||||
|
#[non_exhaustive]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Config {
|
||||||
|
/// SPI mode.
|
||||||
|
pub mode: Mode,
|
||||||
|
/// Bit order.
|
||||||
|
pub bit_order: BitOrder
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
mode: spi::Config::default().mode,
|
||||||
|
bit_order: BitOrder::MsbFirst
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
fn raw_phase(&self) -> vals::Cpha {
|
||||||
|
match self.mode.phase {
|
||||||
|
Phase::CaptureOnSecondTransition => vals::Cpha::SECONDEDGE,
|
||||||
|
Phase::CaptureOnFirstTransition => vals::Cpha::FIRSTEDGE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_polarity(&self) -> vals::Cpol {
|
||||||
|
match self.mode.polarity {
|
||||||
|
Polarity::IdleHigh => vals::Cpol::IDLEHIGH,
|
||||||
|
Polarity::IdleLow => vals::Cpol::IDLELOW
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_byte_order(&self) -> vals::Lsbfirst {
|
||||||
|
match self.bit_order {
|
||||||
|
BitOrder::LsbFirst => vals::Lsbfirst::LSBFIRST,
|
||||||
|
BitOrder::MsbFirst => vals::Lsbfirst::MSBFIRST
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SpiSlave<'d, T: Instance, Tx, Rx> {
|
||||||
|
_peri: PeripheralRef<'d, T>,
|
||||||
|
sck: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
mosi: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
miso: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
cs: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
txdma: PeripheralRef<'d, Tx>,
|
||||||
|
rxdma: PeripheralRef<'d, Rx>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'d, T: Instance, Tx, Rx> SpiSlave<'d, T, Tx, Rx> {
|
||||||
|
/// Create a new SPI driver.
|
||||||
|
pub fn new(
|
||||||
|
peri: impl Peripheral<P = T> + 'd,
|
||||||
|
sck: impl Peripheral<P = impl SckPin<T>> + 'd,
|
||||||
|
mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
|
||||||
|
miso: impl Peripheral<P = impl MisoPin<T>> + 'd,
|
||||||
|
cs: impl Peripheral<P = impl CsPin<T>> + 'd,
|
||||||
|
txdma: impl Peripheral<P = Tx> + 'd,
|
||||||
|
rxdma: impl Peripheral<P = Rx> + 'd,
|
||||||
|
config: Config
|
||||||
|
) -> Self {
|
||||||
|
into_ref!(peri, sck, mosi, miso, cs);
|
||||||
|
|
||||||
|
sck.set_as_af(sck.af_num(), AFType::Input);
|
||||||
|
sck.set_speed(gpio::Speed::VeryHigh);
|
||||||
|
mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull);
|
||||||
|
mosi.set_speed(gpio::Speed::VeryHigh);
|
||||||
|
miso.set_as_af(miso.af_num(), AFType::Input);
|
||||||
|
miso.set_speed(gpio::Speed::VeryHigh);
|
||||||
|
cs.set_as_af(cs.af_num(), AFType::Input);
|
||||||
|
cs.set_speed(gpio::Speed::VeryHigh);
|
||||||
|
|
||||||
|
Self::new_inner(
|
||||||
|
peri,
|
||||||
|
Some(sck.map_into()),
|
||||||
|
Some(mosi.map_into()),
|
||||||
|
Some(miso.map_into()),
|
||||||
|
Some(cs.map_into()),
|
||||||
|
txdma,
|
||||||
|
rxdma,
|
||||||
|
config
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_inner(
|
||||||
|
peri: impl Peripheral<P = T> + 'd,
|
||||||
|
sck: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
mosi: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
miso: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
cs: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
txdma: impl Peripheral<P = Tx> + 'd,
|
||||||
|
rxdma: impl Peripheral<P = Rx> + 'd,
|
||||||
|
config: Config
|
||||||
|
) -> Self {
|
||||||
|
into_ref!(peri, txdma, rxdma);
|
||||||
|
|
||||||
|
let cpha = config.raw_phase();
|
||||||
|
let cpol = config.raw_polarity();
|
||||||
|
|
||||||
|
let lsbfirst = config.raw_byte_order();
|
||||||
|
|
||||||
|
T::enable_and_reset();
|
||||||
|
|
||||||
|
T::REGS.cr2().modify(|w| {
|
||||||
|
w.set_ssoe(false);
|
||||||
|
});
|
||||||
|
T::REGS.cr1().modify(|w| {
|
||||||
|
w.set_cpha(cpha);
|
||||||
|
w.set_cpol(cpol);
|
||||||
|
|
||||||
|
w.set_mstr(vals::Mstr::SLAVE);
|
||||||
|
w.set_spe(true);
|
||||||
|
w.set_lsbfirst(lsbfirst);
|
||||||
|
w.set_ssm(false);
|
||||||
|
w.set_crcen(false);
|
||||||
|
w.set_bidimode(vals::Bidimode::UNIDIRECTIONAL);
|
||||||
|
if mosi.is_none() {
|
||||||
|
w.set_rxonly(vals::Rxonly::OUTPUTDISABLED);
|
||||||
|
}
|
||||||
|
w.set_dff(vals::Dff::EIGHTBIT);
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
_peri: peri,
|
||||||
|
sck,
|
||||||
|
mosi,
|
||||||
|
miso,
|
||||||
|
cs,
|
||||||
|
txdma,
|
||||||
|
rxdma
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// SPI read, using DMA.
|
||||||
|
pub async fn read(&mut self, data: &mut [u8]) -> Result<(), Error>
|
||||||
|
where
|
||||||
|
Tx: TxDma<T>,
|
||||||
|
Rx: RxDma<T>
|
||||||
|
{
|
||||||
|
if data.is_empty() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
T::REGS.cr1().modify(|w| {
|
||||||
|
w.set_spe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// clear rxfifo
|
||||||
|
while T::REGS.sr().read().rxne() {
|
||||||
|
let _ = T::REGS.dr().read();
|
||||||
|
}
|
||||||
|
|
||||||
|
T::REGS.cr2().modify(|w| w.set_rxdmaen(true));
|
||||||
|
|
||||||
|
let clock_byte_count = data.len();
|
||||||
|
|
||||||
|
let rx_request = self.rxdma.request();
|
||||||
|
let rx_src = T::REGS.dr().as_ptr() as *mut u8;
|
||||||
|
let rx_f = unsafe {
|
||||||
|
Transfer::new_read(
|
||||||
|
&mut self.rxdma,
|
||||||
|
rx_request,
|
||||||
|
rx_src,
|
||||||
|
data,
|
||||||
|
Default::default()
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let tx_request = self.txdma.request();
|
||||||
|
let tx_dst = T::REGS.dr().as_ptr() as *mut u8;
|
||||||
|
let clock_byte = 0x00u8;
|
||||||
|
let tx_f = unsafe {
|
||||||
|
Transfer::new_write_repeated(
|
||||||
|
&mut self.txdma,
|
||||||
|
tx_request,
|
||||||
|
&clock_byte,
|
||||||
|
clock_byte_count,
|
||||||
|
tx_dst,
|
||||||
|
Default::default()
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
T::REGS.cr2().modify(|w| w.set_txdmaen(true));
|
||||||
|
T::REGS.cr1().modify(|w| {
|
||||||
|
w.set_spe(true);
|
||||||
|
});
|
||||||
|
#[cfg(any(spi_v3, spi_v4, spi_v5))]
|
||||||
|
T::REGS.cr1().modify(|w| {
|
||||||
|
w.set_cstart(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
join(tx_f, rx_f).await;
|
||||||
|
|
||||||
|
// finish dma
|
||||||
|
while T::REGS.sr().read().bsy() {}
|
||||||
|
T::REGS.cr1().modify(|w| {
|
||||||
|
w.set_spe(false);
|
||||||
|
});
|
||||||
|
T::REGS.cr2().modify(|reg| {
|
||||||
|
reg.set_txdmaen(false);
|
||||||
|
reg.set_rxdmaen(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue