DeviceDefinitions.jl

A package to generate microcontroller definitions from SVD files.
Author Seelengrab
Popularity
2 Stars
Updated Last
1 Year Ago
Started In
October 2023

DeviceDefinitions

A code generator for creating Julia projects from SVD files.

This package is based on https://www.keil.com/pack/doc/CMSIS/SVD/html/index.html, but not a complete implementation of the specification. If you get an error or warning while using this package, please open an issue (with the SVD in question included, if possible).

Known not working:

  • Deriving registers/fields from registers/fields that are not direct siblings.
  • This is mostly because I don't have an example SVD making use of that feature.

Additionally, it's possible that some definitions generated by this package could have a bug; make sure to check the generated code for compliance with your SVD. Please do report any bugs discovered through this in an issue.

API

The main API of this package are generateProject and readSVD. Please check their respective docstrings for usage. In addition to these, the structs Device, Peripheral, Register, Field and CPU are also considered API. Their fieldnames are inspired by the names from the SVD specification.

Layout of generated packages

Packages generated by DeviceDefinitions.jl follow this structure (peripheral names exemplary):

Name.jl
├── Manifest.toml
├── Project.toml
└── src
    ├── peripherals
    │   ├── adc.jl
    │   ├── dma.jl
    │   ├── ...
    │   └── watchdog.jl
    ├── peripherals.jl
    ├── Name.jl
    └── SVD
        └── name.svd

The source SVD file is placed under src/SVD with its original name. When regenerating, only src/Name.jl, src/peripherals.jl and the src/peripherals directory will be deleted & regenerated. It is safe to add other directories to the project.

A single peripheral is stored in its own submodule, with each register of that peripheral also stored in its own subsubmodule. For example:

"""
    ADC

Control and data interface to ADC
"""
module ADC

const baseAddress = Ptr{UInt16}(3141592)

"""
    CS

ADC Control and Status
"""
module CSMod

using MCUCommon: @regdef, Read, Write, ReadWrite, ReadWriteOnce
using ..ADC: baseAddress

const regAddress = baseAddress + 0x0000000000000000
@regdef struct CSStruct(regAddress)
	FieldA:1::ReadWrite
	_:4
	FieldB:5::Read
	_:6
end
const Reg = CSStruct

"""
    FieldA

Description of Field A
"""
FieldA

# ... other fields of this register ...

end # register CS

# ... other registers ...

end # peripheral

To access the data of e.g. the CS register in peripheral ADC, use ADC.CSMod.Reg[], which will return a bitfield describing the register. To read a single field of that register, use ADC.CSMod.FieldA[]. Likewise, setting the register/field works through setindex! without indexing arguments.

Licensing of generated packages

Packages generated with DeviceDefinitions.jl are NOT licensed under the same license as DeviceDefinitions.jl and may be restricted through the license specified in the SVD used to generate the package.

Used By Packages

No packages found.