Skip to content

Commit e26155b

Browse files
committed
update the docs
1 parent 65a370c commit e26155b

File tree

1 file changed

+69
-64
lines changed

1 file changed

+69
-64
lines changed

src/lib.rs

Lines changed: 69 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,87 +18,92 @@
1818
//!
1919
//! # Usage
2020
//!
21-
//! `svd2rust` supports Cortex-M and MSP430 microcontrollers. The generated
22-
//! crate can be tailored for either architecture using the `--target` flag. The
23-
//! flag accepts "cortex-m", "msp430" and "none" as values. "none" can be used
24-
//! to generate a crate that's architecture agnostic and that should work for
25-
//! architectures that `svd2rust` doesn't currently know about like the Cortex-A
26-
//! architecture.
21+
//! `svd2rust` supports Cortex-M, MSP430 and RISCV microcontrollers. The generated crate can be
22+
//! tailored for either architecture using the `--target` flag. The flag accepts "cortex-m",
23+
//! "msp430", "riscv" and "none" as values. "none" can be used to generate a crate that's
24+
//! architecture agnostic and that should work for architectures that `svd2rust` doesn't currently
25+
//! know about like the Cortex-A architecture.
2726
//!
28-
//! If the `--target` flag is omitted `svd2rust` assumes the target is the
29-
//! Cortex-M architecture.
27+
//! If the `--target` flag is omitted `svd2rust` assumes the target is the Cortex-M architecture.
3028
//!
31-
//! ```
32-
//! $ svd2rust -i STM32F30x.svd | rustfmt | tee src/lib.rs
33-
//! //! Peripheral access API for STM32F30X microcontrollers
34-
//! //! (generated using svd2rust v0.12.0)
29+
//! ## target = cortex-m
3530
//!
36-
//! #![deny(missing_docs)]
37-
//! #![deny(warnings)]
38-
//! #![no_std]
31+
//! When targeting the Cortex-M architecture `svd2rust` will generate three files in the current
32+
//! directory:
3933
//!
40-
//! extern crate bare_metal;
41-
//! extern crate cortex_m;
42-
//! #[cfg(feature = "rt")]
43-
//! extern crate cortex_m_rt;
44-
//! extern crate vcell;
34+
//! - build.rs
35+
//! - device.x
36+
//! - lib.rs
4537
//!
46-
//! use cortex_m::peripheral::Peripheral;
38+
//! All these files must be included in the same device crate. The `lib.rs` file contains several
39+
//! inlined modules and its not formatted. It's recommend to split it out using the [`form`] tool
40+
//! and then format the output using `rustfmt` / `cargo fmt`:
4741
//!
48-
//! /// Interrupts
49-
//! pub mod interrupt {
50-
//! // ..
51-
//! }
42+
//! [`form`]: https://crates.io/crates/form
5243
//!
53-
//! /// General-purpose I/Os
54-
//! pub mod gpioa {
55-
//! pub struct RegisterBlock {
56-
//! /// GPIO port mode register
57-
//! pub moder: MODER,
58-
//! ..
59-
//! }
60-
//! ..
61-
//! }
44+
//! ``` text
45+
//! $ svd2rust -i STM32F30x.svd
6246
//!
63-
//! /// General-purpose I/Os
64-
//! pub struct GPIOA { _marker: PhantomData<*const ()> }
47+
//! $ rm -rf src
6548
//!
66-
//! unsafe impl Send for GPIOA {}
49+
//! $ form -i lib.rs -o src/ && rm lib.rs
6750
//!
68-
//! impl GPIOA {
69-
//! /// Returns a pointer to the register block
70-
//! pub fn ptr() -> *const gpioa::RegisterBlock {
71-
//! 0x4800_0000 as *const _
72-
//! }
73-
//! }
51+
//! $ cargo fmt
52+
//! ```
7453
//!
75-
//! impl core::ops::Deref for GPIOA {
76-
//! type Target = gpioa::RegisterBlock;
54+
//! The resulting crate must provide an opt-in "rt" feature and depend on these crates:
55+
//! `bare-metal` v0.2.x, `cortex-m` v0.5.x, `cortex-m-rt` v0.5.x and `vcell` v0.1.x. Furthermore the
56+
//! "device" feature of `cortex-m-rt` must be enabled when the "rt" feature is enabled. The
57+
//! `Cargo.toml` of the device crate will look like this:
7758
//!
78-
//! fn deref(&self) -> &gpioa::RegisterBlock {
79-
//! unsafe { &*GPIOA::ptr() }
80-
//! }
81-
//! }
59+
//! ``` toml
60+
//! [dependencies]
61+
//! bare-metal = "0.2.0"
62+
//! cortex-m = "0.5.0"
63+
//! cortex-m-rt = "0.5.0"
64+
//! vcell = "0.1.0"
8265
//!
83-
//! // ..
66+
//! [features]
67+
//! rt = ["cortex-m-rt/device"]
8468
//! ```
8569
//!
86-
//! # Dependencies
70+
//! ## target != cortex-m
71+
//!
72+
//! When the target is msp430, riscv or none `svd2rust` will emit all the generated code to stdout.
73+
//! Like in the cortex-m case we recommend you use `form` and `rustfmt` on the output:
74+
//!
75+
//! ``` console
76+
//! $ svd2rust -i *.svd --target msp430 > lib.rs
77+
//!
78+
//! $ rm -rf src
79+
//!
80+
//! $ form -i lib.rs -o src/ && rm lib.rs
81+
//!
82+
//! $ cargo fmt
83+
//! ```
8784
//!
88-
//! The generated crate depends on:
85+
//! The resulting crate must provide an opt-in "rt" feature and depend on these crates:
8986
//!
9087
//! - [`bare-metal`](https://crates.io/crates/bare-metal) v0.1.x
9188
//! - [`vcell`](https://crates.io/crates/vcell) v0.1.x
92-
//! - [`cortex-m-rt`](https://crates.io/crates/cortex-m-rt) v0.3.x if targeting
93-
//! the Cortex-M architecture.
94-
//! - [`cortex-m`](https://crates.io/crates/cortex-m) v0.4.x if targeting the
95-
//! Cortex-M architecture.
96-
//! - [`msp430`](https://crates.io/crates/msp430) v0.1.x if targeting the MSP430
97-
//! architecture.
98-
//! - [`msp430-rt`](https://crates.io/crates/msp430-rt) v0.1.x if targeting the
99-
//! MSP430 architecture.
100-
//! - [`riscv-rt`](https://crates.io/crates/riscv-rt) v0.2.x if targeting the
101-
//! RISCV architecture.
89+
//! - [`msp430`](https://crates.io/crates/msp430) v0.1.x if target = msp430.
90+
//! - [`msp430-rt`](https://crates.io/crates/msp430-rt) v0.1.x if target = msp430.
91+
//! - [`riscv`](https://crates.io/crates/riscv) v0.2.x if target = riscv.
92+
//! - [`riscv-rt`](https://crates.io/crates/riscv-rt) v0.2.x if target = riscv.
93+
//!
94+
//! The `*-rt` dependencies must be optional only enabled when the "rt" feature is enabled. The
95+
//! `Cargo.toml` of the device crate will look like this for an msp430 target:
96+
//!
97+
//! ``` toml
98+
//! [dependencies]
99+
//! bare-metal = "0.2.0"
100+
//! msp430 = "0.1.0"
101+
//! msp430-rt = "0.1.0"
102+
//! vcell = "0.1.0"
103+
//!
104+
//! [features]
105+
//! rt = ["msp430"]
106+
//! ```
102107
//!
103108
//! # Peripheral API
104109
//!
@@ -409,12 +414,12 @@
409414
//! If the "rt" Cargo feature of the svd2rust generated crate is enabled the crate will populate the
410415
//! part of the vector table that contains the interrupt vectors and provide an
411416
//! [`interrupt!`](macro.interrupt.html) macro that can be used to register interrupt handlers.
412-
//!
417+
//!
413418
//! ## the `--nightly` flag
414419
//!
415420
//! The `--nightly` flag can be passed to `svd2rust` to enable features in the generated api that are only available to a nightly
416421
//! compiler. These features are
417-
//!
422+
//!
418423
//! - `#[feature(untagged_unions)]` for overlapping/overloaded registers
419424
420425
// NOTE This file is for documentation only

0 commit comments

Comments
 (0)