1
0
Fork 0

Update rust, stm32-eth, hal, smoltcp versions

This commit is contained in:
linuswck 2024-03-22 17:44:06 +08:00
parent f8abfd4300
commit af68b0e90a
13 changed files with 249 additions and 144 deletions

205
Cargo.lock generated
View File

@ -177,9 +177,9 @@ checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216"
[[package]]
name = "defmt"
version = "0.3.5"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a2d011b2fee29fb7d659b83c43fce9a2cb4df453e16d441a51448e448f3f98"
checksum = "3939552907426de152b3c2c6f51ed53f98f448babd26f28694c95f5906194595"
dependencies = [
"bitflags",
"defmt-macros",
@ -187,35 +187,44 @@ dependencies = [
[[package]]
name = "defmt-macros"
version = "0.3.6"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54f0216f6c5acb5ae1a47050a6645024e6edafc2ee32d421955eccfef12ef92e"
checksum = "18bdc7a7b92ac413e19e95240e75d3a73a8d8e78aa24a594c22cbb4d44b4bbda"
dependencies = [
"defmt-parser",
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.48",
"syn 2.0.53",
]
[[package]]
name = "defmt-parser"
version = "0.3.3"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "269924c02afd7f94bc4cecbfa5c379f6ffcf9766b3408fe63d22c728654eccd0"
checksum = "ff4a5fefe330e8d7f31b16a318f9ce81000d8e35e69b93eae154d16d2278f70f"
dependencies = [
"thiserror",
]
[[package]]
name = "deranged"
version = "0.3.10"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc"
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
dependencies = [
"powerfmt",
]
[[package]]
name = "document-features"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef5282ad69563b5fc40319526ba27e0e7363d552a896f0297d54f767717f9b95"
dependencies = [
"litrs",
]
[[package]]
name = "embedded-dma"
version = "0.2.0"
@ -237,10 +246,17 @@ dependencies = [
[[package]]
name = "embedded-hal"
version = "1.0.0-alpha.8"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3babfc7fd332142a0b11aebf592992f211f4e01b6222fb04b03aba1bd80018d"
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
[[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",
]
@ -263,9 +279,9 @@ dependencies = [
[[package]]
name = "embedded-storage"
version = "0.2.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "723dce4e9f25b6e6c5f35628e144794e5b459216ed7da97b7c4b66cdb3fa82ca"
checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032"
[[package]]
name = "embedded-time"
@ -276,6 +292,26 @@ dependencies = [
"num",
]
[[package]]
name = "enumflags2"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3278c9d5fb675e0a51dabcf4c0d355f692b064171535ba72361be1528a9d8e8d"
dependencies = [
"enumflags2_derive",
]
[[package]]
name = "enumflags2_derive"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c785274071b1b420972453b306eeca06acf4633829db4223b58a2a8c5953bc4"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.53",
]
[[package]]
name = "fugit"
version = "0.3.7"
@ -347,6 +383,15 @@ dependencies = [
"byteorder",
]
[[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.5.6"
@ -374,6 +419,16 @@ dependencies = [
"stable_deref_trait",
]
[[package]]
name = "heapless"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
dependencies = [
"hash32 0.3.1",
"stable_deref_trait",
]
[[package]]
name = "ieee802_3_miim"
version = "0.8.0"
@ -425,6 +480,12 @@ version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]]
name = "litrs"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
[[package]]
name = "lock_api"
version = "0.4.11"
@ -437,9 +498,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.20"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
[[package]]
name = "managed"
@ -472,7 +533,7 @@ checksum = "89f46d25f40e41f552d76b8eb9e225fe493ebf978a5c3f42b7599e45cfe6b4e3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
"syn 2.0.53",
]
[[package]]
@ -535,20 +596,25 @@ dependencies = [
]
[[package]]
name = "num-integer"
version = "0.1.45"
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.43"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9"
dependencies = [
"autocfg",
"num-integer",
@ -568,9 +634,9 @@ dependencies = [
[[package]]
name = "num-traits"
version = "0.2.17"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
dependencies = [
"autocfg",
"libm",
@ -593,7 +659,7 @@ checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
"syn 2.0.53",
]
[[package]]
@ -602,6 +668,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
[[package]]
name = "portable-atomic"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
[[package]]
name = "postcard"
version = "0.5.2"
@ -651,9 +723,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.78"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
dependencies = [
"unicode-ident",
]
@ -698,14 +770,14 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver 1.0.20",
"semver 1.0.22",
]
[[package]]
name = "ryu"
version = "1.0.16"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]]
name = "scopeguard"
@ -724,9 +796,9 @@ dependencies = [
[[package]]
name = "semver"
version = "1.0.20"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca"
[[package]]
name = "semver-parser"
@ -736,9 +808,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.196"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
dependencies = [
"serde_derive",
]
@ -756,13 +828,13 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.196"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
"syn 2.0.53",
]
[[package]]
@ -798,14 +870,14 @@ dependencies = [
[[package]]
name = "smoltcp"
version = "0.10.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d2e3a36ac8fea7b94e666dfa3871063d6e0a5c9d5d4fec9a1a6b7b6760f0229"
checksum = "5a1a996951e50b5971a2c8c0fa05a381480d70a933064245c4a223ddc87ccc97"
dependencies = [
"bitflags",
"byteorder",
"cfg-if",
"heapless 0.7.17",
"heapless 0.8.0",
"log",
"managed",
]
@ -827,9 +899,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "stm32-eth"
version = "0.5.2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "114ecd655ee196c97dc4b3ff63b48046f2e2e2a7b3f53cc5114b9599606c093b"
checksum = "97b858953e04ae990830500e70363d336609814ebb014c3e73dc7c1736aea65f"
dependencies = [
"aligned",
"cortex-m",
@ -855,18 +927,20 @@ dependencies = [
[[package]]
name = "stm32f4xx-hal"
version = "0.14.0"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb045e607d0946eca27523141d192d7ee91aea0dff9736be100b8fc0c186abf"
checksum = "10c41454f262c0be0c35b8cfc0d971e598281f7a9be32e894dc97a0b21deadfe"
dependencies = [
"bare-metal 1.0.0",
"bitflags",
"cortex-m",
"cortex-m-rt",
"document-features",
"embedded-dma",
"embedded-hal 0.2.7",
"embedded-hal 1.0.0-alpha.8",
"embedded-hal 1.0.0",
"embedded-hal-nb",
"embedded-storage",
"enumflags2",
"fugit",
"fugit-timer",
"nb 1.1.0",
@ -874,6 +948,7 @@ dependencies = [
"stm32f4",
"synopsys-usb-otg",
"time",
"vcell",
"void",
]
@ -890,9 +965,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.48"
version = "2.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032"
dependencies = [
"proc-macro2",
"quote",
@ -901,9 +976,9 @@ dependencies = [
[[package]]
name = "synopsys-usb-otg"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678f3707a7b1fd4863023292c42f73c6bab0e9b0096f41ae612d1af0ff221b45"
checksum = "e948d523b316939545d8b21a48c27aef150ce25321b9f95ff7978647a806a6fe"
dependencies = [
"cortex-m",
"embedded-hal 0.2.7",
@ -913,31 +988,32 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.51"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7"
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.51"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df"
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
"syn 2.0.53",
]
[[package]]
name = "time"
version = "0.3.30"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
dependencies = [
"deranged",
"num-conv",
"powerfmt",
"time-core",
]
@ -979,18 +1055,23 @@ dependencies = [
[[package]]
name = "usb-device"
version = "0.2.9"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508"
checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6"
dependencies = [
"heapless 0.8.0",
"portable-atomic",
]
[[package]]
name = "usbd-serial"
version = "0.1.1"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db75519b86287f12dcf0d171c7cf4ecc839149fe9f3b720ac4cfce52959e1dfe"
checksum = "c233fa6eb0417df4fa34aef190dfe725497a8a8120310d360e0c91653ce4f792"
dependencies = [
"embedded-hal 0.2.7",
"nb 0.1.3",
"embedded-io",
"nb 1.1.0",
"usb-device",
]

View File

@ -15,21 +15,21 @@ default-target = "thumbv7em-none-eabihf"
[dependencies]
panic-halt = "0.2.0"
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = { version = "0.7.1", features = ["device"] }
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
cortex-m-rt = { version = "0.7.3", features = ["device"] }
cortex-m-semihosting = "0.5.0"
log = "0.4.17"
bare-metal = "1"
nb = "1"
cortex-m-log = { version = "0.7.0", features = ["log-integration", "semihosting"] }
stm32f4xx-hal = { version = "0.14.0", features = ["rt", "stm32f407", "usb_fs"] }
stm32-eth = { version = "0.5.2", features = ["stm32f407", "smoltcp-phy", "smoltcp"] }
stm32f4xx-hal = { version = "0.20.0", features = ["stm32f407", "otg-fs", "usb_fs"] }
stm32-eth = { version = "0.6.0", features = ["stm32f407", "smoltcp-phy", "smoltcp"] }
ieee802_3_miim = "0.8.0"
smoltcp = { version = "0.10.0", default-features = false, features = ["proto-ipv4", "socket-tcp", "log", "medium-ethernet"] }
smoltcp = { version = "0.11.0", default-features = false, features = ["proto-ipv4", "socket-tcp", "log", "medium-ethernet"] }
uom = { version = "0.30", default-features = false, features = ["autoconvert", "si", "f32", "use_serde"] }
num-traits = { version = "0.2.15", default-features = false, features = ["libm"] }
usb-device = "0.2.9"
usbd-serial = "0.1.1"
usb-device = "0.3.2"
usbd-serial = "0.2.1"
fugit = "0.3.6"
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
miniconf = "0.9.0"

View File

@ -8,8 +8,8 @@
let
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) ]; };
rustManifest = pkgs.fetchurl {
url = "https://static.rust-lang.org/dist/2023-02-09/channel-rust-stable.toml";
sha256 = "4b8740ee77b62291471be1278d77e8826ab01b20c54915859c9f1ccb8299af59";
url = "https://static.rust-lang.org/dist/2024-03-21/channel-rust-stable.toml";
sha256 = "faccaa01dda45fc2956bcfd4da0cf76e52104d3b1862ddd4eb7c4159a18e49cf";
};
targets = [

View File

@ -39,7 +39,7 @@ impl StoreBackend for FlashBackend {
}
fn backup_space(&self) -> &'static mut [u8] {
unsafe { &mut BACKUP_SPACE }
unsafe { BACKUP_SPACE.as_mut() }
}
}

View File

@ -7,6 +7,7 @@ use crate::thermostat::ad7172;
use crate::net::net::EthernetMgmtPins;
use crate::device::hw_rev::{HWRev, HwRevPins};
use stm32_eth::EthPins;
use stm32f4xx_hal::gpio::alt::otg_fs::{Dm, Dp};
use stm32f4xx_hal::{
gpio::{gpioa::*, gpiob::*, gpioc::*, GpioExt, Input, Speed},
otg_fs::USB,
@ -16,7 +17,7 @@ use stm32f4xx_hal::{
},
rcc::Clocks,
spi::{NoMiso, Spi},
timer::pwm::PwmExt,
timer::{Channel1, Channel2, Channel3, pwm::PwmExt}
};
pub type EthernetPins =
@ -67,8 +68,8 @@ pub fn setup(
usb_global: otg_fs_global,
usb_device: otg_fs_device,
usb_pwrclk: otg_fs_pwrclk,
pin_dm: gpioa.pa11.into_alternate(),
pin_dp: gpioa.pa12.into_alternate(),
pin_dm: Dm::PA11(gpioa.pa11.into_alternate()),
pin_dp: Dp::PA12(gpioa.pa12.into_alternate()),
hclk: clocks.hclk(),
};
@ -94,7 +95,7 @@ pub fn setup(
spi2,
(
gpiob.pb10.into_alternate(),
NoMiso {},
NoMiso::new(),
gpiob.pb15.into_alternate(),
),
max5719::SPI_MODE,
@ -113,9 +114,9 @@ pub fn setup(
};
let pwm_chs = (
gpiob.pb6.into_alternate(),
gpiob.pb7.into_alternate(),
gpiob.pb8.into_alternate(),
Channel1::new(gpiob.pb6),
Channel2::new(gpiob.pb7),
Channel3::new(gpiob.pb8),
);
let (max_i_neg0, max_v0, max_i_pos0) =
tim4.pwm_hz(pwm_chs, PWM_FREQ_KHZ.convert(), &clocks).split();
@ -126,7 +127,7 @@ pub fn setup(
spi1,
(
gpiob.pb3.into_alternate(),
NoMiso {},
NoMiso::new(),
gpiob.pb5.into_alternate(),
),
ad5680::SPI_MODE,

View File

@ -9,6 +9,8 @@ use stm32f4xx_hal::{
pac::{interrupt, Interrupt, NVIC},
};
use usb_device::{
descriptor::lang_id,
device::StringDescriptors,
class_prelude::UsbBusAllocator,
prelude::{UsbDevice, UsbDeviceBuilder, UsbVidPid},
};
@ -27,16 +29,19 @@ pub struct State {
impl State {
pub fn setup(usb: USB) {
unsafe { BUS.write(Bus::new(usb, &mut EP_MEMORY)) };
unsafe { BUS.write(Bus::new(usb, EP_MEMORY.as_mut())) };
let str_descriptor = StringDescriptors::new(lang_id::LangID::EN)
.manufacturer("M-Labs")
.product("Kirdy");
let bus = unsafe { BUS.assume_init_ref() };
let serial = SerialPort::new(bus);
let dev = UsbDeviceBuilder::new(bus, UsbVidPid(0x16c0, 0x27dd))
.manufacturer("M-Labs")
.product("Kirdy")
.device_release(0x20)
.self_powered(true)
.device_class(usbd_serial::USB_CLASS_CDC)
.strings(&[str_descriptor]).unwrap()
.build();
free(|_| unsafe {

View File

@ -1,9 +1,9 @@
use serde::{Deserialize, Serialize};
use stm32f4xx_hal::{
gpio::{gpioa::*, gpiob::*, gpiod::*, Alternate, Input, Output, PushPull},
hal::{blocking::spi::Transfer, digital::{v2::OutputPin, v2::InputPin}},
gpio::{gpioa::*, gpiob::*, gpiod::*, Input, Output, PushPull},
hal::{spi::SpiBus, digital::{OutputPin, InputPin}},
pac::SPI2,
spi::{NoMiso, Spi, TransferModeNormal},
spi::Spi,
};
use uom::si::{
@ -26,7 +26,7 @@ pub trait ChannelPins {
type TerminationStatus: InputPin;
type Max5719Load: OutputPin;
type Max5719Cs: OutputPin;
type Max5719Spi: Transfer<u8>;
type Max5719Spi: SpiBus<u8>;
}
pub struct LdCtrlPhy<C: ChannelPins> {
@ -44,7 +44,7 @@ impl ChannelPins for Channel0 {
type Max5719Spi = DacSpi;
}
type DacSpi = Spi<SPI2, (PB10<Alternate<5>>, NoMiso, PB15<Alternate<5>>), TransferModeNormal>;
type DacSpi = Spi<SPI2>;
type DacCs = PD8<Output<PushPull>>;
type DacLoad = PB14<Output<PushPull>>;

View File

@ -1,28 +1,32 @@
use stm32f4xx_hal::timer::{CounterUs, Event};
use stm32f4xx_hal::timer::{Event, Counter};
use stm32f4xx_hal::pac::{interrupt, Interrupt, TIM2};
use stm32f4xx_hal::Listen;
use uom::si::{f32::ElectricCurrent, electric_current::ampere};
use fugit::{TimerDurationU32, KilohertzU32};
use core::marker::PhantomData;
use log::debug;
pub struct LdCurrentOutCtrlTimer {
target_i: ElectricCurrent,
now_i: ElectricCurrent,
timer: CounterUs<TIM2>,
timer: Counter<TIM2, FREQ>,
timeout: bool,
}
static mut LD_CURRENT_OUT_CTRL_TIMER: Option<LdCurrentOutCtrlTimer> = None;
pub const FREQ: u32 = 1000000;
/// This timer notifies the main loop to set the correct output current so that ld output current can ramp up/down slowly.
/// The current output slope is guaranteed to be larger but not necessarily equal to than the preset value.
impl LdCurrentOutCtrlTimer {
const TIME_STEP_MS: TimerDurationU32<1000000> = TimerDurationU32::from_rate(KilohertzU32::from_raw(1));
const TIME_STEP_MS: TimerDurationU32<FREQ> = TimerDurationU32::from_rate(KilohertzU32::from_raw(1));
const STEP_SIZE: ElectricCurrent = ElectricCurrent {
dimension: PhantomData,
units: PhantomData,
value: 0.0001,
};
pub fn setup(mut tim2: CounterUs<TIM2>) {
pub fn setup(mut tim2: Counter<TIM2, FREQ>) {
tim2.start(LdCurrentOutCtrlTimer::TIME_STEP_MS).unwrap();
unsafe {
cortex_m::peripheral::NVIC::unmask(Interrupt::TIM2);
@ -85,7 +89,10 @@ impl LdCurrentOutCtrlTimer {
pub fn clear_irq_flag() {
if let Some(ref mut ld_current_out_ctrl_timer ) = LdCurrentOutCtrlTimer::get() {
ld_current_out_ctrl_timer.timer.clear_interrupt(Event::Update);
match ld_current_out_ctrl_timer.timer.wait() {
Ok(_) => {}
Err(_) => {debug!("LD CTRL TIMER Interrupt is not present when clear_irq_flag() is called")}
}
}
}

View File

@ -1,7 +1,7 @@
use crate::device::sys_timer::sleep;
use fugit::MegahertzU32;
use stm32f4xx_hal::{
hal::{blocking::spi::Transfer, digital::v2::OutputPin},
hal::{spi::SpiBus, digital::OutputPin},
spi,
};
@ -14,13 +14,13 @@ pub const SPI_CLOCK_MHZ: MegahertzU32 = MegahertzU32::from_raw(21);
pub const MAX_VALUE: u32 = 0xFFFFF;
pub struct Dac<SPI: Transfer<u8>, S1: OutputPin, S2:OutputPin> {
pub struct Dac<SPI: SpiBus<u8>, S1: OutputPin, S2:OutputPin> {
spi: SPI,
cs_n: S1,
load_n: S2,
}
impl<SPI: Transfer<u8>, S1: OutputPin, S2: OutputPin> Dac<SPI, S1, S2> {
impl<SPI: SpiBus<u8>, S1: OutputPin, S2: OutputPin> Dac<SPI, S1, S2> {
pub fn new(spi: SPI, mut cs_n: S1, mut load_n: S2) -> Self {
let _ = cs_n.set_high();
let _ = load_n.set_high();
@ -30,7 +30,7 @@ impl<SPI: Transfer<u8>, S1: OutputPin, S2: OutputPin> Dac<SPI, S1, S2> {
fn write(&mut self, buf: &mut [u8]) -> Result<(), SPI::Error> {
let _ = self.cs_n.set_low();
self.spi.transfer(buf)?;
self.spi.write(buf)?;
let _ = self.cs_n.set_high();
sleep(1);
// must be high for >= 20 ns

View File

@ -9,6 +9,7 @@ mod laser_diode;
mod thermostat;
mod net;
use core::ptr::addr_of_mut;
use device::{boot::bootup, log_setup, sys_timer};
use crate::net::net::IpSettings;
use serde::{Deserialize, Serialize};
@ -65,6 +66,8 @@ fn main() -> ! {
let mut state = State::default();
let eth_data_buffer = unsafe { addr_of_mut!(ETH_DATA_BUFFER).as_mut().unwrap()};
loop {
wd.feed();
@ -147,9 +150,7 @@ fn main() -> ! {
net::net::for_each(|mut socket, id| {
if net::net::eth_is_socket_active(socket) && net::net::eth_is_socket_connected(socket) {
if active_report[id] {
unsafe {
net::cmd_handler::send_status_report(&mut ETH_DATA_BUFFER, &mut laser, &mut thermostat, &mut socket);
}
net::cmd_handler::send_status_report(eth_data_buffer, &mut laser, &mut thermostat, &mut socket);
}
}
else {
@ -168,14 +169,12 @@ fn main() -> ! {
if eth_is_pending {
net::net::for_each(|mut socket, id| {
if net::net::eth_is_socket_active(socket) && net::net::eth_is_socket_connected(socket){
unsafe{
let bytes = net::net::eth_recv(&mut ETH_DATA_BUFFER, socket);
if bytes != 0 {
info!("Ts: {:?}", sys_timer::now());
debug!("Number of bytes recv: {:?}", bytes);
// State Transition
net::cmd_handler::execute_cmd(&mut ETH_DATA_BUFFER, bytes, &mut socket, &mut laser, &mut thermostat, &mut state, &mut device_settings, &mut active_report[id]);
}
let bytes = net::net::eth_recv(eth_data_buffer, socket);
if bytes != 0 {
info!("Ts: {:?}", sys_timer::now());
debug!("Number of bytes recv: {:?}", bytes);
// State Transition
net::cmd_handler::execute_cmd(eth_data_buffer, bytes, &mut socket, &mut laser, &mut thermostat, &mut state, &mut device_settings, &mut active_report[id]);
}
}
})
@ -225,9 +224,7 @@ fn main() -> ! {
thermostat.power_down();
net::net::for_each(|mut socket, _| {
if net::net::eth_is_socket_active(socket) {
unsafe {
net::cmd_handler::send_response(&mut ETH_DATA_BUFFER, net::cmd_handler::ResponseEnum::HardReset, None, &mut socket);
}
net::cmd_handler::send_response(eth_data_buffer, net::cmd_handler::ResponseEnum::HardReset, None, &mut socket);
}
});
}

View File

@ -1,7 +1,7 @@
use crate::device::sys_timer::sleep;
use fugit::MegahertzU32;
use stm32f4xx_hal::{
hal::{blocking::spi::Transfer, digital::v2::OutputPin},
hal::{spi::SpiBus, digital::OutputPin},
spi,
};
@ -15,12 +15,12 @@ pub const SPI_CLOCK_MHZ: MegahertzU32 = MegahertzU32::from_raw(21);
pub const MAX_VALUE: u32 = 0x3FFFF;
pub struct Dac<SPI: Transfer<u8>, S: OutputPin> {
pub struct Dac<SPI: SpiBus<u8>, S: OutputPin> {
spi: SPI,
sync: S,
}
impl<SPI: Transfer<u8>, S: OutputPin> Dac<SPI, S> {
impl<SPI: SpiBus<u8>, S: OutputPin> Dac<SPI, S> {
pub fn new(spi: SPI, mut sync: S) -> Self {
let _ = sync.set_low();
@ -34,7 +34,7 @@ impl<SPI: Transfer<u8>, S: OutputPin> Dac<SPI, S> {
// must be high for >= 33 ns
sleep(1);
let _ = self.sync.set_low();
self.spi.transfer(buf)?;
self.spi.transfer_in_place(buf)?;
Ok(())
}

View File

@ -2,12 +2,12 @@ use core::fmt;
use log::{info, warn};
use stm32f4xx_hal::
{
spi::{Spi, TransferModeNormal},
spi::Spi,
pac::SPI3,
gpio::{PC10, PC11, PC12, PA15, Alternate, Output, PushPull},
gpio::{PA15, Output, PushPull},
hal::{
blocking::spi::Transfer,
digital::v2::OutputPin,
spi::SpiBus,
digital::OutputPin,
},
};
use uom::si::{
@ -21,17 +21,17 @@ use super::{
/// AD7172-2 implementation
///
/// [Manual](https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-2.pdf)
pub struct Adc<SPI: Transfer<u8>, NSS: OutputPin> {
pub struct Adc<SPI: SpiBus<u8>, NSS: OutputPin> {
spi: SPI,
nss: NSS,
checksum_mode: ChecksumMode,
}
type AdcSpi = Spi<SPI3, (PC10<Alternate<6>>, PC11<Alternate<6>>, PC12<Alternate<6>>), TransferModeNormal>;
type AdcSpi = Spi<SPI3>;
type AdcNss = PA15<Output<PushPull>>;
pub type AdcPhy = Adc<AdcSpi, AdcNss>;
impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS> {
impl<SPI: SpiBus<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS> {
pub fn new(spi: SPI, mut nss: NSS) -> Result<Self, SPI::Error> {
let _ = nss.set_high();
let mut adc = Adc {
@ -272,7 +272,7 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
pub fn reset(&mut self) -> Result<(), SPI::Error> {
let mut buf = [0xFFu8; 8];
let _ = self.nss.set_low();
let result = self.spi.transfer(&mut buf);
let result = self.spi.transfer_in_place(&mut buf);
let _ = self.nss.set_high();
result?;
Ok(())
@ -282,8 +282,8 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
let mut addr_buf = [addr];
let _ = self.nss.set_low();
let result = match self.spi.transfer(&mut addr_buf) {
Ok(_) => self.spi.transfer(reg_data),
let result = match self.spi.transfer_in_place(&mut addr_buf) {
Ok(_) => self.spi.transfer_in_place(reg_data),
Err(e) => Err(e),
};
let result = match (result, checksum) {
@ -291,7 +291,7 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
Ok(None),
(Ok(_), Some(checksum_out)) => {
let mut checksum_buf = [checksum_out; 1];
match self.spi.transfer(&mut checksum_buf) {
match self.spi.transfer_in_place(&mut checksum_buf) {
Ok(_) => Ok(Some(checksum_buf[0])),
Err(e) => Err(e),
}

View File

@ -1,12 +1,13 @@
use crate::thermostat::ad5680;
use core::ptr::addr_of_mut;
use fugit::KilohertzU32;
use stm32f4xx_hal::{
adc::{config::{self, AdcConfig}, Adc},
dma::{config::DmaConfig, PeripheralToMemory, Stream2, StreamsTuple, Transfer as DMA_Transfer},
gpio::{gpioa::*, gpiob::*, gpioc::*, Alternate, Analog, Output, PushPull},
hal::{self, blocking::spi::Transfer, digital::v2::OutputPin},
gpio::{gpioa::*, gpiob::*, gpioc::*, Analog, Output, PushPull},
hal::{self, spi::SpiBus, digital::OutputPin},
pac::{ADC1, ADC2, DMA2, SPI1, TIM4, Peripherals, NVIC},
spi::{NoMiso, Spi, TransferModeNormal},
spi::Spi,
timer::pwm::PwmChannel,
interrupt
};
@ -20,7 +21,7 @@ use uom::si::{
pub const PWM_FREQ_KHZ: KilohertzU32 = KilohertzU32::from_raw(20);
pub trait ChannelPins {
type DacSpi: Transfer<u8>;
type DacSpi: SpiBus<u8>;
type DacSync: OutputPin;
type ShdnPin: OutputPin;
type VRefPin;
@ -71,7 +72,7 @@ pub struct MAX1968PinSet<C: ChannelPins> {
pub max_i_neg: C::MAXINegPin,
}
type DacSpi = Spi<SPI1, (PB3<Alternate<5>>, NoMiso, PB5<Alternate<5>>), TransferModeNormal>;
type DacSpi = Spi<SPI1>;
type DacSync = PB4<Output<PushPull>>;
static mut DMA_TRANSFER_COMPLETE: bool = true;
@ -157,7 +158,7 @@ impl MAX1968 {
let dma = StreamsTuple::new(dma2);
let dma_adc : DMA_Transfer<Stream2<DMA2>, 1, Adc<ADC2>, PeripheralToMemory, &'static mut [u16; 16]>;
unsafe {
dma_adc = DMA_Transfer::init_peripheral_to_memory(dma.2, pins_adc2, &mut ADC2_FIRST_BUFFER, None, dma_config);
dma_adc = DMA_Transfer::init_peripheral_to_memory(dma.2, pins_adc2, addr_of_mut!(ADC2_FIRST_BUFFER).as_mut().unwrap(), None, dma_config);
NVIC::unmask(interrupt::DMA2_STREAM2);
}
@ -185,7 +186,7 @@ impl MAX1968 {
let buffer: &[u16; 16];
unsafe {
(buffer, _) = self.dma_adc
.next_transfer(&mut ADC2_LOCAL_BUFFER)
.next_transfer(addr_of_mut!(ADC2_LOCAL_BUFFER).as_mut().unwrap())
.unwrap();
}
@ -284,21 +285,34 @@ impl MAX1968 {
}
pub fn set_pwm(&mut self, pwm_pin: PwmPinsEnum, duty: f64, max_duty: f64) -> f64 {
fn set<P: hal::PwmPin<Duty = u16>>(pin: &mut P, duty: f64) -> f64 {
let max = pin.get_max_duty();
let value = ((duty * (max as f64)) as u16).min(max);
pin.set_duty(value);
pin.enable();
value as f64 / (max as f64)
fn duty_cycle_value(duty_cycle: f64, duty_cycle_limit: f64, max_value: u16) -> u16 {
((duty_cycle.min(duty_cycle_limit) * (max_value as f64)) as u16).min(max_value)
}
let duty = duty.min(max_duty);
let value: u16;
let max_value: u16;
match pwm_pin {
PwmPinsEnum::MaxV => set(&mut self.phy.max_v, duty),
PwmPinsEnum::MaxPosI => set(&mut self.phy.max_i_pos, duty),
PwmPinsEnum::MaxNegI => set(&mut self.phy.max_i_neg, duty),
PwmPinsEnum::MaxV => {
self.phy.max_v.enable();
max_value = self.phy.max_v.get_max_duty();
value = duty_cycle_value(duty, max_duty, max_value);
self.phy.max_v.set_duty(value);
}
PwmPinsEnum::MaxPosI => {
self.phy.max_i_pos.enable();
max_value = self.phy.max_i_pos.get_max_duty();
value = duty_cycle_value(duty, max_duty, max_value);
self.phy.max_i_pos.set_duty(value);
}
PwmPinsEnum::MaxNegI => {
self.phy.max_i_neg.enable();
max_value = self.phy.max_i_neg.get_max_duty();
value = duty_cycle_value(duty, max_duty, max_value);
self.phy.max_i_neg.set_duty(value);
}
}
return (value as f64) / (max_value as f64);
}
}