|
18 | 18 | //! |
19 | 19 | //! # Usage |
20 | 20 | //! |
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. |
27 | 26 | //! |
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. |
30 | 28 | //! |
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 |
35 | 30 | //! |
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: |
39 | 33 | //! |
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 |
45 | 37 | //! |
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`: |
47 | 41 | //! |
48 | | -//! /// Interrupts |
49 | | -//! pub mod interrupt { |
50 | | -//! // .. |
51 | | -//! } |
| 42 | +//! [`form`]: https://crates.io/crates/form |
52 | 43 | //! |
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 |
62 | 46 | //! |
63 | | -//! /// General-purpose I/Os |
64 | | -//! pub struct GPIOA { _marker: PhantomData<*const ()> } |
| 47 | +//! $ rm -rf src |
65 | 48 | //! |
66 | | -//! unsafe impl Send for GPIOA {} |
| 49 | +//! $ form -i lib.rs -o src/ && rm lib.rs |
67 | 50 | //! |
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 | +//! ``` |
74 | 53 | //! |
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: |
77 | 58 | //! |
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" |
82 | 65 | //! |
83 | | -//! // .. |
| 66 | +//! [features] |
| 67 | +//! rt = ["cortex-m-rt/device"] |
84 | 68 | //! ``` |
85 | 69 | //! |
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 | +//! ``` |
87 | 84 | //! |
88 | | -//! The generated crate depends on: |
| 85 | +//! The resulting crate must provide an opt-in "rt" feature and depend on these crates: |
89 | 86 | //! |
90 | 87 | //! - [`bare-metal`](https://crates.io/crates/bare-metal) v0.1.x |
91 | 88 | //! - [`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 | +//! ``` |
102 | 107 | //! |
103 | 108 | //! # Peripheral API |
104 | 109 | //! |
|
409 | 414 | //! If the "rt" Cargo feature of the svd2rust generated crate is enabled the crate will populate the |
410 | 415 | //! part of the vector table that contains the interrupt vectors and provide an |
411 | 416 | //! [`interrupt!`](macro.interrupt.html) macro that can be used to register interrupt handlers. |
412 | | -//! |
| 417 | +//! |
413 | 418 | //! ## the `--nightly` flag |
414 | 419 | //! |
415 | 420 | //! The `--nightly` flag can be passed to `svd2rust` to enable features in the generated api that are only available to a nightly |
416 | 421 | //! compiler. These features are |
417 | | -//! |
| 422 | +//! |
418 | 423 | //! - `#[feature(untagged_unions)]` for overlapping/overloaded registers |
419 | 424 |
|
420 | 425 | // NOTE This file is for documentation only |
|
0 commit comments