pounder_test/src/hardware/mod.rs

91 lines
2.4 KiB
Rust

pub use embedded_hal;
///! Module for all hardware-specific setup of Stabilizer
pub use stm32h7xx_hal as hal;
pub mod adc;
pub mod afe;
pub mod cycle_counter;
pub mod dac;
pub mod design_parameters;
pub mod input_stamper;
pub mod pounder;
pub mod setup;
pub mod signal_generator;
pub mod system_timer;
mod eeprom;
mod timers;
// 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>>,
>;
// 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>>;
pub type NetworkStack = smoltcp_nal::NetworkStack<
'static,
'static,
hal::ethernet::EthernetDMA<'static>,
>;
pub type EthernetPhy = hal::ethernet::phy::LAN8742A<hal::ethernet::EthernetMAC>;
#[inline(never)]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::{
fmt::Write,
sync::atomic::{AtomicBool, Ordering},
};
use cortex_m::asm;
use rtt_target::{ChannelMode, UpChannel};
cortex_m::interrupt::disable();
// Recursion protection
static PANICKED: AtomicBool = AtomicBool::new(false);
while PANICKED.load(Ordering::Relaxed) {
asm::bkpt();
}
PANICKED.store(true, Ordering::Relaxed);
// Turn on both red LEDs, FP_LED_1, FP_LED_3
let gpiod = unsafe { &*hal::stm32::GPIOD::ptr() };
gpiod.odr.modify(|_, w| w.odr6().high().odr12().high());
// Analogous to panic-rtt-target
if let Some(mut channel) = unsafe { UpChannel::conjure(0) } {
channel.set_mode(ChannelMode::BlockIfFull);
writeln!(channel, "{}", info).ok();
}
// Abort
asm::udf();
// Halt
// loop { core::sync::atomic::compiler_fence(Ordering::SeqCst); }
}
#[cortex_m_rt::exception]
unsafe fn HardFault(ef: &cortex_m_rt::ExceptionFrame) -> ! {
panic!("HardFault at {:#?}", ef);
}
#[cortex_m_rt::exception]
unsafe fn DefaultHandler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}