forked from BluePill_Rust/blue_pill_base
Compare commits
9 Commits
Author | SHA1 | Date |
---|---|---|
Levi Pearson | 45dc286f86 | |
Levi Pearson | e032084a6c | |
Levi Pearson | cd0858873c | |
Levi Pearson | 5db28da7fb | |
Levi Pearson | 3572e55b67 | |
Levi Pearson | 31a137f008 | |
Levi Pearson | adf41ef411 | |
Erich Gubler | 57be162906 | |
Erich Gubler | 0f9517a97a |
35
Cargo.toml
35
Cargo.toml
|
@ -4,30 +4,23 @@ version = "0.1.0"
|
|||
authors = ["Levi Pearson <levipearson@gmail.com>"]
|
||||
description = "Base binary crate for STM32F103 Blue Pill boards"
|
||||
categories = ["embedded", "no-std"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.6.2"
|
||||
cortex-m-rt = "0.6.12"
|
||||
#cortex-m-semihosting = "0.3.5"
|
||||
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"] }
|
||||
# alternate panic impls, choose only one!
|
||||
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"]
|
||||
# panic-halt
|
||||
# panic-semihosting # requires cortex-m-semihosting
|
||||
# panic-itm
|
||||
# panic-abort
|
||||
# panic-ramdump
|
||||
# panic-persist
|
||||
|
||||
[[bin]]
|
||||
name = "blue_pill_base"
|
||||
|
|
10
Embed.toml
10
Embed.toml
|
@ -13,21 +13,25 @@ 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.
|
||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -7,21 +7,15 @@
|
|||
|
||||
#![deny(unsafe_code)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![cfg_attr(not(doc), no_main)]
|
||||
|
||||
//use panic_halt as _;
|
||||
use core::panic::PanicInfo;
|
||||
use panic_rtt_target as _;
|
||||
use rtt_target::{rprintln, rtt_init_print};
|
||||
|
||||
use nb::block;
|
||||
|
||||
use stm32f1xx_hal::{
|
||||
prelude::*,
|
||||
pac,
|
||||
timer::Timer,
|
||||
};
|
||||
use cortex_m_rt::entry;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
|
@ -35,29 +29,30 @@ 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 mut rcc = dp.RCC.constrain();
|
||||
let 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(&mut rcc.apb2);
|
||||
let mut gpioc = dp.GPIOC.split();
|
||||
|
||||
// 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).start_count_down(1.hz());
|
||||
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
|
||||
timer.start(1.Hz()).unwrap();
|
||||
|
||||
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().unwrap();
|
||||
led.set_high();
|
||||
block!(timer.wait()).unwrap();
|
||||
led.set_low().unwrap();
|
||||
led.set_low();
|
||||
i += 1;
|
||||
rprintln!("Hello again; I have blinked {} times.", i);
|
||||
if i == 10 {
|
||||
|
@ -65,10 +60,3 @@ fn main() -> ! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
rprintln!("{}", info);
|
||||
loop {} // You might need a compiler fence in here.
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue