You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+90-34Lines changed: 90 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,8 @@
1
1
# stm32-data
2
2
3
-
`stm32-data` is a project aiming to produce clean machine-readable data about the STM32 microcontroller
4
-
families, including:
3
+
`stm32-data` is a project that generates clean, machine-readable data for the STM32 microcontroller families. It also provides a tool to generate a Rust Peripheral Access Crate (`stm32-metapac`) for these devices.
4
+
5
+
The generated data includes:
5
6
6
7
-:heavy_check_mark: Base chip information
7
8
- RAM, flash
@@ -17,15 +18,56 @@ families, including:
17
18
18
19
:heavy_check_mark: = done, :construction: = work in progress, :x: = to do
19
20
21
+
## Generated JSON data
22
+
20
23
The generated JSON files are available [here in the `stm32-data-generated`](https://github.com/embassy-rs/stm32-data-generated/blob/main/data) repo.
21
24
22
-
## stm32-metapac
25
+
## Generated PAC crate
23
26
24
27
If you're looking for the API docs for `stm32-metapac` customized to a
25
28
particular chip, they are available here: https://docs.embassy.dev/stm32-metapac
26
29
27
30
The generated PAC is available [here in the `stm32-data-generated`](https://github.com/embassy-rs/stm32-data-generated/blob/main/stm32-metapac) repo.
28
31
32
+
## Quick guide
33
+
34
+
### How to generate everything
35
+
36
+
- Run `./d download-all`
37
+
38
+
> This will download all the required data sources into `sources/`.
39
+
40
+
- Run `./d gen-all`
41
+
42
+
> This (re)generates all the intermediate JSON's to `build/data/` and the `stm32-metapac` crate into `build/stm32-metapac/`.
43
+
44
+
The generated PAC crate can be included as a local dependency for testing or development:
The JSON files in `build/data/` are generated as follows:
54
+
55
+
- Run `cargo run --release --bin stm32-data-gen`
56
+
57
+
> This generates all the intermediate JSON's in `build/data/`.
58
+
>
59
+
> Assignments of registers to peripherals are done in a [perimap](#peripheral-mapping-perimap) and fixes to registers can be done in the files located in `data/registers`.
60
+
61
+
### How to generate only the `stm32-metapac` crate
62
+
63
+
When the JSON data was generated as described above, it can be used to generate the PAC:
64
+
65
+
- Run `cargo run --release --bin stm32-metapac-gen`
66
+
67
+
> This generates the `stm32-metapac` crate into `build/stm32-metapac/`.
68
+
69
+
## In-depth topics
70
+
29
71
## Data sources
30
72
31
73
These are the data sources currently used.
@@ -53,23 +95,44 @@ We don't maintain "patches" for registers unlike the `stm32-rs` project. This ha
53
95
- Fixing mistakes and typos in the SVDs is now much easier (and yes, there are A LOT of those). It doesn't require a complicated patching system, you just edit the YAML to fix the mistake instead of writing a patch that will fix it when applied.
54
96
- Ensuring consistency for the same peripherals between chips. (i.e. we check in a single `i2c_v2.yaml` and ensure it is good, vs trying to patch wildly differing SVDs for what's an identical IP block into being consistent). The `stm32-rs` project doesn't have this as a goal, while we do. Writing a single HAL for all stm32 chips (such as [the `embassy-stm32` HAL](https://github.com/embassy-rs/embassy/tree/main/embassy-stm32)) is impossible otherwise.
55
97
56
-
## Generate the `stm32-metapac` crate
57
-
58
-
- Run `./d download-all`
59
-
60
-
> This will download all the required data sources into `sources/`.
61
-
62
-
- Run `cargo run --release --bin stm32-data-gen`
63
-
64
-
> This generates all the intermediate JSON's in `build/data/`.
65
-
>
66
-
> > Assignments of registers to peripherals is done in a [perimap](#peripheral-mapping-perimap) and fixes to registers can be done in the files located in `data/registers`.
67
-
68
-
- Run `cargo run --release --bin stm32-metapac-gen`
69
-
70
-
> This generates the `stm32-metapac` crate into `build/stm32-metapac/`.
71
-
72
-
## Adding support for a new peripheral
98
+
### Toolchain pipeline
99
+
100
+
This project is built in three stages:
101
+
102
+
1.**Source Acquisition**
103
+
-`./d download-all` fetches STM32CubeDB XMLs, CubeProg data, mcufinder JSONs, and HAL headers into `sources/`.
104
+
105
+
2.**JSON Generation**
106
+
-`stm32-data-gen` generates the JSON files from consolidated YAML and source data:
107
+
1. Parse YAML files to build an in-memory IR for registers (`src/registers.rs`).
108
+
-`data/extra/family/*.yaml`: STM32 family metadata (package options, flash/RAM sizes, low-level identifiers).
109
+
-`data/header_map.yaml`: MCU slug to HAL C-header filename mapping for base addresses & IRQ extraction.
`chiptool` provides IR definitions and code-generation templates for PAC generation.
134
+
135
+
### Adding support for a new peripheral
73
136
74
137
This will help you add support for a new peripheral to all STM32 families. (Please take the time to add it for all families, even if you personally
75
138
are only interested in one. It's easier than it looks, and doing all families at once is significantly less work than adding one now then having to revisit everything later when adding more. It also helps massively in catching mistakes and inconsistencies in the source SVDs.)
@@ -88,17 +151,17 @@ are only interested in one. It's easier than it looks, and doing all families at
88
151
- Minimize the diff between each pair of versions. For example between `lpuart_v1.yaml` and `lpuart_v2.yaml`. If one is missing enums or descriptions, copy it from another.
89
152
- Make sure the block
90
153
- Add entries to [`perimap`](https://github.com/embassy-rs/stm32-data/blob/main/stm32-data-gen/src/perimap.rs), see below.
91
-
- Regen, then:
154
+
- Regen, then:
92
155
- Check `data/chips/*.yaml` has the right `block: lpuart_vX/LPUART` fields.
93
156
- Ensure a successful build of the affected pac. e.g.
Please separate manual changes and changes resulting from regen in separate commits. It helps tremendously with review and rebasing/merging.
100
163
101
-
## Register cleanup
164
+
### Register cleanup
102
165
103
166
SVDs have some widespread annoyances that should be fixed when adding register YAMLs to this repo. Check out `chiptool` transforms, they can help in speeding up the cleanups.
104
167
@@ -111,7 +174,7 @@ SVDs have some widespread annoyances that should be fixed when adding register Y
111
174
- Check out the `MakeRegisterArray`, `MakeFieldArray` chiptool transforms.
112
175
- Use `chiptool fmt` on each of the register yamls.
113
176
114
-
## Adding support for a new family (RCC)
177
+
### Adding support for a new family (RCC)
115
178
116
179
NOTE: At the time of writing all families are supported, so this is only useful in particular situations, for example if you want to regenerate an RCC register yaml from scratch.
117
180
@@ -145,16 +208,9 @@ place:
145
208
mv regs_merged.yaml data/registers/rcc_g0.yaml
146
209
```
147
210
148
-
To assign these newly generated registers to peripherals, utilize the mapping done in `parse.py`.
149
-
An example mapping can be seen in the following snippet
150
-
151
-
```
152
-
('STM32G0.*:RCC:.*', 'rcc_g0/RCC'),
153
-
```
154
-
155
-
such mapping assigns the `rcc_g0/RCC` register block to the `RCC` peripheral in every device from the `STM32G0` family.
211
+
To assign these newly generated registers to peripherals, utilize the mapping done in `stm32-data-gen/src/perimap.rs`.
156
212
157
-
## Peripheral mapping (perimap)
213
+
### Peripheral mapping (perimap)
158
214
159
215
The `stm32-data-gen` binary has a map to match peripherals to the right version in all chips, the [perimap](https://github.com/embassy-rs/stm32-data/blob/main/stm32-data-gen/src/perimap.rs).
0 commit comments