Compare commits
No commits in common. "master" and "master" have entirely different histories.
35
Cargo.toml
35
Cargo.toml
|
@ -4,23 +4,30 @@ version = "0.1.0"
|
||||||
authors = ["Levi Pearson <levipearson@gmail.com>"]
|
authors = ["Levi Pearson <levipearson@gmail.com>"]
|
||||||
description = "Base binary crate for STM32F103 Blue Pill boards"
|
description = "Base binary crate for STM32F103 Blue Pill boards"
|
||||||
categories = ["embedded", "no-std"]
|
categories = ["embedded", "no-std"]
|
||||||
edition = "2021"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = "0.7.4"
|
cortex-m = "0.6.2"
|
||||||
cortex-m-rt = "0.7.1"
|
cortex-m-rt = "0.6.12"
|
||||||
embedded-hal = "0.2.4"
|
#cortex-m-semihosting = "0.3.5"
|
||||||
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!
|
# alternate panic impls, choose only one!
|
||||||
# panic-halt
|
panic-halt = "0.2.0"
|
||||||
# panic-semihosting # requires cortex-m-semihosting
|
#panic-semihosting = "0.5.3" # requires cortex-m-semihosting
|
||||||
# panic-itm
|
#panic-itm = "0.4.1"
|
||||||
# panic-abort
|
#panic-abort = "0.3.2"
|
||||||
# panic-ramdump
|
#panic-ramdump = "0.1.1"
|
||||||
# panic-persist
|
#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]]
|
[[bin]]
|
||||||
name = "blue_pill_base"
|
name = "blue_pill_base"
|
||||||
|
|
10
Embed.toml
10
Embed.toml
|
@ -13,25 +13,21 @@ protocol = "Swd"
|
||||||
[default.flashing]
|
[default.flashing]
|
||||||
# Whether or not the target should be flashed.
|
# Whether or not the target should be flashed.
|
||||||
enabled = true
|
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
|
# Whether or not bytes erased but not rewritten with data from the ELF
|
||||||
# should be restored with their contents before erasing.
|
# should be restored with their contents before erasing.
|
||||||
restore_unwritten_bytes = false
|
restore_unwritten_bytes = false
|
||||||
# The path where an SVG of the assembled flash layout should be written to.
|
# The path where an SVG of the assembled flash layout should be written to.
|
||||||
# flash_layout_output_path = "out.svg"
|
# 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]
|
[default.general]
|
||||||
# The chip name of the chip to be debugged.
|
# The chip name of the chip to be debugged.
|
||||||
chip = "stm32f103C8"
|
chip = "stm32f103C8"
|
||||||
# A list of chip descriptions to be loaded during runtime.
|
# A list of chip descriptions to be loaded during runtime.
|
||||||
chip_descriptions = []
|
chip_descriptions = []
|
||||||
# The default log level to be used.
|
# The default log level to be used.
|
||||||
log_level = "WARN"
|
log_level = "Warn"
|
||||||
|
|
||||||
[default.rtt]
|
[default.rtt]
|
||||||
# Whether or not an RTTUI should be opened after flashing.
|
# Whether or not an RTTUI should be opened after flashing.
|
||||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -7,15 +7,21 @@
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
#![no_std]
|
#![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 rtt_target::{rprintln, rtt_init_print};
|
||||||
|
|
||||||
use nb::block;
|
use nb::block;
|
||||||
|
|
||||||
|
use stm32f1xx_hal::{
|
||||||
|
prelude::*,
|
||||||
|
pac,
|
||||||
|
timer::Timer,
|
||||||
|
};
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
|
use embedded_hal::digital::v2::OutputPin;
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
|
@ -29,30 +35,29 @@ fn main() -> ! {
|
||||||
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
|
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
|
||||||
// HAL structs
|
// HAL structs
|
||||||
let mut flash = dp.FLASH.constrain();
|
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
|
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
|
||||||
// `clocks`
|
// `clocks`
|
||||||
let clocks = rcc.cfgr.freeze(&mut flash.acr);
|
let clocks = rcc.cfgr.freeze(&mut flash.acr);
|
||||||
|
|
||||||
// Acquire the GPIOC peripheral
|
// 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
|
// 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.
|
// 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);
|
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||||
// Configure the syst timer to trigger an update every second
|
// Configure the syst timer to trigger an update every second
|
||||||
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
|
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
|
||||||
timer.start(1.Hz()).unwrap();
|
|
||||||
|
|
||||||
rprintln!("Hello, Rust!");
|
rprintln!("Hello, Rust!");
|
||||||
// Wait for the timer to trigger an update and change the state of the LED
|
// Wait for the timer to trigger an update and change the state of the LED
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
loop {
|
loop {
|
||||||
block!(timer.wait()).unwrap();
|
block!(timer.wait()).unwrap();
|
||||||
led.set_high();
|
led.set_high().unwrap();
|
||||||
block!(timer.wait()).unwrap();
|
block!(timer.wait()).unwrap();
|
||||||
led.set_low();
|
led.set_low().unwrap();
|
||||||
i += 1;
|
i += 1;
|
||||||
rprintln!("Hello again; I have blinked {} times.", i);
|
rprintln!("Hello again; I have blinked {} times.", i);
|
||||||
if i == 10 {
|
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.
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue