This repository provides Rust device support crates for some LPC microcontrollers, providing an API to that device's peripherals using svd2rust and the SVD files from NXP. These crates are commonly known as peripheral access crates or "PACs".
Not every register of each device will have been tested on hardware, and so errors or omissions may remain. Please report any bugs you find, or open a PR!
In your own project's Cargo.toml
:
[dependencies.lpc546xx-pac]
version = "x.y.z"
features = ["lpc54608", "rt"]
The rt
feature is optional but helpful. see svd2rust for details.
Then, in your code:
use lpc54606_pac as pac;
let mut peripherals = pac::Peripherals::take().unwrap();
Refer to svd2rust
documentation for further usage.
Replace lpc54606_pac
with your own device; see the individual crate READMEs for the complete list of supported devices.
- Install svd2rust:
cargo install --version 0.25.0 svd2rust
- Install form:
cargo install form --version 0.10.0
- Install rustfmt:
rustup component add rustfmt
- Install svdtools:
cargo install svdtools --version 0.2.7
- Unzip bundled SVD zip files:
cd svd; ./extract.sh; cd ..
- Generate patched SVD files:
make patch -j8
- Generate svd2rust device crates:
make svd2rust -j8
- Optional: Format device crates:
make form -j8
- Install
svd2rust
:cargo install --version 0.24.0 svd2rust
- Install
form
:cargo install --version 0.8.0
- Install
rustfmt
:rustup component add rustfmt
- Generate the PACs:
./generate.sh
- 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 device in
lpc_part_table
- Add family/device (if necessary) in
Makefile
>PACS
- Add family/device (if necessary) in
scripts/makecrates.py
> - 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.
- You'll need to run
svd/extract.sh
at least once to pull the SVDs out. - Edit the device or peripheral YAML (see below for format).
- Run
make
to rebuild all the crates usingsvd patch
andsvd2rust
. - Test your new stuff compiles:
cd lpc546xx-pac; cargo build --features lpc54628