101 lines
2.4 KiB
Rust
101 lines
2.4 KiB
Rust
#![no_std]
|
|
#![feature(asm, used, const_fn, naked_functions, alloc, box_syntax)]
|
|
#![no_main]
|
|
#![feature(extern_prelude)]
|
|
|
|
#[macro_use]
|
|
extern crate hcl;
|
|
|
|
#[macro_use]
|
|
extern crate alloc;
|
|
|
|
use core::mem;
|
|
use hcl::platform::gpio;
|
|
use hcl::platform::irq;
|
|
use hcl::platform::rcc;
|
|
use hcl::platform::scs;
|
|
use hcl::platform::timer;
|
|
use hcl::platform::usart;
|
|
use hcl::platform::dma;
|
|
use hcl::dma::*;
|
|
|
|
mod debug;
|
|
|
|
use debug::UsartPrinter;
|
|
|
|
fn configure_clocks(rcc: &mut rcc::RCC) {
|
|
rcc.clock_control.set_hse_on(true);
|
|
while !rcc.clock_control.hse_ready() {
|
|
}
|
|
|
|
rcc.clock_config.configure(|c| c
|
|
.set_pll_multiplier(10)
|
|
.set_pll_source(rcc::PllSource::HsiDiv2));
|
|
|
|
rcc.clock_control.set_pll_on(true);
|
|
while !rcc.clock_control.pll_ready() {
|
|
}
|
|
|
|
rcc.clock_config.switch_clock_source(rcc::SystemClockSource::Pll);
|
|
}
|
|
|
|
fn configure_peripherals(rcc: &mut hcl::platform::rcc::RCC,
|
|
gpio: &mut gpio::GPIO,
|
|
usart: &mut usart::USART) {
|
|
rcc.apb2_enable.set_gpio_a(true);
|
|
rcc.apb1_enable.configure(|a| a
|
|
.set_usart2(true));
|
|
rcc.ahb_enable.set_dma1(true);
|
|
|
|
gpio.configure(|g| g
|
|
.set_mode(2, gpio::PinMode::Output2MHz)
|
|
.set_output_config(2, gpio::OutputConfig::AfPushPull)
|
|
.set_mode(3, gpio::PinMode::Output50MHz)
|
|
.set_output_config(3, gpio::OutputConfig::AfPushPull)
|
|
.set_mode(5, gpio::PinMode::Output50MHz)
|
|
.set_output_config(5, gpio::OutputConfig::PushPull));
|
|
|
|
usart.configure(|u| u
|
|
.set_enabled(true)
|
|
.set_tx_enabled(true)
|
|
.set_dma_transmit_enabled(true)
|
|
.set_baudgen((21, 11))); // 115.2 kbaud
|
|
}
|
|
|
|
|
|
|
|
// allowing inlining into main() breaks the stack, since main() must be naked to set up a process stack.
|
|
#[inline(never)]
|
|
fn run(mut scs: scs::Instance, mut p: hcl::platform::Instance) {
|
|
configure_clocks(&mut p.rcc);
|
|
configure_peripherals(&mut p.rcc, &mut p.gpio_a, &mut p.usart2);
|
|
|
|
let dma = p.dma1.split();
|
|
|
|
|
|
let mut dma_control = dma.control;
|
|
|
|
|
|
let printer = UsartPrinter::init(p.usart2.split(), 7, dma.channel7);
|
|
|
|
for i in 0u32..0xffffffff {
|
|
let x = format!("> {}\r\n", i).into_bytes();
|
|
|
|
priner.print(x);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
entry_point!(main);
|
|
fn main(scs: scs::Instance, p: hcl::platform::Instance) {
|
|
declare_thread_stack!(stack, 512);
|
|
|
|
unsafe {
|
|
hcl::set_process_stack(&stack);
|
|
hcl::use_process_stack(true);
|
|
}
|
|
|
|
run(scs, p);
|
|
}
|