Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active July 9, 2018 07:33
Show Gist options
  • Save lupyuen/3aa3d6f1d9612e346fcd8bb5f467923e to your computer and use it in GitHub Desktop.
Save lupyuen/3aa3d6f1d9612e346fcd8bb5f467923e to your computer and use it in GitHub Desktop.
fn main() -> ! {
// Show "Hello, world!" on the debug console, which is shown in OpenOCD. "mut" means that this object is mutable, i.e. it can change.
let mut debug_out = hio::hstdout().unwrap();
writeln!(debug_out, "Hello, world!").unwrap();
// Get peripherals (clocks, flash memory, GPIO) for the STM32 Blue Pill microcontroller.
let bluepill = Peripherals::take().unwrap();
// Get the clocks from the STM32 Reset and Clock Control (RCC) and freeze the Flash Access Control Register (ACR).
let mut rcc = bluepill.RCC.constrain();
let mut flash = bluepill.FLASH.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
// Get GPIO Port C, which also enables the Advanced Peripheral Bus 2 (APB2) clock for Port C.
let mut gpioc = bluepill.GPIOC.split(&mut rcc.apb2);
// Use Pin PC 13 of the Blue Pill for GPIO Port C. Select Output Push/Pull mode for the pin, which is connected to our LED.
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
// Create a delay timer from the RCC clocks.
let cp = cortex_m::Peripherals::take().unwrap();
let mut delay = Delay::new(cp.SYST, clocks);
// Loop forever.
loop { ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment