Skip to content

Commit f15ae73

Browse files
committed
[skip ci] start work on blinky example
1 parent 9a22332 commit f15ae73

File tree

9 files changed

+201
-1
lines changed

9 files changed

+201
-1
lines changed

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"rust-analyzer.cargo.features": [
3+
"rt",
4+
"stm32h503"
5+
],
6+
"rust-analyzer.check.allTargets": false,
7+
"rust-analyzer.check.targets": "thumbv8m.main-none-eabihf",
8+
}

Cargo.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,23 @@ log-semihost = []
3535

3636
[dependencies]
3737
cortex-m = { version = "^0.7.7", features = ["critical-section-single-core"] }
38-
stm32h5 = "*"
38+
stm32h5 = { version = "*", git = "https://github.com/stm32-rs/stm32-rs-nightlies" }
3939
fugit = "0.3.6"
4040
embedded-hal = { version = "0.2.7", features = ["unproven"] }
4141

42+
[dev-dependencies]
43+
cortex-m-rt = ">=0.6.15,<0.8"
44+
log = "0.4.11"
45+
panic-halt = "0.2.0"
46+
panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] }
47+
cfg-if = "1.0.0"
48+
rtt-target = "0.4.0"
49+
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
50+
cortex-m-log = { version = "0.8.0", features = ["itm", "semihosting", "log-integration"] }
51+
cortex-m-semihosting = "0.5.0"
52+
panic-itm = { version = "~0.4.1" }
53+
panic-semihosting = "0.6"
54+
4255
[profile.release]
4356
codegen-units = 1 # better optimizations
4457
debug = true # symbols are nice and they don't increase the size in flash

NOTES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Dev notes
2+
3+
* CubeIDE recomends user to enable the `ICACHE` for maximum perfomance.
4+
* OpenOCD does not yet support the H5, [ST maintains a fork with support](https://github.com/STMicroelectronics/OpenOCD).
5+
* OpenOCD does not come with udev rules for the new ST-Link V3, here's the required line:
6+
```
7+
# STLink v3
8+
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374e", MODE="660", GROUP="plugdev", TAG+="uaccess"
9+
```

examples/blinky.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
mod utilities;
5+
6+
use cortex_m_rt::entry;
7+
use stm32h5xx_hal::pac;
8+
9+
#[entry]
10+
fn main() -> ! {
11+
utilities::logger::init();
12+
13+
let cp = cortex_m::Peripherals::take().unwrap();
14+
let dp = pac::Peripherals::take().unwrap();
15+
16+
// TODO: Power/clock config is required before blinky can... blink.
17+
18+
dp.GPIOA.moder.write(|w| w.mode5().variant(1)); // output
19+
dp.GPIOA.pupdr.write(|w| w.pupd5().variant(1)); // pull-up
20+
21+
// dp.GPIOA.odr.write(|w| w.od5().set_bit());
22+
23+
loop {
24+
dp.GPIOA.odr.write(|w| w.od5().clear_bit());
25+
for _ in 0..1_000_0 {
26+
cortex_m::asm::nop();
27+
}
28+
dp.GPIOA.odr.write(|w| w.od5().set_bit());
29+
for _ in 0..1_000_0 {
30+
cortex_m::asm::nop();
31+
}
32+
}
33+
}

examples/utilities/logger.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#![cfg_attr(feature = "log-itm", allow(unsafe_code))]
2+
3+
cfg_if::cfg_if! {
4+
if #[cfg(any(feature = "log-itm"))] {
5+
use panic_itm as _;
6+
7+
use lazy_static::lazy_static;
8+
use log::LevelFilter;
9+
10+
pub use cortex_m_log::log::Logger;
11+
12+
use cortex_m_log::{
13+
destination::Itm as ItmDest,
14+
printer::itm::InterruptSync,
15+
modes::InterruptFree,
16+
printer::itm::ItmSync
17+
};
18+
19+
lazy_static! {
20+
static ref LOGGER: Logger<ItmSync<InterruptFree>> = Logger {
21+
level: LevelFilter::Info,
22+
inner: unsafe {
23+
InterruptSync::new(
24+
ItmDest::new(cortex_m::Peripherals::steal().ITM)
25+
)
26+
},
27+
};
28+
}
29+
30+
pub fn init() {
31+
cortex_m_log::log::init(&LOGGER).unwrap();
32+
}
33+
34+
}
35+
else if #[cfg(any(feature = "log-rtt"))] {
36+
use panic_rtt_target as _;
37+
38+
use log::{Level, Metadata, Record, LevelFilter};
39+
use rtt_target::{rprintln, rtt_init_print};
40+
41+
pub struct Logger {
42+
level: Level,
43+
}
44+
45+
static LOGGER: Logger = Logger {
46+
level: Level::Info,
47+
};
48+
49+
pub fn init() {
50+
rtt_init_print!();
51+
log::set_logger(&LOGGER).map(|()| log::set_max_level(LevelFilter::Info)).unwrap();
52+
}
53+
54+
impl log::Log for Logger {
55+
fn enabled(&self, metadata: &Metadata) -> bool {
56+
metadata.level() <= self.level
57+
58+
}
59+
60+
fn log(&self, record: &Record) {
61+
rprintln!("{} - {}", record.level(), record.args());
62+
}
63+
64+
fn flush(&self) {}
65+
}
66+
}
67+
else if #[cfg(any(feature = "log-semihost"))] {
68+
use panic_semihosting as _;
69+
70+
use lazy_static::lazy_static;
71+
use log::LevelFilter;
72+
73+
pub use cortex_m_log::log::Logger;
74+
use cortex_m_log::printer::semihosting;
75+
use cortex_m_log::printer::semihosting::Semihosting;
76+
use cortex_m_log::modes::InterruptOk;
77+
use cortex_m_semihosting::hio::HostStream;
78+
79+
lazy_static! {
80+
static ref LOGGER: Logger<Semihosting<InterruptOk, HostStream>> = Logger {
81+
level: LevelFilter::Info,
82+
inner: semihosting::InterruptOk::<_>::stdout().expect("Get Semihosting stdout"),
83+
};
84+
}
85+
86+
pub fn init() {
87+
cortex_m_log::log::init(&LOGGER).unwrap();
88+
}
89+
}
90+
else {
91+
use panic_halt as _;
92+
pub fn init() {}
93+
}
94+
}

examples/utilities/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! Utilities for examples
2+
3+
pub mod logger;
4+
#[macro_use]
5+
mod power;

examples/utilities/power.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Power Configuration for examples
2+
3+
macro_rules! example_power {
4+
($pwr:ident) => {{
5+
cfg_if::cfg_if! {
6+
if #[cfg(all(feature = "smps", feature = "example-smps"))] {
7+
$pwr.smps()
8+
} else if #[cfg(all(feature = "smps", feature = "example-ldo"))] {
9+
$pwr.ldo()
10+
} else {
11+
$pwr
12+
}
13+
}
14+
}};
15+
}

memory/503.x renamed to memory.x

File renamed without changes.

src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,26 @@ compile_error!(
1111
stm32h573
1212
"
1313
);
14+
15+
#[cfg(all(feature = "rm0492", feature = "rm0481"))]
16+
compile_error!("Cannot not select both rm0492 and rm0481");
17+
18+
#[cfg(feature = "stm32h503")]
19+
pub use stm32h5::stm32h503 as stm32;
20+
21+
#[cfg(any(
22+
feature = "stm32h562",
23+
feature = "stm32h563",
24+
feature = "stm32h573",
25+
))]
26+
pub use stm32h5::stm32h573 as stm32;
27+
28+
#[cfg(feature = "device-selected")]
29+
pub use crate::stm32 as pac;
30+
#[cfg(feature = "device-selected")]
31+
pub use crate::stm32 as device;
32+
33+
// Enable use of interrupt macro
34+
#[cfg(feature = "rt")]
35+
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
36+
pub use crate::stm32::interrupt;

0 commit comments

Comments
 (0)