This repo is modified from stm32-rs
This repository provides Rust device support crates for all py32 microcontrollers, providing a safe API to that device's peripherals using svd2rust and a community-built collection of patches to the basic SVD files. There is one crate per device family, and each supported device is a feature-gated module in that crate. These crates are commonly known as peripheral access crates or "PACs".
The py32-rs repository contains the patches to the underlying SVD files and the tooling to generate the crates.
While these crates are widely used, not every register of every device will have been tested on hardware, and so errors or omissions may remain. We can't make any guarantee of correctness. Please report any bugs you find!
In your own project's Cargo.toml
:
[dependencies.py32f0]
version = "0.1.1"
features = ["py32f030"]
The rt
feature is optional but helpful. See
svd2rust for
details.
Then, in your code:
use py32f0::py32f030;
let mut peripherals = py32f030::Peripherals::take().unwrap();
Refer to svd2rust
documentation for further usage.
Replace py32f0
and py32f030
with your own device; see the individual
crate READMEs for the complete list of supported devices. All current py32
devices should be supported to some level.
- Install
svd2rust
,svdtools
, andform
:- On x86-64 Linux, run
make install
to download pre-built binaries at the current version used by py32-rs - Otherwise, build using
cargo
(double check versions againstscripts/tool_install.sh
):cargo install form --version 0.12.1
cargo install svdtools --version 0.3.14
cargo install svd2rust --version 0.28.0 --locked
cargo install svd2html --version 0.1.3
- On x86-64 Linux, run
- Install rustfmt:
rustup component add rustfmt
- Unzip bundled SVD zip files:
cd svd; ./extract.sh; cd ..
- Generate patched SVD files:
make patch
(you probably want-j
for allmake
invocations) - Generate svd2rust device crates:
make svd2rust
- Optional: Format device crates:
make form
This project serves two purposes:
- Create a source of high-quality py32 SVD files, with manufacturer errors and inconsistencies fixed. These files could be used with svd2rust or other tools, or in other projects. They should hopefully be useful in their own right.
- Create and publish svd2rust-generated crates covering all py32s, using the SVD files.
When this project began, many individual crates existed for specific py32 devices, typically maintained separately with hand-edited updates to the SVD files. This project hopes to reduce that duplication of effort and centralise the community's py32 device support in one place.
This project is still young and there's a lot to do!
- More peripheral patches need to be written, most of all. See what we've got
in
peripherals/
and grab a reference manual! - Also everything needs testing, and you can't so easily automate finding bugs in the SVD files...
Please see the individual crate READMEs for the full list of devices each crate supports.
- Update SVD zips in
svd/vendor
to include new SVD. - Run
svd/extract.sh
to extract the zips intosvd
(ignored in git). - Add new YAML file in
devices/
with the new SVD path and include any required SVD patches for this device, such as renaming or merging fields. - Add the new devices to
py32_part_table.yaml
. - Add the new devices
scripts/makecrates.py
. - You can run
scripts/matchperipherals.py
script to find out what existing peripherals could be cleanly applied to this new SVD. If they look sensible, you can include them in your device YAML. This requires a Python environment with thepyyaml
andsvdtools
dependencies. Example command:python scripts/matchperipherals.py peripherals/rcc devices/py32f030.yaml
- Re-run
scripts/makecrates.py devices/
to update the crates with the new devices. - Run
make
to rebuild, which will make a patched SVD and then runsvd2rust
on it to generate the final library.
If adding a new py32 family (not just a new device to an existing family), complete these steps as well:
- Add the new devices to the
CRATES
field inMakefile
. - Update this Readme to include the new devices.
- Add the devices to
workflows/ci.yaml
.
- Using Linux, run
svd/extract.sh
at least once to pull the SVDs out. - Edit the device or peripheral YAML (see below for format).
- Using Linux, run
make
to rebuild all the crates usingsvd patch
andsvd2rust
. - Test your new stuff compiles:
cd py32f0; cargo build --features py32f030
If you've added a new peripheral, consider using the matchperipherals.py
script to see which devices it would cleanly apply to.
To generate a new peripheral file from scratch, consider using
periphtemplate.py
, which creates an empty peripheral file based on a single
SVD file, with registers and fields ready to be populated. For single bit wide
fields with names ending in 'E' or 'D' it additionally generates sample
"Enabled"/"Disabled" entries to save time.
Please see the svdtools documentation for full details of the patch file format.
- Enumerated values should be named in the past tense ("enabled", "masked", etc).
- Descriptions should start with capital letters but do not end with a period
Notes for maintainers:
- Create PR preparing for new release:
- Update
CHANGELOG.md
with changes since last release and new contributors - Update
README.md
to bump version number in example snippet - Update
scripts/makecrates.py
to update version number for generated PACs
- Update
- Merge PR once CI passes, pull master locally.
make clean
make -j16 form
cd py32f0; pwd; cargo publish --allow-dirty --no-default-features
git tag -a vX.X.X -m vX.X.X
git push origin vX.X.X
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.