You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This replaces the AoT processing we did to generate the Rust modules
locally. It generates them on the fly at build-time, and only for the
selected MCUs. The process is mostly the same, just automated, with the
addition of what is described in the next paragraph. Some things became
unnecessary though, such as the `modrs.patch` and `Makefile`, and
therefore were removed. `form` is no longer run, in order to minimize
the number of files and directories. The patches were updated to not
have the `_svd` key, since that's now handled by the build script. Those
that ended up empty were removed.
It also updates our `interrupt` macro, adapting it from a newer
iteration of `cortex-m-rt`'s and adding logic to make the vector module
unnecessary. It would be hard to generate it correctly for the macros
crate, since it compiles before the main one where the build logic is
hosted. Instead, we generate a macro `__avr_device_trampoline` in the
main crate, and `#[interrupt(chip)]` calls into that giving the MCU
name, interrupt name and trampoline item to define. This new macro
converts the interrupt's name into a `__vector_N` symbol, which the
linker understands as being an interrupt, and changes the function's
name to it with `#[export_name = "..."]`.
CI code was updated as well.
Co-authored-by: Rahix <[email protected]>
Co-authored-by: tones111 <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+59-40Lines changed: 59 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -38,48 +38,67 @@ Via the feature you can select which chip you want the register specifications f
38
38
|||||`attiny2313a`|
39
39
40
40
## Build Instructions
41
-
The version on `crates.io` is pre-built. The following is only necessary when trying to build this crate from source.
42
-
43
-
You need to have [atdf2svd][] (= 0.5.0), [svd2rust][] (= 0.28), [form][] (>= 0.8), [rustfmt][](for the *nightly* toolchain) and [svdtools][] (= 0.4.0) installed:
Next, clone this repo and build the device definitions:
59
-
```bash
60
-
git clone https://github.com/Rahix/avr-device
61
-
cd avr-device
62
-
make
63
-
# You can build for just one specific chip using
64
-
# make atmega32u4
65
-
# I suggest building documentation as well
66
-
cargo +nightly doc --features <chip> --open
67
-
```
68
-
69
-
## Internals
70
-
*avr-device* is generated using [`atdf2svd`](https://github.com/Rahix/atdf2svd) and [`svd2rust`](https://github.com/rust-embedded/svd2rust). The vendor-provided *atdf* files can be found in `vendor/`. The intermediate svd files are patched by `svdpatch.py` (Adapted from [`svdpatch.py`](https://github.com/stm32-rs/stm32-rs/blob/master/scripts/svdpatch.py) in [stm32-rs](https://github.com/stm32-rs/stm32-rs)) with device-dependent patches in `patch/`, mainly to improve undescriptive names and missing descriptions.
41
+
The PACs (Peripheral Access Crates, or really modules, in our case) **are not**
42
+
checked into git. Rather, we generate them at build time, via an automated
43
+
process implemented in [`build.rs`](./build.rs). It takes the ATDF files
44
+
Microchip (former Atmel) provides plus some patches of our own making as inputs,
45
+
and outputs a module generated from those device descriptions. These inputs
46
+
**are** checked-in. The process is similar to what the `*bindgen` crates
47
+
provide, just has more steps. So, in short, building should be a matter of
48
+
selecting the features and running cargo.
71
49
72
50
### Adding a new Chip
73
-
To add a new chip, download the *atdf* from <http://packs.download.atmel.com/> (or [avr-mcu/packs/](https://github.com/avr-rust/avr-mcu/tree/master/packs)) and place it in `vendor/`***note: file name may need to be modified***. Be sure to name it like the Rust module that should be generated. Next, you need to integrate it into the base crate and build system. Follow what was done in commit [290613454fbd ("Add basic support for ATmega64")](https://github.com/Rahix/avr-device/commit/290613454fbdc5e4ac98e53deccaf74dafc88963). Please adhere to the alphabetical sorting that is present so far.
74
-
75
-
Next, you **must** create a `<chipname>.yaml` in `patch/` which has at least the following content:
76
-
```yaml
77
-
_svd: ../svd/<chipname>.svd
78
-
```
79
-
80
-
If more patches need to be applied (most likely!), they should be added into this file as well. The patching format is documented in the [`svdtools` README](https://github.com/stm32-rs/svdtools#device-and-peripheral-yaml-format). Ideally, try to reuse the exisiting patches in `patch/common/` or `patch/timer/`.
81
-
82
-
Finally, try building the crate for your MCU with `make <chipname>`.
51
+
To add a new chip:
52
+
53
+
1. Download the ATDF from <http://packs.download.atmel.com/> and place it in
54
+
`vendor/`. Be sure to name it like the Rust module that should be generated.
55
+
2. Add a feature of the same name to `Cargo.toml` (it should enable
56
+
`device-selected`);
57
+
3. Add any needed patches to a yaml file with the same name under the `patch`
58
+
directory, ideally by including some of the snippets present in
59
+
`patch/common` and `patch/timer`; The format is decribed
0 commit comments