Skip to content

Commit cea8610

Browse files
authored
Setup defmt and probe run (#58)
* Update dependencies for using defmt/probe-run Setup probe-run configuration for easier running of examples Update vscode settings for rust analyzer Add panic example for testing defmt panic logging setup
1 parent 54587a9 commit cea8610

File tree

5 files changed

+68
-14
lines changed

5 files changed

+68
-14
lines changed

.cargo/config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[target.thumbv7em-none-eabihf]
2-
runner = 'arm-none-eabi-gdb -q -x openocd.gdb'
2+
runner = 'probe-run --connect-under-reset'
33
rustflags = [
4-
"-C", "link-arg=-Tlink.x"
4+
"-C", "link-arg=-Tlink.x",
5+
"-C", "link-arg=-Tdefmt.x",
56
]
67

78
[build]

.vscode/settings.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
2-
"rust.all_targets": false,
3-
"rust.target": "thumbv7em-none-eabihf",
4-
"rust.all_features": false,
5-
"rust.features": [
6-
"rt",
7-
"stm32g431"
2+
"rust-analyzer.check.allTargets": false,
3+
"rust-analyzer.check.extraArgs": [
4+
"--examples",
5+
],
6+
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
7+
"rust-analyzer.cargo.features": [
8+
"stm32g473",
9+
"defmt-logging",
810
]
911
}

Cargo.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ repository = "https://github.com/stm32-rs/stm32g4xx-hal"
1212
version = "0.0.0"
1313

1414
[dependencies]
15-
cortex-m = "0.7.1"
1615
nb = "0.1.1"
1716
stm32g4 = "0.14.0"
1817
paste = "1.0"
1918
bitflags = "1.2"
2019
vcell = "0.1"
2120
static_assertions = "1.1"
2221

22+
[dependencies.cortex-m]
23+
version = "0.7.7"
24+
features = ["critical-section-single-core"]
25+
2326
[dependencies.cast]
2427
version = "0.2.7"
2528
default-features = false
@@ -44,13 +47,15 @@ default-features = false
4447
version = "1.1"
4548

4649
[dependencies.defmt]
47-
version = "0.3.0"
50+
version = "0.3.2"
4851
optional = true
4952

5053
[dev-dependencies]
51-
cortex-m-rt = "0.6.10"
52-
cortex-m-rtfm = "0.5.1"
54+
cortex-m-rt = "0.7.2"
55+
defmt-rtt = "0.4.0"
56+
cortex-m-rtic = "0.5.8"
5357
cortex-m-semihosting = "0.3.5"
58+
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
5459
panic-semihosting = "0.5.3"
5560
panic-halt = "0.2.0"
5661
panic-itm = "0.4.2"
@@ -80,7 +85,7 @@ stm32g4a1 = ["stm32g4/stm32g4a1"]
8085
log-itm = ["cortex-m-log/itm"]
8186
log-rtt = []
8287
log-semihost = ["cortex-m-log/semihosting"]
83-
unstable-defmt = ["defmt"]
88+
defmt-logging = ["defmt"]
8489

8590
[profile.dev]
8691
codegen-units = 1

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,26 @@ If you are compiling the crate on its own for development or running examples,
2929
specify your microcontroller on the command line. For example:
3030

3131
```
32-
cargo build --example blinky
32+
cargo build --example blinky --features stm32g473
3333
```
3434

35+
## Running examples
36+
37+
Examples can be built and run using `cargo run`. It is necessary to provide any
38+
required features followed by the name of the chip.
39+
40+
```
41+
cargo run --example usb_serial --features stm32g473 --features usb_fs --release -- --chip STM32G473RETx
42+
```
43+
44+
A list of chips supported by probe-rs can be found by running
45+
46+
```
47+
probe-run --list-chips
48+
```
49+
50+
For furher information, see the documentation for [probe-run](https://github.com/knurling-rs/probe-run).
51+
3552
### Using as a Dependency
3653

3754
When using this crate as a dependency in your project, the microcontroller can

examples/panic.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
use defmt_rtt as _;
5+
6+
use panic_probe as _;
7+
8+
use stm32g4 as _;
9+
10+
use defmt::Format;
11+
12+
#[defmt::panic_handler]
13+
fn panic() -> ! {
14+
cortex_m::asm::udf()
15+
}
16+
17+
pub fn exit() -> ! {
18+
loop {
19+
cortex_m::asm::bkpt();
20+
}
21+
}
22+
23+
#[cortex_m_rt::entry]
24+
fn main() -> ! {
25+
defmt::info!("main");
26+
27+
panic!("Something bad");
28+
// defmt::panic!()
29+
}

0 commit comments

Comments
 (0)