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.
svd2rust
, svdtools
, and form
:
make install
to download pre-built binaries at the
current version used by py32-rscargo
(double check versions against scripts/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
rustup component add rustfmt
cd svd; ./extract.sh; cd ..
make patch
(you probably want -j
for all make
invocations)make svd2rust
make form
This project serves two purposes:
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!
peripherals/
and grab a reference manual!Please see the individual crate READMEs for the full list of devices each crate supports.
svd/vendor
to include new SVD.svd/extract.sh
to extract the zips into svd
(ignored in git).devices/
with the new SVD path and include any
required SVD patches for this device, such as renaming or merging fields.py32_part_table.yaml
.scripts/makecrates.py
.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 the pyyaml
and svdtools
dependencies.
Example command: python scripts/matchperipherals.py peripherals/rcc devices/py32f030.yaml
scripts/makecrates.py devices/
to update the crates with the new devices.make
to rebuild, which will make a patched SVD and then run svd2rust
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:
CRATES
field in Makefile
.workflows/ci.yaml
.svd/extract.sh
at least once to pull the SVDs out.make
to rebuild all the crates using svd patch
and svd2rust
.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.
Notes for maintainers:
CHANGELOG.md
with changes since last release and new contributorsREADME.md
to bump version number in example snippetscripts/makecrates.py
to update version number for generated PACsmake 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
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.