Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

3 changed files with 45 additions and 30 deletions

View File

@ -4,23 +4,30 @@ version = "0.1.0"
authors = ["Levi Pearson <levipearson@gmail.com>"]
description = "Base binary crate for STM32F103 Blue Pill boards"
categories = ["embedded", "no-std"]
edition = "2021"
edition = "2018"
[dependencies]
cortex-m = "0.7.4"
cortex-m-rt = "0.7.1"
embedded-hal = "0.2.4"
nb = "1.0.0"
stm32f1xx-hal = { version = "0.9.0", features = ["rt", "stm32f103", "medium"] }
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] }
cortex-m = "0.6.2"
cortex-m-rt = "0.6.12"
#cortex-m-semihosting = "0.3.5"
# alternate panic impls, choose only one!
# panic-halt
# panic-semihosting # requires cortex-m-semihosting
# panic-itm
# panic-abort
# panic-ramdump
# panic-persist
panic-halt = "0.2.0"
#panic-semihosting = "0.5.3" # requires cortex-m-semihosting
#panic-itm = "0.4.1"
#panic-abort = "0.3.2"
#panic-ramdump = "0.1.1"
#panic-persist = "0.2.1"
embedded-hal = "0.2.3"
nb = "0.1.2"
rtt-target = { version = "0.2.0", features = ["cortex-m"] }
[dependencies.stm32f1]
version = "0.10.0"
features = ["stm32f103", "rt"]
[dependencies.stm32f1xx-hal]
version = "0.5.3"
features = ["rt", "stm32f103", "medium"]
[[bin]]
name = "blue_pill_base"

View File

@ -13,25 +13,21 @@ protocol = "Swd"
[default.flashing]
# Whether or not the target should be flashed.
enabled = true
# Whether or not the target should be halted after flashing.
halt_afterwards = false
# Whether or not bytes erased but not rewritten with data from the ELF
# should be restored with their contents before erasing.
restore_unwritten_bytes = false
# The path where an SVG of the assembled flash layout should be written to.
# flash_layout_output_path = "out.svg"
[default.reset]
# Whether or not the target should be reset.
enabled = true
# Whether or not the target should be halted after flashing.
halt_afterwards = false
[default.general]
# The chip name of the chip to be debugged.
chip = "stm32f103C8"
# A list of chip descriptions to be loaded during runtime.
chip_descriptions = []
# The default log level to be used.
log_level = "WARN"
log_level = "Warn"
[default.rtt]
# Whether or not an RTTUI should be opened after flashing.

View File

@ -7,15 +7,21 @@
#![deny(unsafe_code)]
#![no_std]
#![cfg_attr(not(doc), no_main)]
#![no_main]
use panic_rtt_target as _;
//use panic_halt as _;
use core::panic::PanicInfo;
use rtt_target::{rprintln, rtt_init_print};
use nb::block;
use stm32f1xx_hal::{
prelude::*,
pac,
timer::Timer,
};
use cortex_m_rt::entry;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
use embedded_hal::digital::v2::OutputPin;
#[entry]
fn main() -> ! {
@ -29,30 +35,29 @@ fn main() -> ! {
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
// HAL structs
let mut flash = dp.FLASH.constrain();
let rcc = dp.RCC.constrain();
let mut rcc = dp.RCC.constrain();
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
// `clocks`
let clocks = rcc.cfgr.freeze(&mut flash.acr);
// Acquire the GPIOC peripheral
let mut gpioc = dp.GPIOC.split();
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
// in order to configure the port. For pins 0-7, crl should be passed instead.
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
// Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
timer.start(1.Hz()).unwrap();
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
rprintln!("Hello, Rust!");
// Wait for the timer to trigger an update and change the state of the LED
let mut i = 0;
loop {
block!(timer.wait()).unwrap();
led.set_high();
led.set_high().unwrap();
block!(timer.wait()).unwrap();
led.set_low();
led.set_low().unwrap();
i += 1;
rprintln!("Hello again; I have blinked {} times.", i);
if i == 10 {
@ -60,3 +65,10 @@ fn main() -> ! {
}
}
}
#[inline(never)]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
rprintln!("{}", info);
loop {} // You might need a compiler fence in here.
}