Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump stm32f4xx-hal from 0.15.0 to 0.16.0 #301

Merged
merged 4 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum-iterator = { version = "1.4", default-features = false }
built = { version = "0.6", features = ["git2"], default-features = false }

[dependencies.stm32f4xx-hal]
version = "0.15"
version = "0.16"
features = ["stm32f407", "rt", "usb_fs"]

[dependencies.enc424j600]
Expand Down
27 changes: 4 additions & 23 deletions src/hardware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,13 @@ pub type SystemTimer = mono_clock::MonoClock<u32, MONOTONIC_FREQUENCY>;
pub const CPU_FREQ: u32 = 168_000_000;

// Convenience type definition for the I2C bus used for booster RF channels.
pub type I2C = hal::i2c::I2c<
hal::pac::I2C1,
(
hal::gpio::gpiob::PB6<hal::gpio::Alternate<4, hal::gpio::OpenDrain>>,
hal::gpio::gpiob::PB7<hal::gpio::Alternate<4, hal::gpio::OpenDrain>>,
),
>;

pub type I2C2 = hal::i2c::I2c<
hal::pac::I2C2,
(
hal::gpio::gpiob::PB10<hal::gpio::Alternate<4, hal::gpio::OpenDrain>>,
hal::gpio::gpiob::PB11<hal::gpio::Alternate<4, hal::gpio::OpenDrain>>,
),
>;
pub type I2C = hal::i2c::I2c<hal::pac::I2C1>;

pub type I2C2 = hal::i2c::I2c<hal::pac::I2C2>;

pub type SpiCs = hal::gpio::gpioa::PA4<hal::gpio::Output<hal::gpio::PushPull>>;

pub type Spi = hal::spi::Spi<
hal::pac::SPI1,
(
hal::gpio::gpioa::PA5<hal::gpio::Alternate<5>>,
hal::gpio::gpioa::PA6<hal::gpio::Alternate<5>>,
hal::gpio::gpioa::PA7<hal::gpio::Alternate<5>>,
),
>;
pub type Spi = hal::spi::Spi<hal::pac::SPI1>;

pub type Led1 = hal::gpio::gpioc::PC8<hal::gpio::Output<hal::gpio::PushPull>>;
pub type Led2 = hal::gpio::gpioc::PC9<hal::gpio::Output<hal::gpio::PushPull>>;
Expand Down
35 changes: 20 additions & 15 deletions src/hardware/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::settings::BoosterSettings;
use stm32f4xx_hal as hal;

use bit_field::BitField;
use core::convert::TryInto;
use core::fmt::Write;
use hal::prelude::*;
use heapless::String;
Expand Down Expand Up @@ -176,9 +177,10 @@ pub fn setup(
let (i2c_peripheral, pins) = mux.free().release();
let (scl, sda) = pins;

// Configure I2C pins as open-drain outputs.
let mut scl = scl.into_open_drain_output();
let mut sda = sda.into_open_drain_output();
let mut scl: hal::gpio::PB6<hal::gpio::Output<hal::gpio::OpenDrain>> =
scl.try_into().unwrap();
let mut sda: hal::gpio::PB7<hal::gpio::Output<hal::gpio::OpenDrain>> =
sda.try_into().unwrap();

platform::i2c_bus_reset(&mut sda, &mut scl, &mut delay);

Expand Down Expand Up @@ -247,7 +249,7 @@ pub fn setup(
device.SPI2,
(
gpiob.pb13.into_alternate(),
hal::gpio::NoPin,
hal::spi::NoMosi::new(),
gpiob.pb15.into_alternate(),
),
mode,
Expand Down Expand Up @@ -315,19 +317,21 @@ pub fn setup(
// version code of 0x04, but the ENC424J600 won't return anything meaningful.
let w5500_detected = {
cs.set_low();
let mut transfer = [
let transfer = [
0x00, 0x39, // Reading the version register (address 0x0039)
0x01, // Control phase, 1 byte of data, common register block, read
0x00, // Data, don't care, will be overwritten during read.
];

spi.transfer(&mut transfer).unwrap();
let mut result = [0; 4];

spi.transfer(&mut result, &transfer).unwrap();

cs.set_high();

// The result is stored in the data phase byte. This should always be a 0x04 for the
// W5500.
transfer[3] == 0x04
result[3] == 0x04
};

if w5500_detected {
Expand Down Expand Up @@ -425,14 +429,15 @@ pub fn setup(
.unwrap();
let serial_number = cortex_m::singleton!(: Option<String<64>> = None).unwrap();

let usb = hal::otg_fs::USB {
usb_global: device.OTG_FS_GLOBAL,
usb_device: device.OTG_FS_DEVICE,
usb_pwrclk: device.OTG_FS_PWRCLK,
pin_dm: gpioa.pa11.into_alternate(),
pin_dp: gpioa.pa12.into_alternate(),
hclk: clocks.hclk(),
};
let usb = hal::otg_fs::USB::new(
(
device.OTG_FS_GLOBAL,
device.OTG_FS_DEVICE,
device.OTG_FS_PWRCLK,
),
(gpioa.pa11.into_alternate(), gpioa.pa12.into_alternate()),
&clocks,
);

usb_bus.replace(hal::otg_fs::UsbBus::new(usb, &mut endpoint_memory[..]));

Expand Down
11 changes: 2 additions & 9 deletions src/hardware/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use super::Channel;
use bit_field::BitField;
use hal::hal::{blocking::spi::Write, digital::v2::InputPin};
use hal::hal::digital::v2::InputPin;
use stm32f4xx_hal as hal;

use debounced_pin::{Debounce, DebounceState, DebouncedInputPin};
Expand Down Expand Up @@ -107,14 +107,7 @@ pub enum Color {
Green,
}

type LedSpi = hal::spi::Spi<
hal::pac::SPI2,
(
hal::gpio::gpiob::PB13<hal::gpio::Alternate<5>>,
hal::spi::NoMiso,
hal::gpio::gpiob::PB15<hal::gpio::Alternate<5>>,
),
>;
type LedSpi = hal::spi::Spi<hal::pac::SPI2>;

pub struct UserLeds {
red: u8,
Expand Down