1
0
Fork 0

add gpio setup

This commit is contained in:
topquark12 2022-10-21 12:05:55 +08:00
parent 18a603ab5f
commit 361c2ff316
9 changed files with 161 additions and 70 deletions

View File

@ -2,11 +2,13 @@ use stm32f4xx_hal::{
watchdog::IndependentWatchdog, watchdog::IndependentWatchdog,
rcc::RccExt, rcc::RccExt,
pac::{CorePeripherals, Peripherals}, pac::{CorePeripherals, Peripherals},
time::MegaHertz, prelude::_stm32f4xx_hal_gpio_GpioExt, time::MegaHertz
}; };
use fugit::ExtU32; use fugit::ExtU32;
use log::info; use log::info;
use super::{log_setup, sys_timer, usb}; use super::{log_setup, sys_timer, usb};
use super::gpio;
use crate::laser_diode::current_sources;
#[cfg(not(feature = "semihosting"))] #[cfg(not(feature = "semihosting"))]
const WATCHDOG_PERIOD: u32 = 1000; const WATCHDOG_PERIOD: u32 = 1000;
@ -33,13 +35,15 @@ pub fn bootup (mut core_perif : CorePeripherals, perif : Peripherals) -> (
.pclk2(MegaHertz::from_raw(64).convert()) .pclk2(MegaHertz::from_raw(64).convert())
.freeze(); .freeze();
// let (pins, eth_pins, usb) = Pins::setup( let (eth_pins,
// clocks, perif.TIM4, usb,
// perif.GPIOA, perif.GPIOB, perif.GPIOC, perif.GPIOD, perif.GPIOE, perif.GPIOF, perif.GPIOG, current_source) = gpio::setup(
// perif.SPI1, perif.SPI2, perif.SPI3, clocks, perif.TIM4,
// perif.ADC1, perif.GPIOA, perif.GPIOB, perif.GPIOC, perif.GPIOD, perif.GPIOE, perif.GPIOF, perif.GPIOG,
// perif.OTG_FS_GLOBAL, perif.OTG_FS_DEVICE, perif.OTG_FS_PWRCLK, perif.SPI1, perif.SPI2, perif.SPI3,
// ); perif.ADC1,
perif.OTG_FS_GLOBAL, perif.OTG_FS_DEVICE, perif.OTG_FS_PWRCLK,
);
let mut wd = IndependentWatchdog::new(perif.IWDG); let mut wd = IndependentWatchdog::new(perif.IWDG);
wd.start(WATCHDOG_PERIOD.millis()); wd.start(WATCHDOG_PERIOD.millis());
@ -47,6 +51,8 @@ pub fn bootup (mut core_perif : CorePeripherals, perif : Peripherals) -> (
sys_timer::setup(core_perif.SYST, clocks); sys_timer::setup(core_perif.SYST, clocks);
info!("Kirdy setup complete");
(wd) (wd)
} }

View File

@ -1,10 +1,11 @@
use stm32f4xx_hal::{ use stm32f4xx_hal::{
adc::Adc, adc::Adc,
gpio::{ gpio::{
AF5, Alternate, AlternateOD, Analog, Floating, Input, AF5, Alternate, Analog, Input,
gpioa::*, gpioa::*,
gpiob::*, gpiob::*,
gpioc::*, gpioc::*,
gpiod::*,
gpioe::*, gpioe::*,
gpiof::*, gpiof::*,
gpiog::*, gpiog::*,
@ -14,7 +15,7 @@ use stm32f4xx_hal::{
hal::{self, blocking::spi::Transfer, digital::v2::OutputPin}, hal::{self, blocking::spi::Transfer, digital::v2::OutputPin},
otg_fs::USB, otg_fs::USB,
rcc::Clocks, rcc::Clocks,
pwm::{self, PwmChannels}, spi,
spi::{Spi, NoMiso, TransferModeNormal}, spi::{Spi, NoMiso, TransferModeNormal},
pac::{ pac::{
ADC1, ADC1,
@ -25,45 +26,22 @@ use stm32f4xx_hal::{
}, },
timer::Timer, timer::Timer,
time::U32Ext, time::U32Ext,
time::MegaHertz
}; };
use fugit::RateExtU32;
use stm32_eth::EthPins; use stm32_eth::EthPins;
use crate::laser_diode::current_sources::*;
pub type EthernetPins = EthPins< pub type EthernetPins = EthPins<
PA1<Input<Floating>>, PA1<Input>,
PA7<Input<Floating>>, PA7<Input>,
PB11<Input<Floating>>, PB11<Input>,
PG13<Input<Floating>>, PG13<Input>,
PB13<Input<Floating>>, PB13<Input>,
PC4<Input<Floating>>, PC4<Input>,
PC5<Input<Floating>>, PC5<Input>,
>; >;
impl thermostatPins for thermostat {
type DacSpi = Dac0Spi;
type DacSync = PE4<Output<PushPull>>;
type Shdn = PE10<Output<PushPull>>;
type VRefPin = PA0<Analog>;
type ItecPin = PA6<Analog>;
type DacFeedbackPin = PA4<Analog>;
type TecUMeasPin = PC2<Analog>;
}
pub struct thermostatPinSet {
pub dac_spi: Transfer<u8>,
pub dac_sync: OutputPin,
pub shdn: OutputPin,
pub vref_pin: VRefPin,
pub itec_pin: ItecPin,
pub dac_feedback_pin: DacFeedbackPin,
pub tec_u_meas_pin: TecUMeasPin,
}
pub struct Pins {
pub thermostat: thermostatPinSet,
}
impl Pins {
pub fn setup( pub fn setup(
clocks: Clocks, clocks: Clocks,
tim4: TIM4, tim4: TIM4,
@ -71,7 +49,14 @@ impl Pins {
spi1: SPI1, spi2: SPI2, spi3: SPI3, spi1: SPI1, spi2: SPI2, spi3: SPI3,
adc1: ADC1, adc1: ADC1,
otg_fs_global: OTG_FS_GLOBAL, otg_fs_device: OTG_FS_DEVICE, otg_fs_pwrclk: OTG_FS_PWRCLK, otg_fs_global: OTG_FS_GLOBAL, otg_fs_device: OTG_FS_DEVICE, otg_fs_pwrclk: OTG_FS_PWRCLK,
) -> (Self, EthernetPins, USB) { ) -> (
EthernetPins,
USB,
current_source_construct<current_source_0>,
// photo_diode_phy,
// thermostat_phy
) {
let gpioa = gpioa.split(); let gpioa = gpioa.split();
let gpiob = gpiob.split(); let gpiob = gpiob.split();
let gpioc = gpioc.split(); let gpioc = gpioc.split();
@ -80,8 +65,48 @@ impl Pins {
let gpiof = gpiof.split(); let gpiof = gpiof.split();
let gpiog = gpiog.split(); let gpiog = gpiog.split();
let usb = USB {
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(),
hclk: clocks.hclk(),
};
let eth_pins = EthPins {
ref_clk: gpioa.pa1,
crs: gpioa.pa7,
tx_en: gpiob.pb11,
tx_d0: gpiog.pg13,
tx_d1: gpiob.pb13,
rx_d0: gpioc.pc4,
rx_d1: gpioc.pc5,
};
let sck = gpiob.pb10.into_alternate();
let mosi = gpiob.pb15.into_alternate();
let mode = spi::Mode {
polarity: spi::Polarity::IdleHigh,
phase: spi::Phase::CaptureOnSecondTransition,
};
let spi2 = Spi::new(
spi2,
(sck, NoMiso {}, mosi),
mode,
10_u32.MHz(),
&clocks);
let current_source: current_source_construct<current_source_0> = current_source_construct {
max5719_spi: spi2,
max5719_load: gpioe.pe4.into_push_pull_output(),
current_source_ldo_en: gpioe.pe10.into_push_pull_output(),
current_source_short: gpioa.pa4.into_push_pull_output(),
output_current: 0.0
};
(eth_pins, usb, current_source)
} }
}

View File

@ -2,4 +2,4 @@ pub mod log_setup;
pub mod usb; pub mod usb;
pub mod sys_timer; pub mod sys_timer;
pub mod boot; pub mod boot;
// pub mod init_gpio; pub mod gpio;

View File

@ -0,0 +1,41 @@
use stm32f4xx_hal::{
adc::Adc,
gpio::{
AF5, Alternate,
gpioa::*,
gpiob::*,
gpioe::*,
Output,
PushPull,
},
hal::{self, blocking::spi::Transfer, digital::v2::OutputPin},
spi::{Spi, NoMiso, TransferModeNormal},
pac::SPI2,
};
pub trait current_source_phy {
type max5719_spi: Transfer<u8>;
type max5719_load: OutputPin;
type current_source_ldo_en: OutputPin;
type current_source_short: OutputPin;
}
pub struct current_source_construct<C: current_source_phy> {
pub max5719_spi: C::max5719_spi,
pub max5719_load: C::max5719_load,
pub current_source_ldo_en: C::current_source_ldo_en,
pub current_source_short: C::current_source_short,
pub output_current : f32,
}
pub struct current_source_0;
impl current_source_phy for current_source_0 {
type max5719_spi = Spi<SPI2, (PB10<Alternate<5>>, NoMiso, PB15<Alternate<5>>), TransferModeNormal>;
type max5719_load = PE4<Output<PushPull>>;
type current_source_ldo_en = PE10<Output<PushPull>>;
type current_source_short = PA4<Output<PushPull>>;
}

View File

@ -0,0 +1,17 @@
use stm32f4xx_hal::{
adc::Adc,
gpio::{
AF5, Alternate, Analog, Input,
gpioa::*,
gpiob::*,
gpiod::*,
Output, PushPull, Pin,
},
hal::{self, blocking::spi::Transfer, digital::v2::OutputPin},
spi::{Spi, NoMiso, TransferModeNormal},
pac::{GPIOB, SPI2}
};

1
src/laser_diode/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod current_sources;

View File

@ -4,15 +4,16 @@
use panic_halt as _; use panic_halt as _;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
watchdog::IndependentWatchdog, pac::{CorePeripherals, Peripherals}
rcc::RccExt,
pac::{CorePeripherals, Peripherals},
time::MegaHertz, prelude::_stm32f4xx_hal_gpio_GpioExt,
}; };
use log::info; use log::info;
mod device; mod device;
use device::boot::bootup; mod laser_diode;
use device::sys_timer; use device::{
boot::bootup,
sys_timer
};
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {

0
src/thermostat/mod.rs Normal file
View File