From c6859d956ef2a2b7944ef92f05a6060ca341f293 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Sat, 20 Jun 2020 16:43:07 +0200 Subject: [PATCH 1/4] Allowing pounder to not be present --- src/main.rs | 110 ++++++++++++++++++++++++++++++--------------- src/pounder/mod.rs | 1 + 2 files changed, 75 insertions(+), 36 deletions(-) diff --git a/src/main.rs b/src/main.rs index 722f554..9b67978 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,7 +180,7 @@ const APP: () = { eth_mac: ethernet::EthernetMAC, mac_addr: net::wire::EthernetAddress, - pounder: pounder::PounderDevices, + pounder: Option>, #[init([[0.; 5]; 2])] iir_state: [iir::IIRState; 2], @@ -376,7 +376,18 @@ const APP: () = { fp_led_2.set_low().unwrap(); fp_led_3.set_low().unwrap(); - let pounder_devices = { + // Attempt to instantiate the I2C GPIO expander on pounder. + let pounder_gpio_expander = { + let sda = gpiob.pb7.into_alternate_af4().set_open_drain(); + let scl = gpiob.pb8.into_alternate_af4().set_open_drain(); + let i2c1 = dp.I2C1.i2c((scl, sda), 100.khz(), &clocks); + mcp23017::MCP23017::default(i2c1) + }; + + // If instantiating the GPIO expander was successful, we were able to communicate with the + // IO expander and pounder is available. If the GPIO expander did not communicate with I2C, + // we will assume that pounder is not available. + let pounder_devices = if let Ok(io_expander) = pounder_gpio_expander { let ad9959 = { let qspi_interface = { // Instantiate the QUADSPI pins and peripheral interface. @@ -435,13 +446,6 @@ const APP: () = { .unwrap() }; - let io_expander = { - let sda = gpiob.pb7.into_alternate_af4().set_open_drain(); - let scl = gpiob.pb8.into_alternate_af4().set_open_drain(); - let i2c1 = dp.I2C1.i2c((scl, sda), 100.khz(), &clocks); - mcp23017::MCP23017::default(i2c1).unwrap() - }; - let spi = { let spi_mosi = gpiod .pd7 @@ -489,16 +493,20 @@ const APP: () = { let adc1_in_p = gpiof.pf11.into_analog(); let adc2_in_p = gpiof.pf14.into_analog(); - pounder::PounderDevices::new( - io_expander, - ad9959, - spi, - adc1, - adc2, - adc1_in_p, - adc2_in_p, + Some( + pounder::PounderDevices::new( + io_expander, + ad9959, + spi, + adc1, + adc2, + adc1_in_p, + adc2_in_p, + ) + .unwrap(), ) - .unwrap() + } else { + None }; let mut eeprom_i2c = { @@ -746,23 +754,38 @@ const APP: () = { "stabilizer/afe1/gain": (|| c.resources.afe1.get_gain()), "stabilizer/afe2/gain": (|| c.resources.afe2.get_gain()), "pounder/in0": (|| { - c.resources.pounder.get_input_channel_state( - pounder::Channel::In0) + match c.resources.pounder { + Some(pounder) => + pounder.get_input_channel_state(pounder::Channel::In0), + _ => Err(pounder::Error::Access), + } }), "pounder/in1": (|| { - c.resources.pounder.get_input_channel_state( - pounder::Channel::In1) + match c.resources.pounder { + Some(pounder) => + pounder.get_input_channel_state(pounder::Channel::In1), + _ => Err(pounder::Error::Access), + } }), "pounder/out0": (|| { - c.resources.pounder.get_output_channel_state( - pounder::Channel::Out0) + match c.resources.pounder { + Some(pounder) => + pounder.get_output_channel_state(pounder::Channel::Out0), + _ => Err(pounder::Error::Access), + } }), "pounder/out1": (|| { - c.resources.pounder.get_output_channel_state( - pounder::Channel::Out1) + match c.resources.pounder { + Some(pounder) => + pounder.get_output_channel_state(pounder::Channel::Out1), + _ => Err(pounder::Error::Access), + } }), "pounder/dds/clock": (|| { - c.resources.pounder.get_dds_clock_config() + match c.resources.pounder { + Some(pounder) => pounder.get_dds_clock_config(), + _ => Err(pounder::Error::Access), + } }) ], @@ -790,23 +813,38 @@ const APP: () = { }) }), "pounder/in0": pounder::ChannelState, (|state| { - c.resources.pounder.set_channel_state(pounder::Channel::In0, - state) + match c.resources.pounder { + Some(pounder) => + pounder.set_channel_state(pounder::Channel::In0, state), + _ => Err(pounder::Error::Access), + } }), "pounder/in1": pounder::ChannelState, (|state| { - c.resources.pounder.set_channel_state(pounder::Channel::In1, - state) + match c.resources.pounder { + Some(pounder) => + pounder.set_channel_state(pounder::Channel::In1, state), + _ => Err(pounder::Error::Access), + } }), "pounder/out0": pounder::ChannelState, (|state| { - c.resources.pounder.set_channel_state(pounder::Channel::Out0, - state) + match c.resources.pounder { + Some(pounder) => + pounder.set_channel_state(pounder::Channel::Out0, state), + _ => Err(pounder::Error::Access), + } }), "pounder/out1": pounder::ChannelState, (|state| { - c.resources.pounder.set_channel_state(pounder::Channel::Out1, - state) + match c.resources.pounder { + Some(pounder) => + pounder.set_channel_state(pounder::Channel::Out1, state), + _ => Err(pounder::Error::Access), + } }), "pounder/dds/clock": pounder::DdsClockConfig, (|config| { - c.resources.pounder.configure_dds_clock(config) + match c.resources.pounder { + Some(pounder) => pounder.configure_dds_clock(config), + _ => Err(pounder::Error::Access), + } }), "stabilizer/afe1/gain": afe::Gain, (|gain| { Ok::<(), ()>(c.resources.afe1.set_gain(gain)) diff --git a/src/pounder/mod.rs b/src/pounder/mod.rs index c89c6cc..1288765 100644 --- a/src/pounder/mod.rs +++ b/src/pounder/mod.rs @@ -29,6 +29,7 @@ pub enum Error { InvalidAddress, InvalidChannel, Adc, + Access, } #[derive(Debug, Copy, Clone)] From 78c9f6e6866a2e1683f034ea503f552accff4ae9 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Sun, 21 Jun 2020 14:30:49 +0200 Subject: [PATCH 2/4] Running rustfmt --- src/main.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9b67978..55365ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ use rtic::cyccnt::{Instant, U32Ext}; use stm32h7xx_hal as hal; use stm32h7xx_hal::prelude::*; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal::digital::v2::{InputPin, OutputPin}; use smoltcp as net; use stm32h7_ethernet as ethernet; @@ -175,8 +175,7 @@ const APP: () = { 'static, 'static, 'static, - ethernet::EthernetDMA<'static>, - >, + ethernet::EthernetDMA<'static>>, eth_mac: ethernet::EthernetMAC, mac_addr: net::wire::EthernetAddress, @@ -376,18 +375,10 @@ const APP: () = { fp_led_2.set_low().unwrap(); fp_led_3.set_low().unwrap(); - // Attempt to instantiate the I2C GPIO expander on pounder. - let pounder_gpio_expander = { - let sda = gpiob.pb7.into_alternate_af4().set_open_drain(); - let scl = gpiob.pb8.into_alternate_af4().set_open_drain(); - let i2c1 = dp.I2C1.i2c((scl, sda), 100.khz(), &clocks); - mcp23017::MCP23017::default(i2c1) - }; - - // If instantiating the GPIO expander was successful, we were able to communicate with the - // IO expander and pounder is available. If the GPIO expander did not communicate with I2C, - // we will assume that pounder is not available. - let pounder_devices = if let Ok(io_expander) = pounder_gpio_expander { + // Measure the Pounder PGOOD output to detect if pounder is present on Stabilizer. + let pounder_pgood = gpiob.pb13.into_pull_down_input(); + delay.delay_ms(2u8); + let pounder_devices = if pounder_pgood.is_high().unwrap() { let ad9959 = { let qspi_interface = { // Instantiate the QUADSPI pins and peripheral interface. @@ -446,6 +437,13 @@ const APP: () = { .unwrap() }; + let io_expander = { + let sda = gpiob.pb7.into_alternate_af4().set_open_drain(); + let scl = gpiob.pb8.into_alternate_af4().set_open_drain(); + let i2c1 = dp.I2C1.i2c((scl, sda), 100.khz(), &clocks); + mcp23017::MCP23017::default(i2c1).unwrap() + }; + let spi = { let spi_mosi = gpiod .pd7 From 7e279ed87cfae1eaf74fd5abfc4ec7f76a946ad3 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Sun, 21 Jun 2020 14:39:23 +0200 Subject: [PATCH 3/4] Re-enabling the HSE --- src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 55365ca..eb7d282 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,6 +171,9 @@ const APP: () = { eeprom_i2c: hal::i2c::I2c, timer: hal::timer::Timer, + + // Note: Do not rustfmt the following definition, as it appears to cause a bug in GDB that + // results in failing to set breakpoints at correct locations. net_interface: net::iface::EthernetInterface< 'static, 'static, @@ -197,8 +200,7 @@ const APP: () = { let rcc = dp.RCC.constrain(); let mut clocks = rcc - //TODO: Re-enable HSE for Stabilizer platform. - // .use_hse(8.mhz()) + .use_hse(8.mhz()) .sysclk(400.mhz()) .hclk(200.mhz()) .per_ck(100.mhz()) From a992d20414bcdba5cb95bd1c788e7db4ac071231 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Sun, 21 Jun 2020 13:36:45 +0200 Subject: [PATCH 4/4] Updating comment about debugging --- src/main.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index eb7d282..3af98f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -172,13 +172,23 @@ const APP: () = { timer: hal::timer::Timer, - // Note: Do not rustfmt the following definition, as it appears to cause a bug in GDB that - // results in failing to set breakpoints at correct locations. + // Note: It appears that rustfmt generates a format that GDB cannot recognize, which + // results in GDB breakpoints being set improperly. To debug, redefine the following + // definition to: + // + // ```rust + // net_interface: net::iface::EthernetInterface< + // 'static, + // 'static, + // 'static, + // ethernet::EthernetDMA<'static>>, + // ``` net_interface: net::iface::EthernetInterface< 'static, 'static, 'static, - ethernet::EthernetDMA<'static>>, + ethernet::EthernetDMA<'static>, + >, eth_mac: ethernet::EthernetMAC, mac_addr: net::wire::EthernetAddress,