2021-01-18 23:47:47 +08:00
|
|
|
///! Module for all hardware-specific setup of Stabilizer
|
2021-05-17 19:01:45 +08:00
|
|
|
pub use stm32h7xx_hal as hal;
|
2021-01-18 23:47:47 +08:00
|
|
|
|
2021-04-15 19:47:10 +08:00
|
|
|
// Re-export for the DigitalInputs below:
|
|
|
|
pub use embedded_hal::digital::v2::InputPin;
|
|
|
|
|
2021-01-18 23:47:47 +08:00
|
|
|
mod adc;
|
|
|
|
mod afe;
|
|
|
|
mod configuration;
|
2021-02-17 19:08:03 +08:00
|
|
|
mod cycle_counter;
|
2021-01-18 23:47:47 +08:00
|
|
|
mod dac;
|
2021-02-04 19:48:25 +08:00
|
|
|
pub mod design_parameters;
|
2021-01-18 23:47:47 +08:00
|
|
|
mod digital_input_stamper;
|
|
|
|
mod eeprom;
|
2021-02-08 22:24:52 +08:00
|
|
|
pub mod pounder;
|
2021-04-15 20:40:47 +08:00
|
|
|
mod system_timer;
|
2021-01-18 23:47:47 +08:00
|
|
|
mod timers;
|
|
|
|
|
2021-05-17 19:01:45 +08:00
|
|
|
pub use adc::*;
|
|
|
|
pub use afe::{Gain as AfeGain, *};
|
|
|
|
pub use cycle_counter::*;
|
|
|
|
pub use dac::*;
|
|
|
|
pub use digital_input_stamper::*;
|
|
|
|
pub use pounder::*;
|
|
|
|
pub use system_timer::*;
|
2021-01-18 23:47:47 +08:00
|
|
|
|
|
|
|
// Type alias for the analog front-end (AFE) for ADC0.
|
|
|
|
pub type AFE0 = afe::ProgrammableGainAmplifier<
|
|
|
|
hal::gpio::gpiof::PF2<hal::gpio::Output<hal::gpio::PushPull>>,
|
|
|
|
hal::gpio::gpiof::PF5<hal::gpio::Output<hal::gpio::PushPull>>,
|
|
|
|
>;
|
|
|
|
|
|
|
|
// Type alias for the analog front-end (AFE) for ADC1.
|
|
|
|
pub type AFE1 = afe::ProgrammableGainAmplifier<
|
|
|
|
hal::gpio::gpiod::PD14<hal::gpio::Output<hal::gpio::PushPull>>,
|
|
|
|
hal::gpio::gpiod::PD15<hal::gpio::Output<hal::gpio::PushPull>>,
|
|
|
|
>;
|
|
|
|
|
2021-04-14 21:53:52 +08:00
|
|
|
// Type alias for digital input 0 (DI0).
|
|
|
|
pub type DigitalInput0 =
|
|
|
|
hal::gpio::gpiog::PG9<hal::gpio::Input<hal::gpio::Floating>>;
|
|
|
|
|
|
|
|
// Type alias for digital input 1 (DI1).
|
|
|
|
pub type DigitalInput1 =
|
|
|
|
hal::gpio::gpioc::PC15<hal::gpio::Input<hal::gpio::Floating>>;
|
|
|
|
|
2021-01-31 01:48:27 +08:00
|
|
|
pub type NetworkStack = smoltcp_nal::NetworkStack<
|
2021-01-18 23:47:47 +08:00
|
|
|
'static,
|
|
|
|
'static,
|
|
|
|
hal::ethernet::EthernetDMA<'static>,
|
|
|
|
>;
|
|
|
|
|
2021-03-18 03:16:13 +08:00
|
|
|
pub type EthernetPhy = hal::ethernet::phy::LAN8742A<hal::ethernet::EthernetMAC>;
|
|
|
|
|
2021-01-18 23:47:47 +08:00
|
|
|
pub use configuration::{setup, PounderDevices, StabilizerDevices};
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
#[panic_handler]
|
2021-05-13 17:14:03 +08:00
|
|
|
fn panic(info: &core::panic::PanicInfo) -> ! {
|
|
|
|
use core::{
|
|
|
|
fmt::Write,
|
2021-05-13 21:18:22 +08:00
|
|
|
sync::atomic::{AtomicBool, Ordering},
|
2021-05-13 17:14:03 +08:00
|
|
|
};
|
2021-05-13 21:18:22 +08:00
|
|
|
use cortex_m::asm;
|
2021-05-13 17:14:03 +08:00
|
|
|
use rtt_target::{ChannelMode, UpChannel};
|
|
|
|
|
2021-05-13 21:18:22 +08:00
|
|
|
cortex_m::interrupt::disable();
|
|
|
|
|
|
|
|
// Recursion protection
|
|
|
|
static PANICKED: AtomicBool = AtomicBool::new(false);
|
|
|
|
while PANICKED.load(Ordering::Relaxed) {
|
|
|
|
asm::bkpt();
|
|
|
|
}
|
|
|
|
PANICKED.store(true, Ordering::Relaxed);
|
2021-05-13 17:14:03 +08:00
|
|
|
|
2021-03-03 23:36:10 +08:00
|
|
|
// Turn on both red LEDs, FP_LED_1, FP_LED_3
|
2021-05-13 21:18:22 +08:00
|
|
|
let gpiod = unsafe { &*hal::stm32::GPIOD::ptr() };
|
2021-03-03 23:36:10 +08:00
|
|
|
gpiod.odr.modify(|_, w| w.odr6().high().odr12().high());
|
2021-05-13 17:14:03 +08:00
|
|
|
|
|
|
|
// Analogous to panic-rtt-target
|
|
|
|
if let Some(mut channel) = unsafe { UpChannel::conjure(0) } {
|
|
|
|
channel.set_mode(ChannelMode::BlockIfFull);
|
|
|
|
writeln!(channel, "{}", info).ok();
|
|
|
|
}
|
|
|
|
|
2021-05-13 21:18:22 +08:00
|
|
|
// Abort
|
|
|
|
asm::udf();
|
|
|
|
// Halt
|
|
|
|
// loop { core::sync::atomic::compiler_fence(Ordering::SeqCst); }
|
2021-01-18 23:47:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cortex_m_rt::exception]
|
2021-03-29 02:32:50 +08:00
|
|
|
unsafe fn HardFault(ef: &cortex_m_rt::ExceptionFrame) -> ! {
|
2021-01-18 23:47:47 +08:00
|
|
|
panic!("HardFault at {:#?}", ef);
|
|
|
|
}
|
2021-03-04 00:05:22 +08:00
|
|
|
|
|
|
|
#[cortex_m_rt::exception]
|
2021-03-29 02:32:50 +08:00
|
|
|
unsafe fn DefaultHandler(irqn: i16) {
|
2021-03-04 00:05:22 +08:00
|
|
|
panic!("Unhandled exception (IRQn = {})", irqn);
|
|
|
|
}
|