~ruther/avr-device

c15bfe54e77c3b8f840f8a50ac2672bcdba2855a — octycs 5 years ago c7d5680
Integrate patching in the build process
3 files changed, 18 insertions(+), 8 deletions(-)

M Makefile
M README.md
M patch/svdpatch.py
M Makefile => Makefile +6 -2
@@ 9,9 9,13 @@ svd/%.bare.svd: vendor/%.atdf
	mkdir -p svd
	atdf2svd $< $@

# TODO: Implement actual patching
svd/%.patched.svd: svd/%.bare.svd
	cp $< $@
	if [ -f patch/$*.yaml ] ; then \
		python3 patch/svdpatch.py patch/$*.yaml $< $@; \
	else \
		echo "No patches found for $*"; \
		cp $< $@; \
	fi

src/devices/%/mod.full.rs: svd/%.patched.svd
	mkdir -p $(@D)

M README.md => README.md +3 -2
@@ 3,7 3,7 @@ avr-device
Auto-generated wrappers around registers for avr chips.

## Usage
You need to have [atdf2svd](https://github.com/Rahix/atdf2svd), [svd2rust](https://github.com/rust-embedded/svd2rust), [form](https://github.com/djmcgill/form), and [rustfmt](https://github.com/rust-lang/rustfmt) installed:
You need to have [atdf2svd](https://github.com/Rahix/atdf2svd), [svd2rust](https://github.com/rust-embedded/svd2rust), [form](https://github.com/djmcgill/form), [rustfmt](https://github.com/rust-lang/rustfmt) and [PyYAML](https://github.com/yaml/pyyaml) installed:
```bash
rustup component add rustfmt
cargo install form


@@ 11,6 11,7 @@ cargo install svd2rust
git clone https://github.com/Rahix/atdf2svd
cd atdf2svd
cargo install --path .
pip3 install --user pyyaml
```

Next, clone this repo and build the device definitions:


@@ 38,7 39,7 @@ Via the feature you can select which chip you want the register specifications f
* `attiny85`

## Internals
*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/`.  Later on, we intend to add support for patching the svd files because some information in the provided files is not quite as good as it should be (mainly undescriptive names and missing descriptions).
*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.

### Adding a new Chip
To add a new chip, download the *atdf* from <http://packs.download.atmel.com/> and place it in `vendor/`.  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 [this commit](https://github.com/Rahix/avr-device/commit/8b1679a89704f5a303a1578b261aa2aee53e1251).  Please adhere to the alphabetical sorting that is present so far.

M patch/svdpatch.py => patch/svdpatch.py +9 -4
@@ 3,6 3,9 @@ svdpatch.py

Copyright 2017-2019 Adam Greig.
Licensed under the MIT and Apache 2.0 licenses. See LICENSE files for details.

This script was adapted from stm32-rs (https://github.com/stm32-rs/stm32-rs/blob/master/scripts/svdpatch.py).
To be integrated into the build system, support for an input / output svd argument is added.
"""

import copy


@@ 35,6 38,8 @@ def parseargs():
    """Parse our command line arguments, returns a Namespace of results."""
    parser = argparse.ArgumentParser()
    parser.add_argument("yaml", help="Path to YAML file to load")
    parser.add_argument("svd_in", help="Path to the input SVD file")
    parser.add_argument("svd_out", help="Path to write the patched SVD file")
    args = parser.parse_args()
    return args



@@ 774,10 779,10 @@ def main():
        root["_path"] = args.yaml

    # Load the specified SVD file
    if "_svd" not in root:
        raise RuntimeError("You must have an svd key in the root YAML file")
    svdpath = abspath(args.yaml, root["_svd"])
    svdpath_out = svdpath + ".patched"
    svdpath = args.svd_in
    if not os.path.exists(svdpath):
        raise FileNotFoundError("The input SVD file does not exist")
    svdpath_out = args.svd_out
    svd = ET.parse(svdpath)

    # Load all included YAML files

Do not follow this link