From a717630c535ba5417058a494c14795d50fe77c03 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 17 Mar 2021 20:16:13 +0100 Subject: [PATCH 01/16] Adding prototype PHY reset detection --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/bin/dual-iir.rs | 78 +++++++++--------------------- src/bin/lockin-external.rs | 78 +++++++++--------------------- src/hardware/configuration.rs | 6 +-- src/hardware/mod.rs | 2 + src/lib.rs | 1 + src/net/mod.rs | 89 +++++++++++++++++++++++++++++++++++ 8 files changed, 141 insertions(+), 117 deletions(-) create mode 100644 src/net/mod.rs diff --git a/Cargo.lock b/Cargo.lock index b435a6b..8b66fe7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,7 +707,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=main#56519012d7c6a382eaa0d7ecb26f2701771d9ce8" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/reset-support#a6db6579100987502563578fb386109ad08758a7" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index 6b14532..f1d88b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ git = "https://github.com/quartiq/minimq.git" [patch.crates-io.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -branch = "main" +branch = "feature/reset-support" [patch.crates-io.serde-json-core] git = "https://github.com/rust-embedded-community/serde-json-core.git" diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 4a27d48..6c391c7 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -4,17 +4,18 @@ use stm32h7xx_hal as hal; -use stabilizer::hardware; +use stabilizer::{hardware, net}; -use miniconf::{minimq, Miniconf, MqttInterface}; +use miniconf::Miniconf; use serde::Deserialize; use dsp::iir; use hardware::{ - Adc0Input, Adc1Input, AfeGain, CycleCounter, Dac0Output, Dac1Output, - NetworkStack, AFE0, AFE1, + Adc0Input, Adc1Input, AfeGain, Dac0Output, Dac1Output, AFE0, AFE1, }; +use net::{Action, MqttSettings}; + const SCALE: f32 = i16::MAX as _; // The number of cascaded IIR biquads per channel. Select 1 or 2! @@ -41,9 +42,7 @@ const APP: () = { afes: (AFE0, AFE1), adcs: (Adc0Input, Adc1Input), dacs: (Dac0Output, Dac1Output), - mqtt_interface: - MqttInterface, - clock: CycleCounter, + mqtt_settings: MqttSettings, // Format: iir_state[ch][cascade-no][coeff] #[init([[[0.; 5]; IIR_CASCADE_LENGTH]; 2])] @@ -57,23 +56,13 @@ const APP: () = { // Configure the microcontroller let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device); - let mqtt_interface = { - let mqtt_client = { - minimq::MqttClient::new( - hardware::design_parameters::MQTT_BROKER.into(), - "", - stabilizer.net.stack, - ) - .unwrap() - }; - - MqttInterface::new( - mqtt_client, - "dt/sinara/stabilizer", - Settings::default(), - ) - .unwrap() - }; + let mqtt_settings = MqttSettings::new( + stabilizer.net.stack, + "", + "dt/sinara/stabilizer", + stabilizer.net.phy, + stabilizer.cycle_counter, + ); // Enable ADC/DAC events stabilizer.adcs.0.start(); @@ -85,11 +74,10 @@ const APP: () = { stabilizer.adc_dac_timer.start(); init::LateResources { - mqtt_interface, afes: stabilizer.afes, adcs: stabilizer.adcs, dacs: stabilizer.dacs, - clock: stabilizer.cycle_counter, + mqtt_settings, } } @@ -138,44 +126,22 @@ const APP: () = { } } - #[idle(resources=[mqtt_interface, clock], spawn=[settings_update])] + #[idle(resources=[mqtt_settings], spawn=[settings_update])] fn idle(mut c: idle::Context) -> ! { - let clock = c.resources.clock; - loop { - let sleep = c.resources.mqtt_interface.lock(|interface| { - match interface.network_stack().poll(clock.current_ms()) { - Ok(updated) => !updated, - Err(err) => { - log::info!("Network error: {:?}", err); - false - } + match c.resources.mqtt_settings.lock(|settings| settings.update()) { + Some(Action::Sleep) => cortex_m::asm::wfi(), + Some(Action::UpdateSettings) => { + c.spawn.settings_update().unwrap() } - }); - - match c - .resources - .mqtt_interface - .lock(|interface| interface.update()) - { - Ok(update) => { - if update { - c.spawn.settings_update().unwrap(); - } else if sleep { - cortex_m::asm::wfi(); - } - } - Err(miniconf::MqttError::Network( - smoltcp_nal::NetworkError::NoIpAddress, - )) => {} - Err(error) => log::info!("Unexpected error: {:?}", error), + _ => {} } } } - #[task(priority = 1, resources=[mqtt_interface, afes, iir_ch])] + #[task(priority = 1, resources=[mqtt_settings, afes, iir_ch])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_interface.settings; + let settings = &c.resources.mqtt_settings.mqtt_interface.settings; // Update the IIR channels. c.resources.iir_ch.lock(|iir| *iir = settings.iir_ch); diff --git a/src/bin/lockin-external.rs b/src/bin/lockin-external.rs index 7d2db0e..bb84e91 100644 --- a/src/bin/lockin-external.rs +++ b/src/bin/lockin-external.rs @@ -4,16 +4,18 @@ use generic_array::typenum::U4; -use miniconf::{minimq, Miniconf, MqttInterface}; use serde::Deserialize; use dsp::{Accu, Complex, ComplexExt, Lockin, RPLL}; use stabilizer::hardware::{ - design_parameters, setup, Adc0Input, Adc1Input, AfeGain, CycleCounter, - Dac0Output, Dac1Output, InputStamper, NetworkStack, AFE0, AFE1, + design_parameters, setup, Adc0Input, Adc1Input, AfeGain, Dac0Output, + Dac1Output, InputStamper, AFE0, AFE1, }; +use miniconf::Miniconf; +use stabilizer::net::{Action, MqttSettings}; + #[derive(Copy, Clone, Debug, Deserialize, Miniconf)] enum Conf { PowerPhase, @@ -56,11 +58,7 @@ const APP: () = { afes: (AFE0, AFE1), adcs: (Adc0Input, Adc1Input), dacs: (Dac0Output, Dac1Output), - clock: CycleCounter, - - mqtt_interface: - MqttInterface, - + mqtt_settings: MqttSettings, settings: Settings, timestamper: InputStamper, @@ -73,21 +71,13 @@ const APP: () = { // Configure the microcontroller let (mut stabilizer, _pounder) = setup(c.core, c.device); - let mqtt_interface = { - let mqtt_client = minimq::MqttClient::new( - design_parameters::MQTT_BROKER.into(), - "", - stabilizer.net.stack, - ) - .unwrap(); - - MqttInterface::new( - mqtt_client, - "dt/sinara/lockin", - Settings::default(), - ) - .unwrap() - }; + let mqtt_settings = MqttSettings::new( + stabilizer.net.stack, + "", + "dt/sinara/lockin", + stabilizer.net.phy, + stabilizer.cycle_counter, + ); let settings = Settings::default(); @@ -118,10 +108,8 @@ const APP: () = { afes: stabilizer.afes, adcs: stabilizer.adcs, dacs: stabilizer.dacs, + mqtt_settings, timestamper: stabilizer.timestamper, - clock: stabilizer.cycle_counter, - - mqtt_interface, settings, @@ -202,44 +190,22 @@ const APP: () = { } } - #[idle(resources=[mqtt_interface, clock], spawn=[settings_update])] + #[idle(resources=[mqtt_settings], spawn=[settings_update])] fn idle(mut c: idle::Context) -> ! { - let clock = c.resources.clock; - loop { - let sleep = c.resources.mqtt_interface.lock(|interface| { - match interface.network_stack().poll(clock.current_ms()) { - Ok(updated) => !updated, - Err(err) => { - log::info!("Network error: {:?}", err); - false - } + match c.resources.mqtt_settings.lock(|settings| settings.update()) { + Some(Action::Sleep) => cortex_m::asm::wfi(), + Some(Action::UpdateSettings) => { + c.spawn.settings_update().unwrap() } - }); - - match c - .resources - .mqtt_interface - .lock(|interface| interface.update()) - { - Ok(update) => { - if update { - c.spawn.settings_update().unwrap(); - } else if sleep { - cortex_m::asm::wfi(); - } - } - Err(miniconf::MqttError::Network( - smoltcp_nal::NetworkError::NoIpAddress, - )) => {} - Err(error) => log::info!("Unexpected error: {:?}", error), + _ => {} } } } - #[task(priority = 1, resources=[mqtt_interface, settings, afes])] + #[task(priority = 1, resources=[mqtt_settings, settings, afes])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_interface.settings; + let settings = &c.resources.mqtt_settings.mqtt_interface.settings; c.resources.afes.0.set_gain(settings.afe[0]); c.resources.afes.1.set_gain(settings.afe[1]); diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index dfab1e0..74307dd 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -13,8 +13,8 @@ use embedded_hal::digital::v2::{InputPin, OutputPin}; use super::{ adc, afe, cycle_counter::CycleCounter, dac, design_parameters, - digital_input_stamper, eeprom, pounder, timers, DdsOutput, NetworkStack, - AFE0, AFE1, + digital_input_stamper, eeprom, pounder, timers, DdsOutput, EthernetPhy, + NetworkStack, AFE0, AFE1, }; pub struct NetStorage { @@ -56,7 +56,7 @@ impl NetStorage { /// The available networking devices on Stabilizer. pub struct NetworkDevices { pub stack: NetworkStack, - pub phy: ethernet::phy::LAN8742A, + pub phy: EthernetPhy, } /// The available hardware interfaces on Stabilizer. diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index cc7a34a..60e7768 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -40,6 +40,8 @@ pub type NetworkStack = smoltcp_nal::NetworkStack< hal::ethernet::EthernetDMA<'static>, >; +pub type EthernetPhy = hal::ethernet::phy::LAN8742A; + pub use configuration::{setup, PounderDevices, StabilizerDevices}; #[inline(never)] diff --git a/src/lib.rs b/src/lib.rs index 0c9bf2a..975b08f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,3 +5,4 @@ extern crate log; pub mod hardware; +pub mod net; diff --git a/src/net/mod.rs b/src/net/mod.rs new file mode 100644 index 0000000..a996555 --- /dev/null +++ b/src/net/mod.rs @@ -0,0 +1,89 @@ +use crate::hardware::{ + design_parameters::MQTT_BROKER, CycleCounter, EthernetPhy, NetworkStack, +}; + +use miniconf::{minimq, MqttInterface}; + +pub enum Action { + Sleep, + UpdateSettings, +} + +pub struct MqttSettings +where + S: miniconf::Miniconf + Default, +{ + pub mqtt_interface: MqttInterface, + clock: CycleCounter, + phy: EthernetPhy, + network_was_reset: bool, +} + +impl MqttSettings +where + S: miniconf::Miniconf + Default, +{ + pub fn new( + stack: NetworkStack, + client_id: &str, + prefix: &str, + phy: EthernetPhy, + clock: CycleCounter, + ) -> Self { + let mqtt_interface = { + let mqtt_client = { + minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack) + .unwrap() + }; + + MqttInterface::new(mqtt_client, prefix, S::default()).unwrap() + }; + + Self { + mqtt_interface, + clock, + phy, + network_was_reset: false, + } + } + + pub fn update(&mut self) -> Option { + let now = self.clock.current_ms(); + + let sleep = match self.mqtt_interface.network_stack().poll(now) { + Ok(updated) => !updated, + Err(err) => { + log::info!("Network error: {:?}", err); + false + } + }; + + // If the PHY indicates there's no more ethernet link, reset the network stack and close all + // sockets. + if self.phy.poll_link() == false { + // Only reset the network stack once per link reconnection. This prevents us from + // sending an excessive number of DHCP requests. + if !self.network_was_reset { + self.network_was_reset = true; + self.mqtt_interface.network_stack().reset(); + } + } else { + self.network_was_reset = false; + } + + match self.mqtt_interface.update() { + Ok(true) => Some(Action::UpdateSettings), + Ok(false) if sleep => Some(Action::Sleep), + Ok(_) => None, + + Err(miniconf::MqttError::Network( + smoltcp_nal::NetworkError::NoIpAddress, + )) => None, + + Err(error) => { + log::info!("Unexpected error: {:?}", error); + None + } + } + } +} From 9459152f6f71122a3a97565d85252c32af81a469 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 24 Mar 2021 13:40:17 +0100 Subject: [PATCH 02/16] Updating dependencies --- Cargo.lock | 8 ++++---- Cargo.toml | 3 +-- src/net/mod.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b66fe7..d203a3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,9 +390,9 @@ dependencies = [ [[package]] name = "managed" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" +checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" [[package]] name = "matrixmultiply" @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "smoltcp" version = "0.7.0" -source = "git+https://github.com/ryan-summers/smoltcp.git?branch=feature/dhcp-lease-updates#e3954ebb8149341c52a4992e037d4b5109387910" +source = "git+https://github.com/smoltcp-rs/smoltcp.git#1bff999a6f3f7adf623d837ea96cc807e1b3a470" dependencies = [ "bitflags", "byteorder", @@ -707,7 +707,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/reset-support#a6db6579100987502563578fb386109ad08758a7" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/reset-support#c43e751afe3c14aac153fa4425231270dbfd918b" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index f1d88b3..fe610d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,8 +63,7 @@ git = "https://github.com/rust-embedded-community/serde-json-core.git" branch = "master" [patch.crates-io.smoltcp] -git = "https://github.com/ryan-summers/smoltcp.git" -branch = "feature/dhcp-lease-updates" +git = "https://github.com/smoltcp-rs/smoltcp.git" [dependencies.mcp23017] git = "https://github.com/mrd0ll4r/mcp23017.git" diff --git a/src/net/mod.rs b/src/net/mod.rs index a996555..1939703 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -65,7 +65,7 @@ where // sending an excessive number of DHCP requests. if !self.network_was_reset { self.network_was_reset = true; - self.mqtt_interface.network_stack().reset(); + self.mqtt_interface.network_stack().handle_link_reset(); } } else { self.network_was_reset = false; From 5e448f284bde0b7c43a85b278266bb6d7298123e Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 24 Mar 2021 13:48:34 +0100 Subject: [PATCH 03/16] Updating net module --- src/bin/dual-iir.rs | 2 +- src/bin/lockin-external.rs | 2 +- src/net/mod.rs | 35 +++++++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 6c391c7..0e2215b 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -141,7 +141,7 @@ const APP: () = { #[task(priority = 1, resources=[mqtt_settings, afes, iir_ch])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_settings.mqtt_interface.settings; + let settings = &c.resources.mqtt_settings.mqtt.settings; // Update the IIR channels. c.resources.iir_ch.lock(|iir| *iir = settings.iir_ch); diff --git a/src/bin/lockin-external.rs b/src/bin/lockin-external.rs index bb84e91..b62ea42 100644 --- a/src/bin/lockin-external.rs +++ b/src/bin/lockin-external.rs @@ -205,7 +205,7 @@ const APP: () = { #[task(priority = 1, resources=[mqtt_settings, settings, afes])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_settings.mqtt_interface.settings; + let settings = &c.resources.mqtt_settings.mqtt.settings; c.resources.afes.0.set_gain(settings.afe[0]); c.resources.afes.1.set_gain(settings.afe[1]); diff --git a/src/net/mod.rs b/src/net/mod.rs index 1939703..f38f3d9 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -4,16 +4,21 @@ use crate::hardware::{ use miniconf::{minimq, MqttInterface}; +/// Potential actions for firmware to take. pub enum Action { + /// Indicates that firmware can sleep for the next event. Sleep, + + /// Indicates that settings have updated and firmware needs to propogate changes. UpdateSettings, } +/// MQTT settings interface. pub struct MqttSettings where S: miniconf::Miniconf + Default, { - pub mqtt_interface: MqttInterface, + pub mqtt: MqttInterface, clock: CycleCounter, phy: EthernetPhy, network_was_reset: bool, @@ -23,6 +28,14 @@ impl MqttSettings where S: miniconf::Miniconf + Default, { + /// Construct a new MQTT settings interface. + /// + /// # Args + /// * `stack` - The network stack to use for communication. + /// * `client_id` - The ID of the MQTT client. May be an empty string for auto-assigning. + /// * `prefix` - The MQTT device prefix to use for this device. + /// * `phy` - The PHY driver for querying the link state. + /// * `clock` - The clock to utilize for querying the current system time. pub fn new( stack: NetworkStack, client_id: &str, @@ -30,7 +43,7 @@ where phy: EthernetPhy, clock: CycleCounter, ) -> Self { - let mqtt_interface = { + let mqtt = { let mqtt_client = { minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack) .unwrap() @@ -40,17 +53,22 @@ where }; Self { - mqtt_interface, + mqtt, clock, phy, network_was_reset: false, } } + /// Update the MQTT interface and service the network + /// + /// # Returns + /// An option containing an action that should be completed as a result of network servicing. pub fn update(&mut self) -> Option { let now = self.clock.current_ms(); - let sleep = match self.mqtt_interface.network_stack().poll(now) { + // First, service the network stack to process and inbound and outbound traffic. + let sleep = match self.mqtt.network_stack().poll(now) { Ok(updated) => !updated, Err(err) => { log::info!("Network error: {:?}", err); @@ -58,20 +76,21 @@ where } }; - // If the PHY indicates there's no more ethernet link, reset the network stack and close all - // sockets. + // If the PHY indicates there's no more ethernet link, reset the DHCP server in the network + // stack. if self.phy.poll_link() == false { // Only reset the network stack once per link reconnection. This prevents us from // sending an excessive number of DHCP requests. if !self.network_was_reset { self.network_was_reset = true; - self.mqtt_interface.network_stack().handle_link_reset(); + self.mqtt.network_stack().handle_link_reset(); } } else { self.network_was_reset = false; } - match self.mqtt_interface.update() { + // Finally, service the MQTT interface and handle any necessary messages. + match self.mqtt.update() { Ok(true) => Some(Action::UpdateSettings), Ok(false) if sleep => Some(Action::Sleep), Ok(_) => None, From d0c1bef55f41e201bb2d6c5f41086603ae75dd40 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 8 Apr 2021 13:37:24 +0200 Subject: [PATCH 04/16] Updating dependencies --- Cargo.lock | 7 +------ Cargo.toml | 5 +---- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3aa8999..83f9171 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -710,7 +710,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/reset-support#c43e751afe3c14aac153fa4425231270dbfd918b" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=db2d6c6#db2d6c6ac538a128e63da2f166a0907f4c99989a" dependencies = [ "embedded-nal", "heapless 0.6.1", @@ -835,8 +835,3 @@ name = "wasi" version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - -[[patch.unused]] -name = "smoltcp" -version = "0.7.0" -source = "git+https://github.com/smoltcp-rs/smoltcp.git#09f941851ded868b759e7db067abd67f2fe136a6" diff --git a/Cargo.toml b/Cargo.toml index 144444f..63ea340 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,15 +60,12 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -branch = "feature/reset-support" +rev = "db2d6c6" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" rev = "933687c2e4b" -[patch.crates-io.smoltcp] -git = "https://github.com/smoltcp-rs/smoltcp.git" - [patch.crates-io.serde-json-core] git = "https://github.com/rust-embedded-community/serde-json-core.git" rev = "ee06ac91bc" From 164fd5969d1b1cc86497853872fb1d8e56700669 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 8 Apr 2021 13:56:57 +0200 Subject: [PATCH 05/16] Updating smoltcp-nal --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83f9171..6224d53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -710,7 +710,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=db2d6c6#db2d6c6ac538a128e63da2f166a0907f4c99989a" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=d200d4e#d200d4eb20cdad42ed30a77f9c1690f43361d9e8" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index 63ea340..dcdffea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -rev = "db2d6c6" +rev = "d200d4e" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" From c24eb17d1eb469a03a3538638d1fa660b3180fde Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 8 Apr 2021 14:02:56 +0200 Subject: [PATCH 06/16] Using main branch commit --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6224d53..f77e0bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -710,7 +710,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=d200d4e#d200d4eb20cdad42ed30a77f9c1690f43361d9e8" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=7572183#757218316620e074405bc38ff5502ef17a8a3499" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index dcdffea..0c4ab0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -rev = "d200d4e" +rev = "7572183" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" From 1b4d31dbd9ce1432149685eb993f9971df59bd70 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 8 Apr 2021 15:28:11 +0200 Subject: [PATCH 07/16] Updating NAL to support TCP port randomization --- Cargo.lock | 9 ++++++++- Cargo.toml | 2 +- src/hardware/configuration.rs | 24 ++++++++++++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f77e0bd..0c99862 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -437,6 +437,12 @@ dependencies = [ "heapless 0.6.1", ] +[[package]] +name = "nanorand" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1378b66f7c93a1c0f8464a19bf47df8795083842e5090f4b7305973d5a22d0" + [[package]] name = "nb" version = "0.1.3" @@ -710,10 +716,11 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=7572183#757218316620e074405bc38ff5502ef17a8a3499" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/random-port#462adc56a8cc95bc1324f6d96fdbe82e85ca6d36" dependencies = [ "embedded-nal", "heapless 0.6.1", + "nanorand", "smoltcp", ] diff --git a/Cargo.toml b/Cargo.toml index 0c4ab0d..87a0e2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -rev = "7572183" +branch = "feature/random-port" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index 74307dd..8a6ec0d 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -594,13 +594,25 @@ pub fn setup( ) }; + let random_seed = { + let mut rng = + device.RNG.constrain(ccdr.peripheral.RNG, &ccdr.clocks); + let mut data = [0u8; 4]; + rng.fill(&mut data).unwrap(); + data + }; + + let mut stack = smoltcp_nal::NetworkStack::new( + interface, + sockets, + &handles, + Some(dhcp_client), + ); + + stack.seed_random_port(&random_seed); + NetworkDevices { - stack: smoltcp_nal::NetworkStack::new( - interface, - sockets, - &handles, - Some(dhcp_client), - ), + stack, phy: lan8742a, } }; From 033420b9346e376cc7ec1ccdbc8ee061f3309cbe Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 13 Apr 2021 15:38:30 +0200 Subject: [PATCH 08/16] Adding custom identifier prefix calculations --- src/bin/dual-iir.rs | 5 +++- src/bin/lockin-external.rs | 7 +++++- src/hardware/configuration.rs | 4 +++- src/hardware/design_parameters.rs | 2 +- src/net/mod.rs | 40 +++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 0e2215b..b0072af 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -59,7 +59,10 @@ const APP: () = { let mqtt_settings = MqttSettings::new( stabilizer.net.stack, "", - "dt/sinara/stabilizer", + &net::get_device_prefix( + env!("CARGO_BIN_NAME"), + stabilizer.net.mac_address, + ), stabilizer.net.phy, stabilizer.cycle_counter, ); diff --git a/src/bin/lockin-external.rs b/src/bin/lockin-external.rs index b62ea42..34a3d5b 100644 --- a/src/bin/lockin-external.rs +++ b/src/bin/lockin-external.rs @@ -8,6 +8,8 @@ use serde::Deserialize; use dsp::{Accu, Complex, ComplexExt, Lockin, RPLL}; +use stabilizer::net; + use stabilizer::hardware::{ design_parameters, setup, Adc0Input, Adc1Input, AfeGain, Dac0Output, Dac1Output, InputStamper, AFE0, AFE1, @@ -74,7 +76,10 @@ const APP: () = { let mqtt_settings = MqttSettings::new( stabilizer.net.stack, "", - "dt/sinara/lockin", + &net::get_device_prefix( + env!("CARGO_BIN_NAME"), + stabilizer.net.mac_address, + ), stabilizer.net.phy, stabilizer.cycle_counter, ); diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index 82158f3..fdde1f4 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -57,6 +57,7 @@ impl NetStorage { pub struct NetworkDevices { pub stack: NetworkStack, pub phy: EthernetPhy, + pub mac_address: smoltcp::wire::EthernetAddress, } /// The available hardware interfaces on Stabilizer. @@ -544,7 +545,7 @@ pub fn setup( smoltcp::iface::NeighborCache::new(&mut store.neighbor_cache[..]); let interface = smoltcp::iface::EthernetInterfaceBuilder::new(eth_dma) - .ethernet_addr(mac_addr) + .ethernet_addr(mac_addr.clone()) .neighbor_cache(neighbor_cache) .ip_addrs(&mut store.ip_addrs[..]) .routes(routes) @@ -599,6 +600,7 @@ pub fn setup( Some(dhcp_client), ), phy: lan8742a, + mac_address: mac_addr, } }; diff --git a/src/hardware/design_parameters.rs b/src/hardware/design_parameters.rs index 9a4279b..0ae4c35 100644 --- a/src/hardware/design_parameters.rs +++ b/src/hardware/design_parameters.rs @@ -51,4 +51,4 @@ pub const SAMPLE_BUFFER_SIZE_LOG2: u8 = 3; pub const SAMPLE_BUFFER_SIZE: usize = 1 << SAMPLE_BUFFER_SIZE_LOG2; // The MQTT broker IPv4 address -pub const MQTT_BROKER: [u8; 4] = [10, 34, 16, 10]; +pub const MQTT_BROKER: [u8; 4] = [10, 35, 16, 10]; diff --git a/src/net/mod.rs b/src/net/mod.rs index f38f3d9..3ad21b6 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -2,6 +2,10 @@ use crate::hardware::{ design_parameters::MQTT_BROKER, CycleCounter, EthernetPhy, NetworkStack, }; +use core::fmt::Write; + +use heapless::{consts, String}; + use miniconf::{minimq, MqttInterface}; /// Potential actions for firmware to take. @@ -106,3 +110,39 @@ where } } } + +/// Get the MQTT prefix of a device. +/// +/// # Args +/// * `app` - The name of the application that is executing. +/// * `mac` - The ethernet MAC address of the device. +/// +/// # Returns +/// The MQTT prefix used for this device. +pub fn get_device_prefix( + app: &str, + mac: smoltcp_nal::smoltcp::wire::EthernetAddress, +) -> String { + let mac_string = { + let mut mac_string: String = String::new(); + let mac = mac.as_bytes(); + + // Note(unwrap): 32-bytes is guaranteed to be valid for any mac address, as the address has + // a fixed length. + write!( + &mut mac_string, + "{:02x}-{:02x}-{:02x}-{:02x}-{:02x}-{:02x}", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] + ) + .unwrap(); + + mac_string + }; + + // Note(unwrap): The mac address + binary name must be short enough to fit into this string. If + // they are defined too long, this will panic and the device will fail to boot. + let mut prefix: String = String::new(); + write!(&mut prefix, "dt/sinara/{}/{}", app, mac_string).unwrap(); + + prefix +} From d333a25301a53e2b8d0347db1bbd7779f734feb4 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 15 Apr 2021 12:24:49 +0200 Subject: [PATCH 09/16] Updating dependency --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0c99862..ee321ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/random-port#462adc56a8cc95bc1324f6d96fdbe82e85ca6d36" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/random-port#b5b050b135f3fe89e1a33d7d9f1d3d8570132f3c" dependencies = [ "embedded-nal", "heapless 0.6.1", From 1a08634dcb90634141c5f2bb966174b7905423fe Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 19 Apr 2021 12:17:41 +0200 Subject: [PATCH 10/16] Renaming interface to avoid confusion --- src/bin/dual-iir.rs | 20 ++++++++++++-------- src/bin/lockin-external.rs | 20 ++++++++++++-------- src/net/mod.rs | 11 ++++++----- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index cac6f45..8f07cf1 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -13,7 +13,7 @@ use hardware::{ InputPin, AFE0, AFE1, }; -use net::{Action, MqttSettings}; +use net::{Action, MiniconfInterface}; const SCALE: f32 = i16::MAX as _; @@ -46,7 +46,7 @@ const APP: () = { digital_input1: DigitalInput1, adcs: (Adc0Input, Adc1Input), dacs: (Dac0Output, Dac1Output), - mqtt_settings: MqttSettings, + mqtt_config: MiniconfInterface, // Format: iir_state[ch][cascade-no][coeff] #[init([[[0.; 5]; IIR_CASCADE_LENGTH]; 2])] @@ -59,7 +59,7 @@ const APP: () = { // Configure the microcontroller let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device); - let mqtt_settings = MqttSettings::new( + let mqtt_config = MiniconfInterface::new( stabilizer.net.stack, "", "dt/sinara/stabilizer", @@ -83,7 +83,7 @@ const APP: () = { afes: stabilizer.afes, adcs: stabilizer.adcs, dacs: stabilizer.dacs, - mqtt_settings, + mqtt_config, digital_input1: stabilizer.digital_inputs.1, settings: Settings::default(), } @@ -140,10 +140,14 @@ const APP: () = { } } - #[idle(resources=[mqtt_settings], spawn=[settings_update])] + #[idle(resources=[mqtt_config], spawn=[settings_update])] fn idle(mut c: idle::Context) -> ! { loop { - match c.resources.mqtt_settings.lock(|settings| settings.update()) { + match c + .resources + .mqtt_config + .lock(|config_interface| config_interface.update()) + { Some(Action::Sleep) => cortex_m::asm::wfi(), Some(Action::UpdateSettings) => { c.spawn.settings_update().unwrap() @@ -153,9 +157,9 @@ const APP: () = { } } - #[task(priority = 1, resources=[mqtt_settings, afes, settings])] + #[task(priority = 1, resources=[mqtt_config, afes, settings])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_settings.mqtt.settings; + let settings = &c.resources.mqtt_config.mqtt.settings; // Update the IIR channels. c.resources.settings.lock(|current| *current = *settings); diff --git a/src/bin/lockin-external.rs b/src/bin/lockin-external.rs index b62ea42..36bd882 100644 --- a/src/bin/lockin-external.rs +++ b/src/bin/lockin-external.rs @@ -14,7 +14,7 @@ use stabilizer::hardware::{ }; use miniconf::Miniconf; -use stabilizer::net::{Action, MqttSettings}; +use stabilizer::net::{Action, MiniconfInterface}; #[derive(Copy, Clone, Debug, Deserialize, Miniconf)] enum Conf { @@ -58,7 +58,7 @@ const APP: () = { afes: (AFE0, AFE1), adcs: (Adc0Input, Adc1Input), dacs: (Dac0Output, Dac1Output), - mqtt_settings: MqttSettings, + mqtt_config: MiniconfInterface, settings: Settings, timestamper: InputStamper, @@ -71,7 +71,7 @@ const APP: () = { // Configure the microcontroller let (mut stabilizer, _pounder) = setup(c.core, c.device); - let mqtt_settings = MqttSettings::new( + let mqtt_config = MiniconfInterface::new( stabilizer.net.stack, "", "dt/sinara/lockin", @@ -108,7 +108,7 @@ const APP: () = { afes: stabilizer.afes, adcs: stabilizer.adcs, dacs: stabilizer.dacs, - mqtt_settings, + mqtt_config, timestamper: stabilizer.timestamper, settings, @@ -190,10 +190,14 @@ const APP: () = { } } - #[idle(resources=[mqtt_settings], spawn=[settings_update])] + #[idle(resources=[mqtt_config], spawn=[settings_update])] fn idle(mut c: idle::Context) -> ! { loop { - match c.resources.mqtt_settings.lock(|settings| settings.update()) { + match c + .resources + .mqtt_config + .lock(|config_interface| config_interface.update()) + { Some(Action::Sleep) => cortex_m::asm::wfi(), Some(Action::UpdateSettings) => { c.spawn.settings_update().unwrap() @@ -203,9 +207,9 @@ const APP: () = { } } - #[task(priority = 1, resources=[mqtt_settings, settings, afes])] + #[task(priority = 1, resources=[mqtt_config, settings, afes])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_settings.mqtt.settings; + let settings = &c.resources.mqtt_config.mqtt.settings; c.resources.afes.0.set_gain(settings.afe[0]); c.resources.afes.1.set_gain(settings.afe[1]); diff --git a/src/net/mod.rs b/src/net/mod.rs index f38f3d9..23d712d 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -2,7 +2,7 @@ use crate::hardware::{ design_parameters::MQTT_BROKER, CycleCounter, EthernetPhy, NetworkStack, }; -use miniconf::{minimq, MqttInterface}; +use miniconf::minimq; /// Potential actions for firmware to take. pub enum Action { @@ -14,17 +14,17 @@ pub enum Action { } /// MQTT settings interface. -pub struct MqttSettings +pub struct MiniconfInterface where S: miniconf::Miniconf + Default, { - pub mqtt: MqttInterface, + pub mqtt: miniconf::MqttInterface, clock: CycleCounter, phy: EthernetPhy, network_was_reset: bool, } -impl MqttSettings +impl MiniconfInterface where S: miniconf::Miniconf + Default, { @@ -49,7 +49,8 @@ where .unwrap() }; - MqttInterface::new(mqtt_client, prefix, S::default()).unwrap() + miniconf::MqttInterface::new(mqtt_client, prefix, S::default()) + .unwrap() }; Self { From b2285d1ba2f0c9eba38e83aec33cefd88d7a4b93 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 19 Apr 2021 15:55:02 +0200 Subject: [PATCH 11/16] Updating dependency revision --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee321ff..970506d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/random-port#b5b050b135f3fe89e1a33d7d9f1d3d8570132f3c" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=8468f11#8468f11abacd7aba82454e6904df19c1d1ab91bb" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index 87a0e2e..f4db4d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -branch = "feature/random-port" +rev = "8468f11" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" From dfda6b6d751e168990cf0ea4e5d2ad765299293e Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 19 Apr 2021 15:57:52 +0200 Subject: [PATCH 12/16] Reverting unintended change --- src/hardware/design_parameters.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/design_parameters.rs b/src/hardware/design_parameters.rs index 0ae4c35..9a4279b 100644 --- a/src/hardware/design_parameters.rs +++ b/src/hardware/design_parameters.rs @@ -51,4 +51,4 @@ pub const SAMPLE_BUFFER_SIZE_LOG2: u8 = 3; pub const SAMPLE_BUFFER_SIZE: usize = 1 << SAMPLE_BUFFER_SIZE_LOG2; // The MQTT broker IPv4 address -pub const MQTT_BROKER: [u8; 4] = [10, 35, 16, 10]; +pub const MQTT_BROKER: [u8; 4] = [10, 34, 16, 10]; From 42999e8b2ad54d27d228a6026e10b68d1a600f4e Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 20 Apr 2021 10:44:44 +0200 Subject: [PATCH 13/16] Updating ping deadline --- hitl/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hitl/run.sh b/hitl/run.sh index 483a8a3..0203071 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -21,7 +21,7 @@ cargo flash --elf target/thumbv7em-none-eabihf/release/dual-iir --chip STM32H743 # * DHCP is functional and an IP has been acquired # * Stabilizer's network is functioning as intended # * The stabilizer application is operational -ping -c 5 -w 20 stabilizer-hitl +ping -c 5 -w 45 stabilizer-hitl # Test the MQTT interface. python3 miniconf.py dt/sinara/stabilizer afe/0='"G2"' From bc5e532655e358300b27c24987479ecd5b2edea8 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 20 Apr 2021 12:13:40 +0200 Subject: [PATCH 14/16] Adding sleep to HITL run --- hitl/run.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hitl/run.sh b/hitl/run.sh index 483a8a3..947a0d3 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -17,11 +17,13 @@ python3 -m pip install -r requirements.txt cargo flash --elf target/thumbv7em-none-eabihf/release/dual-iir --chip STM32H743ZITx +sleep 30 + # Test pinging Stabilizer. This exercises that: # * DHCP is functional and an IP has been acquired # * Stabilizer's network is functioning as intended # * The stabilizer application is operational -ping -c 5 -w 20 stabilizer-hitl +ping -c 5 -w 45 stabilizer-hitl # Test the MQTT interface. python3 miniconf.py dt/sinara/stabilizer afe/0='"G2"' From 7106b7d585e220754aef5a964681b304eec71334 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 20 Apr 2021 13:21:02 +0200 Subject: [PATCH 15/16] Adding comment, reverting change --- hitl/run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hitl/run.sh b/hitl/run.sh index 947a0d3..41d59a0 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -17,13 +17,14 @@ python3 -m pip install -r requirements.txt cargo flash --elf target/thumbv7em-none-eabihf/release/dual-iir --chip STM32H743ZITx +# Before attempting to ping the device, sleep to allow Stabilizer to boot. sleep 30 # Test pinging Stabilizer. This exercises that: # * DHCP is functional and an IP has been acquired # * Stabilizer's network is functioning as intended # * The stabilizer application is operational -ping -c 5 -w 45 stabilizer-hitl +ping -c 5 -w 20 stabilizer-hitl # Test the MQTT interface. python3 miniconf.py dt/sinara/stabilizer afe/0='"G2"' From 65073d11b9e6e6196481c62e812dfe7cd0bd924f Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 20 Apr 2021 13:37:49 +0200 Subject: [PATCH 16/16] Updating code after review --- hitl/run.sh | 6 +++--- src/hardware/configuration.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hitl/run.sh b/hitl/run.sh index 40f9039..2af4732 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -24,9 +24,9 @@ sleep 30 # * DHCP is functional and an IP has been acquired # * Stabilizer's network is functioning as intended # * The stabilizer application is operational -ping -c 5 -w 45 stabilizer-hitl +ping -c 5 -w 20 stabilizer-hitl # Test the MQTT interface. -python3 miniconf.py dt/sinara/stabilizer afe/0='"G2"' -python3 miniconf.py dt/sinara/stabilizer afe/0='"G1"' iir_ch/0/0=\ +python3 miniconf.py dt/sinara/dual-iir/04-91-62-d9-7e-5f afe/0='"G2"' +python3 miniconf.py dt/sinara/dual-iir/04-91-62-d9-7e-5f afe/0='"G1"' iir_ch/0/0=\ '{"y_min": -32767, "y_max": 32767, "y_offset": 0, "ba": [1.0, 0, 0, 0, 0]}' diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index 630fe12..f453c11 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -552,7 +552,7 @@ pub fn setup( smoltcp::iface::NeighborCache::new(&mut store.neighbor_cache[..]); let interface = smoltcp::iface::EthernetInterfaceBuilder::new(eth_dma) - .ethernet_addr(mac_addr.clone()) + .ethernet_addr(mac_addr) .neighbor_cache(neighbor_cache) .ip_addrs(&mut store.ip_addrs[..]) .routes(routes)