Skip to content

Commit 9d4b464

Browse files
committed
initial stm32g0 support
1 parent 06f6138 commit 9d4b464

30 files changed

+218
-59
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ all: patch svd2rust
55
SHELL := /bin/bash
66

77
CRATES := stm32f0 stm32f1 stm32f2 stm32f3 stm32f4 stm32f7 stm32h7 \
8-
stm32l0 stm32l1 stm32l4
8+
stm32l0 stm32l1 stm32l4 stm32g0
99

1010
# All yaml files in devices/ will be used to patch an SVD
1111
YAMLS := $(wildcard devices/*.yaml)

devices/stm32g0x0.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
_svd: ../svd/stm32g0x0.svd
2+
3+
_include:
4+
- ./common_patches/merge_USART_CR1_DEATx_fields.yaml
5+
- ./common_patches/merge_USART_CR2_ADDx_fields.yaml
6+
- ./common_patches/merge_USART_CR2_ABRMODx_fields.yaml
7+
- ./common_patches/merge_USART_CR1_DEDTx_fields.yaml
8+
- ./common_patches/merge_LPUART_CR1_DEATx_fields.yaml
9+
- ./common_patches/merge_LPUART_CR1_DEDTx_fields.yaml
10+
- ./common_patches/rename_LPUART_CR2_DATAINV_field.yaml
11+
- ./common_patches/merge_LPUART_CR2_ADDx_fields.yaml
12+
- ./common_patches/rename_USART_CR2_DATAINV_field.yaml
13+
- ./common_patches/merge_USART_BRR_fields.yaml
14+
- ../peripherals/crc/crc_basic.yaml
15+
- ../peripherals/wwdg/wwdg.yaml
16+
- ../peripherals/tim/tim_basic.yaml
17+
- ../peripherals/tim/tim6.yaml
18+
- ../peripherals/tim/tim2_32bit.yaml
19+
- ../peripherals/iwdg/iwdg_with_WINR.yaml
20+
- ../peripherals/usart/usart_v2B1.yaml

devices/stm32g0x1.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_svd: ../svd/stm32g0x1.svd

scripts/makecrates.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"stm32l0": ["rt", "stm32l0x1", "stm32l0x2", "stm32l0x3"],
3131
"stm32l1": ["rt", "stm32l100", "stm32l151", "stm32l162"],
3232
"stm32l4": ["rt", "stm32l4x1", "stm32l4x5"],
33+
"stm32g0": ["rt", "stm32g0x0", "stm32g0x1"],
3334
}
3435

3536
CARGO_TOML_TPL = """\
@@ -38,7 +39,7 @@
3839
version = "{version}"
3940
authors = ["Adam Greig <[email protected]>"]
4041
description = "Device support crates for {family} devices"
41-
repository = "https://github.com/adamgreig/stm32-rs"
42+
repository = "https://github.com/stm32-rs/stm32-rs"
4243
readme = "README.md"
4344
keywords = ["stm32", "svd2rust", "no_std", "embedded"]
4445
categories = ["embedded", "no-std"]
@@ -186,7 +187,7 @@ def make_device_clauses(devices):
186187
return " else ".join("""\
187188
if env::var_os("CARGO_FEATURE_{}").is_some() {{
188189
"src/{}/device.x"
189-
}}""".format(d.upper(), d) for d in sorted(devices)) + \
190+
}}""".strip().format(d.upper(), d) for d in sorted(devices)) + \
190191
" else { panic!(\"No device features selected\"); }"
191192

192193

stm32_part_table.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,21 @@ stm32l4:
449449
- STM32L486
450450
- STM32L496
451451
- STM32L4A6
452+
453+
stm32g0:
454+
stm32g0x0:
455+
url: https://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32-mainstream-mcus/stm32g0-series/stm32g0x0-value-line.html
456+
rm: RM0454
457+
rm_title: STM32G070xx
458+
rm_url: https://www.st.com/resource/en/reference_manual/dm00463896.pdf
459+
members:
460+
- STM32G070
461+
462+
stm32g0x1:
463+
url: https://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32-mainstream-mcus/stm32g0-series/stm32g0x1.html
464+
rm: RM0444
465+
rm_title: STM32G071xx, STM32G081xx
466+
rm_url: https://www.st.com/resource/en/reference_manual/dm00371828.pdf
467+
members:
468+
- STM32G071
469+
- STM32G081

stm32f0/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "stm32f0"
33
version = "0.5.0"
44
authors = ["Adam Greig <[email protected]>"]
55
description = "Device support crates for STM32F0 devices"
6-
repository = "https://github.com/adamgreig/stm32-rs"
6+
repository = "https://github.com/stm32-rs/stm32-rs"
77
readme = "README.md"
88
keywords = ["stm32", "svd2rust", "no_std", "embedded"]
99
categories = ["embedded", "no-std"]

stm32f0/build.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ fn main() {
55
if env::var_os("CARGO_FEATURE_RT").is_some() {
66
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
77
println!("cargo:rustc-link-search={}", out.display());
8-
let device_file = if env::var_os("CARGO_FEATURE_STM32F0X0").is_some() {
8+
let device_file = if env::var_os("CARGO_FEATURE_STM32F0X0").is_some() {
99
"src/stm32f0x0/device.x"
10-
} else if env::var_os("CARGO_FEATURE_STM32F0X1").is_some() {
10+
} else if env::var_os("CARGO_FEATURE_STM32F0X1").is_some() {
1111
"src/stm32f0x1/device.x"
12-
} else if env::var_os("CARGO_FEATURE_STM32F0X2").is_some() {
12+
} else if env::var_os("CARGO_FEATURE_STM32F0X2").is_some() {
1313
"src/stm32f0x2/device.x"
14-
} else if env::var_os("CARGO_FEATURE_STM32F0X8").is_some() {
14+
} else if env::var_os("CARGO_FEATURE_STM32F0X8").is_some() {
1515
"src/stm32f0x8/device.x"
1616
} else { panic!("No device features selected"); };
1717
fs::copy(device_file, out.join("device.x")).unwrap();

stm32f1/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "stm32f1"
33
version = "0.5.0"
44
authors = ["Adam Greig <[email protected]>"]
55
description = "Device support crates for STM32F1 devices"
6-
repository = "https://github.com/adamgreig/stm32-rs"
6+
repository = "https://github.com/stm32-rs/stm32-rs"
77
readme = "README.md"
88
keywords = ["stm32", "svd2rust", "no_std", "embedded"]
99
categories = ["embedded", "no-std"]

stm32f1/build.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ fn main() {
55
if env::var_os("CARGO_FEATURE_RT").is_some() {
66
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
77
println!("cargo:rustc-link-search={}", out.display());
8-
let device_file = if env::var_os("CARGO_FEATURE_STM32F100").is_some() {
8+
let device_file = if env::var_os("CARGO_FEATURE_STM32F100").is_some() {
99
"src/stm32f100/device.x"
10-
} else if env::var_os("CARGO_FEATURE_STM32F101").is_some() {
10+
} else if env::var_os("CARGO_FEATURE_STM32F101").is_some() {
1111
"src/stm32f101/device.x"
12-
} else if env::var_os("CARGO_FEATURE_STM32F102").is_some() {
12+
} else if env::var_os("CARGO_FEATURE_STM32F102").is_some() {
1313
"src/stm32f102/device.x"
14-
} else if env::var_os("CARGO_FEATURE_STM32F103").is_some() {
14+
} else if env::var_os("CARGO_FEATURE_STM32F103").is_some() {
1515
"src/stm32f103/device.x"
16-
} else if env::var_os("CARGO_FEATURE_STM32F107").is_some() {
16+
} else if env::var_os("CARGO_FEATURE_STM32F107").is_some() {
1717
"src/stm32f107/device.x"
1818
} else { panic!("No device features selected"); };
1919
fs::copy(device_file, out.join("device.x")).unwrap();

stm32f2/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "stm32f2"
33
version = "0.5.0"
44
authors = ["Adam Greig <[email protected]>"]
55
description = "Device support crates for STM32F2 devices"
6-
repository = "https://github.com/adamgreig/stm32-rs"
6+
repository = "https://github.com/stm32-rs/stm32-rs"
77
readme = "README.md"
88
keywords = ["stm32", "svd2rust", "no_std", "embedded"]
99
categories = ["embedded", "no-std"]

stm32f2/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ fn main() {
55
if env::var_os("CARGO_FEATURE_RT").is_some() {
66
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
77
println!("cargo:rustc-link-search={}", out.display());
8-
let device_file = if env::var_os("CARGO_FEATURE_STM32F215").is_some() {
8+
let device_file = if env::var_os("CARGO_FEATURE_STM32F215").is_some() {
99
"src/stm32f215/device.x"
10-
} else if env::var_os("CARGO_FEATURE_STM32F217").is_some() {
10+
} else if env::var_os("CARGO_FEATURE_STM32F217").is_some() {
1111
"src/stm32f217/device.x"
1212
} else { panic!("No device features selected"); };
1313
fs::copy(device_file, out.join("device.x")).unwrap();

stm32f3/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "stm32f3"
33
version = "0.5.0"
44
authors = ["Adam Greig <[email protected]>"]
55
description = "Device support crates for STM32F3 devices"
6-
repository = "https://github.com/adamgreig/stm32-rs"
6+
repository = "https://github.com/stm32-rs/stm32-rs"
77
readme = "README.md"
88
keywords = ["stm32", "svd2rust", "no_std", "embedded"]
99
categories = ["embedded", "no-std"]

stm32f3/build.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ fn main() {
55
if env::var_os("CARGO_FEATURE_RT").is_some() {
66
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
77
println!("cargo:rustc-link-search={}", out.display());
8-
let device_file = if env::var_os("CARGO_FEATURE_STM32F301").is_some() {
8+
let device_file = if env::var_os("CARGO_FEATURE_STM32F301").is_some() {
99
"src/stm32f301/device.x"
10-
} else if env::var_os("CARGO_FEATURE_STM32F302").is_some() {
10+
} else if env::var_os("CARGO_FEATURE_STM32F302").is_some() {
1111
"src/stm32f302/device.x"
12-
} else if env::var_os("CARGO_FEATURE_STM32F303").is_some() {
12+
} else if env::var_os("CARGO_FEATURE_STM32F303").is_some() {
1313
"src/stm32f303/device.x"
14-
} else if env::var_os("CARGO_FEATURE_STM32F373").is_some() {
14+
} else if env::var_os("CARGO_FEATURE_STM32F373").is_some() {
1515
"src/stm32f373/device.x"
16-
} else if env::var_os("CARGO_FEATURE_STM32F3X4").is_some() {
16+
} else if env::var_os("CARGO_FEATURE_STM32F3X4").is_some() {
1717
"src/stm32f3x4/device.x"
18-
} else if env::var_os("CARGO_FEATURE_STM32F3X8").is_some() {
18+
} else if env::var_os("CARGO_FEATURE_STM32F3X8").is_some() {
1919
"src/stm32f3x8/device.x"
2020
} else { panic!("No device features selected"); };
2121
fs::copy(device_file, out.join("device.x")).unwrap();

stm32f4/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "stm32f4"
33
version = "0.5.0"
44
authors = ["Adam Greig <[email protected]>"]
55
description = "Device support crates for STM32F4 devices"
6-
repository = "https://github.com/adamgreig/stm32-rs"
6+
repository = "https://github.com/stm32-rs/stm32-rs"
77
readme = "README.md"
88
keywords = ["stm32", "svd2rust", "no_std", "embedded"]
99
categories = ["embedded", "no-std"]

stm32f4/build.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ fn main() {
55
if env::var_os("CARGO_FEATURE_RT").is_some() {
66
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
77
println!("cargo:rustc-link-search={}", out.display());
8-
let device_file = if env::var_os("CARGO_FEATURE_STM32F401").is_some() {
8+
let device_file = if env::var_os("CARGO_FEATURE_STM32F401").is_some() {
99
"src/stm32f401/device.x"
10-
} else if env::var_os("CARGO_FEATURE_STM32F405").is_some() {
10+
} else if env::var_os("CARGO_FEATURE_STM32F405").is_some() {
1111
"src/stm32f405/device.x"
12-
} else if env::var_os("CARGO_FEATURE_STM32F407").is_some() {
12+
} else if env::var_os("CARGO_FEATURE_STM32F407").is_some() {
1313
"src/stm32f407/device.x"
14-
} else if env::var_os("CARGO_FEATURE_STM32F410").is_some() {
14+
} else if env::var_os("CARGO_FEATURE_STM32F410").is_some() {
1515
"src/stm32f410/device.x"
16-
} else if env::var_os("CARGO_FEATURE_STM32F411").is_some() {
16+
} else if env::var_os("CARGO_FEATURE_STM32F411").is_some() {
1717
"src/stm32f411/device.x"
18-
} else if env::var_os("CARGO_FEATURE_STM32F412").is_some() {
18+
} else if env::var_os("CARGO_FEATURE_STM32F412").is_some() {
1919
"src/stm32f412/device.x"
20-
} else if env::var_os("CARGO_FEATURE_STM32F413").is_some() {
20+
} else if env::var_os("CARGO_FEATURE_STM32F413").is_some() {
2121
"src/stm32f413/device.x"
22-
} else if env::var_os("CARGO_FEATURE_STM32F427").is_some() {
22+
} else if env::var_os("CARGO_FEATURE_STM32F427").is_some() {
2323
"src/stm32f427/device.x"
24-
} else if env::var_os("CARGO_FEATURE_STM32F429").is_some() {
24+
} else if env::var_os("CARGO_FEATURE_STM32F429").is_some() {
2525
"src/stm32f429/device.x"
26-
} else if env::var_os("CARGO_FEATURE_STM32F446").is_some() {
26+
} else if env::var_os("CARGO_FEATURE_STM32F446").is_some() {
2727
"src/stm32f446/device.x"
28-
} else if env::var_os("CARGO_FEATURE_STM32F469").is_some() {
28+
} else if env::var_os("CARGO_FEATURE_STM32F469").is_some() {
2929
"src/stm32f469/device.x"
3030
} else { panic!("No device features selected"); };
3131
fs::copy(device_file, out.join("device.x")).unwrap();

stm32f7/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "stm32f7"
33
version = "0.5.0"
44
authors = ["Adam Greig <[email protected]>"]
55
description = "Device support crates for STM32F7 devices"
6-
repository = "https://github.com/adamgreig/stm32-rs"
6+
repository = "https://github.com/stm32-rs/stm32-rs"
77
readme = "README.md"
88
keywords = ["stm32", "svd2rust", "no_std", "embedded"]
99
categories = ["embedded", "no-std"]

stm32f7/build.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ fn main() {
55
if env::var_os("CARGO_FEATURE_RT").is_some() {
66
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
77
println!("cargo:rustc-link-search={}", out.display());
8-
let device_file = if env::var_os("CARGO_FEATURE_STM32F7X2").is_some() {
8+
let device_file = if env::var_os("CARGO_FEATURE_STM32F7X2").is_some() {
99
"src/stm32f7x2/device.x"
10-
} else if env::var_os("CARGO_FEATURE_STM32F7X3").is_some() {
10+
} else if env::var_os("CARGO_FEATURE_STM32F7X3").is_some() {
1111
"src/stm32f7x3/device.x"
12-
} else if env::var_os("CARGO_FEATURE_STM32F7X5").is_some() {
12+
} else if env::var_os("CARGO_FEATURE_STM32F7X5").is_some() {
1313
"src/stm32f7x5/device.x"
14-
} else if env::var_os("CARGO_FEATURE_STM32F7X6").is_some() {
14+
} else if env::var_os("CARGO_FEATURE_STM32F7X6").is_some() {
1515
"src/stm32f7x6/device.x"
16-
} else if env::var_os("CARGO_FEATURE_STM32F7X7").is_some() {
16+
} else if env::var_os("CARGO_FEATURE_STM32F7X7").is_some() {
1717
"src/stm32f7x7/device.x"
18-
} else if env::var_os("CARGO_FEATURE_STM32F7X9").is_some() {
18+
} else if env::var_os("CARGO_FEATURE_STM32F7X9").is_some() {
1919
"src/stm32f7x9/device.x"
2020
} else { panic!("No device features selected"); };
2121
fs::copy(device_file, out.join("device.x")).unwrap();

stm32g0/Cargo.toml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "stm32g0"
3+
version = "0.5.0"
4+
authors = ["Adam Greig <[email protected]>"]
5+
description = "Device support crates for STM32G0 devices"
6+
repository = "https://github.com/stm32-rs/stm32-rs"
7+
readme = "README.md"
8+
keywords = ["stm32", "svd2rust", "no_std", "embedded"]
9+
categories = ["embedded", "no-std"]
10+
license = "MIT/Apache-2.0"
11+
12+
[dependencies]
13+
bare-metal = "0.2.4"
14+
vcell = "0.1.0"
15+
cortex-m = "0.5.8"
16+
17+
[dependencies.cortex-m-rt]
18+
optional = true
19+
version = "0.6.7"
20+
21+
[package.metadata.docs.rs]
22+
features = ['rt', 'stm32g0x0', 'stm32g0x1']
23+
24+
[features]
25+
default = []
26+
rt = ["cortex-m-rt/device"]
27+
stm32g0x0 = []
28+
stm32g0x1 = []

stm32g0/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# stm32g0
2+
This crate provides an autogenerated API for access to STM32G0 peripherals.
3+
The API is generated using [svd2rust] with patched svd files containing
4+
extensive type-safe support. For more information please see the [main repo].
5+
6+
[svd2rust]: https://github.com/japaric/svd2rust
7+
[main repo]: https://github.com/adamgreig/stm32-rs
8+
9+
## Usage
10+
Each device supported by this crate is behind a feature gate so that you only
11+
compile the device(s) you want. To use, in your Cargo.toml:
12+
13+
```toml
14+
[dependencies.stm32g0]
15+
version = "0.5.0"
16+
features = ["stm32g0x0", "rt"]
17+
```
18+
19+
The `rt` feature is optional and brings in support for `cortex-m-rt`.
20+
21+
In your code:
22+
23+
```rust
24+
extern crate stm32g0;
25+
use stm32g0::stm32g0x0;
26+
27+
let mut peripherals = stm32g0x0::Peripherals::take().unwrap();
28+
let gpioa = &peripherals.GPIOA;
29+
gpioa.odr.modify(|_, w| w.odr0().set_bit());
30+
```
31+
32+
For full details on the autogenerated API, please see:
33+
https://docs.rs/svd2rust/0.14.0/svd2rust/#peripheral-api
34+
35+
## Supported Devices
36+
37+
| Module | Devices | Links |
38+
|:------:|:-------:|:-----:|
39+
| stm32g0x0 | STM32G070 | [RM0454](https://www.st.com/resource/en/reference_manual/dm00463896.pdf), [st.com](https://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32-mainstream-mcus/stm32g0-series/stm32g0x0-value-line.html) |
40+
| stm32g0x1 | STM32G071, STM32G081 | [RM0444](https://www.st.com/resource/en/reference_manual/dm00371828.pdf), [st.com](https://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32-mainstream-mcus/stm32g0-series/stm32g0x1.html) |

stm32g0/build.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::env;
2+
use std::fs;
3+
use std::path::PathBuf;
4+
fn main() {
5+
if env::var_os("CARGO_FEATURE_RT").is_some() {
6+
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
7+
println!("cargo:rustc-link-search={}", out.display());
8+
let device_file = if env::var_os("CARGO_FEATURE_STM32G0X0").is_some() {
9+
"src/stm32g0x0/device.x"
10+
} else if env::var_os("CARGO_FEATURE_STM32G0X1").is_some() {
11+
"src/stm32g0x1/device.x"
12+
} else { panic!("No device features selected"); };
13+
fs::copy(device_file, out.join("device.x")).unwrap();
14+
println!("cargo:rerun-if-changed={}", device_file);
15+
}
16+
println!("cargo:rerun-if-changed=build.rs");
17+
}

stm32g0/src/lib.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Peripheral access API for STM32G0 microcontrollers
2+
//! (generated using [svd2rust](https://github.com/rust-embedded/svd2rust)
3+
//! 0.14.0)
4+
//!
5+
//! You can find an overview of the API here:
6+
//! https://docs.rs/svd2rust/0.14.0/svd2rust/#peripheral-api
7+
//!
8+
//! For more details see the README here:
9+
//! https://github.com/adamgreig/stm32-rs
10+
//!
11+
//! This crate supports all STM32G0 devices; for the complete list please
12+
//! see:
13+
//! https://github.com/adamgreig/stm32-rs/tree/master/STM32G0
14+
//!
15+
//! Due to doc build limitations, not all devices may be shown on docs.rs;
16+
//! a representative few have been selected instead. For a complete list of
17+
//! available registers and fields see: https://stm32.agg.io/rs
18+
19+
#![allow(non_camel_case_types)]
20+
#![no_std]
21+
22+
extern crate vcell;
23+
extern crate bare_metal;
24+
extern crate cortex_m;
25+
26+
#[cfg(feature = "rt")]
27+
extern crate cortex_m_rt;
28+
29+
#[cfg(feature = "stm32g0x0")]
30+
pub mod stm32g0x0;
31+
32+
#[cfg(feature = "stm32g0x1")]
33+
pub mod stm32g0x1;
34+

0 commit comments

Comments
 (0)