creatoy / py32-rs

Embedded Rust device crates for PY32 microcontrollers
Other
8 stars 1 forks source link
embedded-rust py32f0 rust svd2rust

PY32 Peripheral Access Crates

This repo is modified from stm32-rs

CI crates.io

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!

Using Device Crates In Your Own Project

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.

Generating Device Crates / Building Locally

Motivation and Objectives

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.

Helping

This project is still young and there's a lot to do!

Supported Device Families

crates.io

Please see the individual crate READMEs for the full list of devices each crate supports.

Adding New Devices

If adding a new py32 family (not just a new device to an existing family), complete these steps as well:

Updating Existing Devices/Peripherals

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.

Device and Peripheral YAML Format

Please see the svdtools documentation for full details of the patch file format.

Style Guide

Releasing

Notes for maintainers:

  1. 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
  2. Merge PR once CI passes, pull master locally.
  3. make clean
  4. make -j16 form
  5. cd py32f0; pwd; cargo publish --allow-dirty --no-default-features
  6. git tag -a vX.X.X -m vX.X.X
  7. git push origin vX.X.X

License

Licensed under either of

at your option.

Contribution

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.