This is an attempt at parsing vendor-provided data to generate
a complete database of the STM32 devices, which can be used
for code-generation purposes. Main target is to replace original
ivory-bsp-stm32 library supporting handful of devices with
a generated version supporting most of the STM32 devices.
The package contains
- parsers for SVD files
- parsers for CubeMX database files
- utilities for working with both databases
- utilities for working with peripheral registers
- ivory-bsp-stm32 library generator
- git clone https://github.com/HaskellEmbedded/data-stm32
- cd nix
- cd ..
- cabal repl genstm
- :l Main
- db <- loadDatabases
At first run parsed XML files are serialized to cache files to save time with repeated loads of database
Generating device library
genstm tool can generate
with support for most of the STM32 devices.
To run it enter
nix directory in the repository root. Run
to obtain data files creating the database needed by
This shell has two environment variables set for your convenience -
DB_PATH with vendor files
TEMPLATES_PATH pointing to templates used during generation.
cd nix nix-shell
Then you can cd back to the repo root directory and run the actual generator
cd .. cabal run genstm
Generated library is now available in
and you can build it by entering
data and another
cd data nix-shell
Depending on [default.nix](data/default.nix) this will either build an environment
ivory-tower-helloworld (default) or an environment where you can
cabal to build the generated library. This is useful for running
cabal new-repl and reloading code instead of recompiling everything with Nix.
# in nix-shell from previous step git clone https://github.com/distrap/ivory-tower-helloworld cd ivory-tower-helloworld # checkout data-stm32 branch XXX: this is only temporary git checkout data-stm32 # adjust test/SimpleBlinkTest.hs make simpleblink-test # load and run make simpleblink-test-run
data/nix/ directory contains overlays for building whole Ivory Tower stack
in compatible and reproducible manner. Files can be adjusted to build from local git checkout
see for example [ivory-tower-drivers.nix](data/nix/ivory-tower-drivers.nix) - swapping
srcX will build from
local directory instead of git checkout.
Final overlay is then constructed in [default.nix](data/default.nix) which also contains target to build.
First we extract data from
$DB_PATH/db/mcu/families.xml and corresponding
$DB_PATH/db/mcu/*, this gives us CubeMX database (cmx) according
We load all the SVD files found in
Then we match each device with its SVD file according to its name.
Updating SVD files
app/gensvds is a simple SVD downloader / unpacker. To obtain
recent SVD files from vendor run
cabal new-run gensvds
To update the
mv svds new_svds git checkout svds mv new_svds/stm/*.svd svds/stm/ git diff git commit ... git push ... git show # note the new revision
Don't forget to update
nix/svd-database.nix, to obtain
sha256 hash use
nix-prefetch-git https://github.com/HaskellEmbedded/data-stm32 <NEW_REVISION_HASH>