stm32f429idiscovery/
io.rsuse core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of;
use core::ptr::addr_of_mut;
use kernel::debug;
use kernel::debug::IoWrite;
use kernel::hil::led;
use kernel::hil::uart;
use kernel::hil::uart::Configure;
use stm32f429zi::chip_specs::Stm32f429Specs;
use stm32f429zi::gpio::PinId;
use crate::CHIP;
use crate::PROCESSES;
use crate::PROCESS_PRINTER;
pub struct Writer {
initialized: bool,
}
pub static mut WRITER: Writer = Writer { initialized: false };
impl Writer {
pub fn set_initialized(&mut self) {
self.initialized = true;
}
}
impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}
impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) -> usize {
let rcc = stm32f429zi::rcc::Rcc::new();
let clocks: stm32f429zi::clocks::Clocks<Stm32f429Specs> =
stm32f429zi::clocks::Clocks::new(&rcc);
let uart = stm32f429zi::usart::Usart::new_usart1(&clocks);
if !self.initialized {
self.initialized = true;
let _ = uart.configure(uart::Parameters {
baud_rate: 115200,
stop_bits: uart::StopBits::One,
parity: uart::Parity::None,
hw_flow_control: false,
width: uart::Width::Eight,
});
}
for &c in buf {
uart.send_byte(c);
}
buf.len()
}
}
#[no_mangle]
#[panic_handler]
pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
let rcc = stm32f429zi::rcc::Rcc::new();
let clocks: stm32f429zi::clocks::Clocks<Stm32f429Specs> =
stm32f429zi::clocks::Clocks::new(&rcc);
let syscfg = stm32f429zi::syscfg::Syscfg::new(&clocks);
let exti = stm32f429zi::exti::Exti::new(&syscfg);
let pin = stm32f429zi::gpio::Pin::new(PinId::PG14, &exti);
let gpio_ports = stm32f429zi::gpio::GpioPorts::new(&clocks, &exti);
pin.set_ports_ref(&gpio_ports);
let led = &mut led::LedHigh::new(&pin);
let writer = &mut *addr_of_mut!(WRITER);
debug::panic(
&mut [led],
writer,
info,
&cortexm4::support::nop,
&*addr_of!(PROCESSES),
&*addr_of!(CHIP),
&*addr_of!(PROCESS_PRINTER),
)
}