diff options
Diffstat (limited to 'sw/demo1')
-rw-r--r-- | sw/demo1/Cargo.lock | 222 | ||||
-rw-r--r-- | sw/demo1/Cargo.toml | 4 | ||||
-rw-r--r-- | sw/demo1/Makefile | 2 | ||||
-rw-r--r-- | sw/demo1/README.md | 14 | ||||
-rw-r--r-- | sw/demo1/src/main.rs | 134 |
5 files changed, 283 insertions, 93 deletions
diff --git a/sw/demo1/Cargo.lock b/sw/demo1/Cargo.lock index 59d2cba..f3bfa79 100644 --- a/sw/demo1/Cargo.lock +++ b/sw/demo1/Cargo.lock @@ -2,264 +2,322 @@ # It is not intended for manual editing. [[package]] name = "aligned" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d39da9b88ae1a81c03c9c082b8db83f1d0e93914126041962af61034ab44c4a5" + +[[package]] +name = "aligned" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb1ce8b3382016136ab1d31a1b5ce807144f8b7eb2d5f16b2108f0f07edceb94" dependencies = [ - "as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "as-slice", ] [[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" + +[[package]] name = "as-slice" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37dfb65bc03b2bc85ee827004f14a6817e04160e3b1a28931986a666a9290e70" dependencies = [ - "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", - "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", - "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.12.3", + "generic-array 0.13.2", + "stable_deref_trait", ] [[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 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version", ] [[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] name = "cast" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "cortex-m" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c0b159a1e8306949579de3698c841dba58058197b65c60807194e4fa1e7a554" dependencies = [ - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "aligned 0.2.0", + "bare-metal", + "cortex-m 0.6.2", + "volatile-register", ] [[package]] name = "cortex-m" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763" dependencies = [ - "aligned 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "aligned 0.3.2", + "bare-metal", + "volatile-register", ] [[package]] name = "cortex-m-rt" version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d518da72bba39496024b62607c1d8e37bcece44b2536664f1132a73a499a28" dependencies = [ - "cortex-m-rt-macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt-macros", + "r0", ] [[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 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "cortex-m-semihosting" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "113ef0ecffee2b62b58f9380f4469099b30e9f9cbee2804771b4203ba1762cfa" dependencies = [ - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.2", ] [[package]] name = "demo1" version = "0.1.0" dependencies = [ - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "stm32f1xx-hal 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec", + "cortex-m 0.6.2", + "cortex-m-rt", + "cortex-m-semihosting", + "embedded-hal", + "hd44780-driver", + "nb", + "panic-semihosting", + "shared-bus", + "si5351", + "stm32f1xx-hal", ] [[package]] name = "embedded-hal" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b" dependencies = [ - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "nb", + "void", ] [[package]] name = "generic-array" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum", ] [[package]] name = "generic-array" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd" +dependencies = [ + "typenum", +] + +[[package]] +name = "hd44780-driver" +version = "0.3.0" dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal", ] [[package]] name = "nb" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc" [[package]] name = "panic-semihosting" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03864ac862876c16a308f5286f4aa217f1a69ac45df87ad3cd2847f818a642c" dependencies = [ - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.2", + "cortex-m-semihosting", ] [[package]] name = "proc-macro2" -version = "1.0.10" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid", ] [[package]] name = "quote" -version = "1.0.3" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "r0" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" [[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 (registry+https://github.com/rust-lang/crates.io-index)", + "semver", ] [[package]] name = "semver" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver-parser", ] [[package]] name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "shared-bus" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed792a53f339088822c0cc9d6ebfb950752016a288dc96ed3e302e9592f18ab0" +dependencies = [ + "cortex-m 0.5.10", + "embedded-hal", +] + +[[package]] +name = "si5351" +version = "0.2.0" +source = "git+https://github.com/ilya-epifanov/si5351?rev=e509c36#e509c36df9b7521ffb253079e3226d6b870f0b4d" +dependencies = [ + "bitflags", + "embedded-hal", +] [[package]] name = "stable_deref_trait" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" [[package]] name = "stm32f1" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ce629123831891663402861bdc7140ebfd6a34a464329f9b9ec1cfde72055a" dependencies = [ - "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bare-metal", + "cortex-m 0.6.2", + "cortex-m-rt", + "vcell", ] [[package]] name = "stm32f1xx-hal" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455bf444813cdc2498130626c5d0ca42f91de1e8261751f3bdc6e5ad9e2aa128" dependencies = [ - "as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "stm32f1 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "as-slice", + "cast", + "cortex-m 0.6.2", + "cortex-m-rt", + "embedded-hal", + "nb", + "stm32f1", + "void", ] [[package]] name = "syn" -version = "1.0.17" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6" dependencies = [ - "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-xid", ] [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" [[package]] name = "vcell" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c" [[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.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" dependencies = [ - "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell", ] - -[metadata] -"checksum aligned 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eb1ce8b3382016136ab1d31a1b5ce807144f8b7eb2d5f16b2108f0f07edceb94" -"checksum as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "37dfb65bc03b2bc85ee827004f14a6817e04160e3b1a28931986a666a9290e70" -"checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" -"checksum cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" -"checksum cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763" -"checksum cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "00d518da72bba39496024b62607c1d8e37bcece44b2536664f1132a73a499a28" -"checksum cortex-m-rt-macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4717562afbba06e760d34451919f5c3bf3ac15c7bb897e8b04862a7428378647" -"checksum cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "113ef0ecffee2b62b58f9380f4469099b30e9f9cbee2804771b4203ba1762cfa" -"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b" -"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" -"checksum generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd" -"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc" -"checksum panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c03864ac862876c16a308f5286f4aa217f1a69ac45df87ad3cd2847f818a642c" -"checksum proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" -"checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" -"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" -"checksum stm32f1 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "22ce629123831891663402861bdc7140ebfd6a34a464329f9b9ec1cfde72055a" -"checksum stm32f1xx-hal 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "455bf444813cdc2498130626c5d0ca42f91de1e8261751f3bdc6e5ad9e2aa128" -"checksum syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" -"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" -"checksum vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" diff --git a/sw/demo1/Cargo.toml b/sw/demo1/Cargo.toml index 7219b30..cf33da1 100644 --- a/sw/demo1/Cargo.toml +++ b/sw/demo1/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" license = "MIT" [dependencies] +arrayvec = { version = "0.5", default-features = false, features = [] } # alloc-cortex-m = "0.3" # requires nightly cortex-m = "0.6" cortex-m-rt = "0.6" @@ -16,6 +17,9 @@ nb = "0.1" #stm32h7 = { version = "0.9", features = ["stm32h743", "rt"] } stm32f1xx-hal = { version = "0.5", features = ["rt", "stm32f103"] } embedded-hal = { version = "0.2", features = [] } +shared-bus = { version = "0.1.4", features = ["cortexm"] } +hd44780-driver = { path = "../deps/hd44780-driver"} +si5351 = { git = "https://github.com/ilya-epifanov/si5351", rev = "e509c36" } [profile.dev] codegen-units = 1 diff --git a/sw/demo1/Makefile b/sw/demo1/Makefile index 1dcb47c..f875306 100644 --- a/sw/demo1/Makefile +++ b/sw/demo1/Makefile @@ -6,7 +6,7 @@ BIN := target/thumbv7em-none-eabihf/release/demo1 # Build and flash in release mode all: - cargo build --release + cargo build $(OPENOCD) -f $(OPENOCD_CFG) -c "program $(BIN) reset exit" # Start a openocd session. diff --git a/sw/demo1/README.md b/sw/demo1/README.md index 496864c..d15a874 100644 --- a/sw/demo1/README.md +++ b/sw/demo1/README.md @@ -2,3 +2,17 @@ demo1 example ============= See examples in https://github.com/stm32-rs/stm32f1xx-hal/tree/v0.5.3/examples + +Programming +----------- + +Put target in reset + + openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg + + cargo run + +Deassert RESET + + gdb% load + gdb% cont diff --git a/sw/demo1/src/main.rs b/sw/demo1/src/main.rs index 80e38b9..4f8ce6e 100644 --- a/sw/demo1/src/main.rs +++ b/sw/demo1/src/main.rs @@ -8,13 +8,15 @@ use panic_semihosting as _; use stm32f1xx_hal::{ prelude::*, pac, - timer::Timer, + i2c::{BlockingI2c, Mode}, + delay::Delay, }; use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin}; +use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780}; +use si5351::{Si5351, Si5351Device}; use core::fmt::Write; -use nb::block; fn print(step: usize) -> Result<(), core::fmt::Error> { let mut stdout = match hio::hstdout() { @@ -37,7 +39,9 @@ fn main() -> ! { let mut flash = dp.FLASH.constrain(); let mut rcc = dp.RCC.constrain(); + let mut afio = dp.AFIO.constrain(&mut rcc.apb2); let clocks = rcc.cfgr.freeze(&mut flash.acr); + let mut delay = Delay::new(cp.SYST, clocks); let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); @@ -45,28 +49,138 @@ fn main() -> ! { let mut led = gpiob.pb14.into_push_pull_output(&mut gpiob.crh); led.set_low().unwrap(); - let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz()); + // Configure I2C1 to be used for Si5351 and display + let scl = gpiob.pb6.into_alternate_open_drain(&mut gpiob.crl); + let sda = gpiob.pb7.into_alternate_open_drain(&mut gpiob.crl); + + let i2c = BlockingI2c::i2c1( + dp.I2C1, + (scl, sda), + &mut afio.mapr, + Mode::Standard { + frequency: 100_000.hz(), + }, + clocks, + &mut rcc.apb1, + /* start_timeout_us */ 1000, + /* start_retries */ 10, + /* addr_timeout_us */ 1000, + /* data_timeout_us */ 1000, + ); + + let i2c_busmanager = shared_bus::CortexMBusManager::new(i2c); + + /* + // Configure I2C2 + let scl2 = gpiob.pb10.into_alternate_open_drain(&mut gpiob.crh); + let sda2 = gpiob.pb11.into_alternate_open_drain(&mut gpiob.crh); + + let i2c2 = BlockingI2c::i2c2( + dp.I2C2, + (scl2, sda2), + Mode::Fast { + frequency: 400_000.hz(), + duty_cycle: DutyCycle::Ratio2to1, + }, + clocks, + &mut rcc.apb1, + /* start_timeout_us */ 1000, + /* start_retries */ 10, + /* addr_timeout_us */ 1000, + /* data_timeout_us */ 1000, + ); + */ + + const I2C_ADDRESS: u8 = 0b010_0000; // MCP23008, depending on solder bridges + let mut lcd = match HD44780::new_i2c_mcp23008(i2c_busmanager.acquire(), I2C_ADDRESS, &mut delay) { + Ok(lcd) => lcd, + Err(_) => panic!("HD44780 init fail"), + }; + + lcd.reset(&mut delay).unwrap(); + lcd.clear(&mut delay).unwrap(); + lcd.set_display_mode( + DisplayMode { + display: Display::On, + cursor_visibility: Cursor::Invisible, + cursor_blink: CursorBlink::Off, + }, + &mut delay).unwrap(); + lcd.set_cursor_pos(0, &mut delay).unwrap(); + lcd.write_str("Hello, world!", &mut delay).unwrap(); + + let ref_clock = 25_000_000; + let mut siclock = Si5351Device::new(i2c_busmanager.acquire(), false, ref_clock); + siclock.init(si5351::CrystalLoad::_10).unwrap(); + siclock.set_frequency(si5351::PLL::B, si5351::ClockOutput::Clk0, 28_000_000 + 4_915_200).unwrap(); + siclock.set_frequency(si5351::PLL::A, si5351::ClockOutput::Clk1, 144_000_000 + 28_000_000).unwrap(); + siclock.set_frequency(si5351::PLL::A, si5351::ClockOutput::Clk2, 4_915_100).unwrap(); + + lcd.set_cursor_pos(0, &mut delay).unwrap(); + lcd.write_str("Clocks set. ", &mut delay).unwrap(); let mut step = 0; print(step).unwrap(); loop { - for _ in 0..5 { - led.toggle().unwrap(); - block!(timer.wait()).ok(); - } + led.toggle().unwrap(); + delay.delay_ms(600u32); + + lcd.set_cursor_pos(40, &mut delay).unwrap(); + let mut string = arrayvec::ArrayString::<[_; 16]>::new(); + write!(string, "Step {} ", step).unwrap(); + lcd.write_str(&string, &mut delay).unwrap(); - print(step).unwrap(); step += 1; } } #[cortex_m_rt::exception] fn HardFault(ef: &ExceptionFrame) -> ! { - panic!("HardFault at {:#?}", ef); + let periph = unsafe { cortex_m::Peripherals::steal() }; + let hfsr = periph.SCB.hfsr.read(); + let cfsr = periph.SCB.cfsr.read(); + + let mut stdout = match hio::hstdout() { + Ok(fd) => fd, + Err(()) => panic!("no stdout"), + }; + + let _ = write!(stdout, "Hardfault {:x} {:x} at {:x}\n", hfsr, cfsr, ef.pc); + cortex_m::asm::bkpt(); + loop { } } #[cortex_m_rt::exception] fn DefaultHandler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); + let mut stdout = match hio::hstdout() { + Ok(fd) => fd, + Err(()) => panic!("no stdout"), + }; + + let _ = write!(stdout, "Unhandled exception (IRQn = {})", irqn); + cortex_m::asm::bkpt(); + loop { } } + + + + /* code to discover i2c device address + let mut stdout = hio::hstdout().unwrap(); + + loop { + for addr in 0..127usize { + let bytes = [0u8; 1]; + let mut buffer = [0u8; 1]; + match i2c.write_read(addr as u8, &bytes, &mut buffer) { + Ok(()) => { + write!(stdout, "{}: {}\n", addr, buffer[0]).unwrap(); + }, + Err(_) => { + write!(stdout, "{}: fail\n", addr).unwrap(); + }, + } + } + } + */ + |