Skip to content

Commit 127d876

Browse files
committed
Add codegen README
1 parent 4686000 commit 127d876

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

codegen/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Codegen
2+
3+
This crate provides code-generation for the stm32f3xx-hal. It reads information
4+
from an [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html)
5+
database and uses that to output code that can directly be included into the
6+
source code of the stm32f3xx-hal crate.
7+
8+
For more information on how the STM32CubeMX database is structured, check out
9+
the README in the [cube-parse](https://github.com/dbrgn/cube-parse) repository.
10+
11+
Because by default cargo tries to use the `thumbv7em-none-eabihf` target, due
12+
to what's specified in the `.cargo/config`, you need to manually specify your
13+
host's target when building `codegen`, e.g.:
14+
15+
```
16+
$ cargo run --target x86_64-unknown-linux-gnu -- help
17+
```
18+
19+
`codgen` can generate the following code:
20+
21+
- GPIO mappings
22+
23+
## GPIO mappings
24+
25+
Running `codegen`'s `gpio` subcommand generates the `gpio!` macro
26+
invocations at the end of `src/gpio.rs`. Re-generating those macro-invocations
27+
is simply a matter of deleting the old ones and then executing:
28+
29+
```
30+
$ cargo run --target $host_target -- gpio $cubemx_db_path >> ../src/gpio.rs
31+
```
32+
33+
`$cubemx_db_path` must be the path to the `db/mcu` directory under an
34+
STM32CubeMX installation. With a default Linux install, this would be
35+
`/opt/stm32cubemx/db/mcu`.
36+
37+
The generated `gpio!` invocations are gated by features whose names are derived
38+
from the respective GPIO internal peripheral (IP) version:
39+
40+
- gpio-f302
41+
- gpio-f303
42+
- gpio-f303e
43+
- gpio-f333
44+
- gpio-f373
45+
46+
Note that the GPIO IP version names don't necessarily match the MCUs they are
47+
used in. For example, the GPIOs in `STM32F302xB` MCUs have the IP version
48+
"STM32F303_gpio_v1_0". The MCU features of the `stm32f3xx-hal` also select the
49+
correct `gpio-*` features, so users generally don't have to care about these
50+
details.

0 commit comments

Comments
 (0)