Skip to content

Commit 09576f3

Browse files
committed
Add contributing.md
This should hopefully clear up some confusion upfront for first-time contributors and also lays down a kind of "roadmap" how this crate should go forward.
1 parent 2fc0ecf commit 09576f3

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
<!--
9+
If you are adding a CHANGELOG entry with a link to the PR e.g. ([#123])
10+
do not forget to add the corresponding URL at the end of the file:
11+
12+
[#123]: https://github.com/stm32-rs/stm32f3xx-hal/pull/123
13+
-->
14+
815
## Unreleased
916

1017
### Added
@@ -15,7 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1522

1623
### Changed
1724

18-
- `PXx` struct (representing a generic GPIO pin) implements `Send` and `Sync` [#251]
25+
- `PXx` struct (representing a generic GPIO pin) implements `Send` and `Sync` ([#251])
1926
- Each pin aliases (`PA0`, `PA1`, ..) are defined under `gpio` module directly.
2027
Re-export from gpio port sub-modules are provided for compatibility. [#257]
2128

@@ -356,6 +363,7 @@ let clocks = rcc
356363
[#257]: https://github.com/stm32-rs/stm32f3xx-hal/pull/257
357364
[#255]: https://github.com/stm32-rs/stm32f3xx-hal/pull/255
358365
[#252]: https://github.com/stm32-rs/stm32f3xx-hal/pull/252
366+
[#251]: https://github.com/stm32-rs/stm32f3xx-hal/pull/251
359367
[#247]: https://github.com/stm32-rs/stm32f3xx-hal/pull/247
360368
[#246]: https://github.com/stm32-rs/stm32f3xx-hal/pull/246
361369
[#239]: https://github.com/stm32-rs/stm32f3xx-hal/pull/239

CONTRIBUTING.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# CONTRIBUTING.md
2+
3+
This document explains some concepts used for this repository and answers some
4+
questions for contributors.
5+
6+
## Abstracting a new peripheral
7+
8+
- Useful documentations are
9+
- STM datasheets - a list of these can be found in the
10+
[`stm32f3`][device-support] README.
11+
- Documentation of [`stm32f3`](https://docs.rs/stm32f3/latest/stm32f3/)
12+
itself.
13+
- The HTML table overview of
14+
[all documented registers](https://stm32-rs.github.io/stm32-rs/).
15+
- While designing, take inspiration of existing abstraction. For example from
16+
the existing `stm32` abstractions ([`stm32f1xx`], [`stm32f4xx`],
17+
[`stm32f7xx`], ...) or the [`nrf-hal`]
18+
- Incomplete abstraction of peripherals are OK!
19+
- Reading through the documentation can be daunting.
20+
- Rather concentrate on a few features you want to support.
21+
- Think about extensibility.
22+
- If you know your implementation is incomplete, leave it in a state,
23+
where it is easy to at least add the most common features afterwards
24+
without having to introduce [Breaking Changes](#breaking-changes).
25+
For example use [`#[non_exhaustive]`][non-exhaustive] where it does make
26+
sense.
27+
28+
[device-support]: https://github.com/stm32-rs/stm32-rs-nightlies/tree/master/stm32f3#supported-devices
29+
[non-exhaustive]: https://rust-lang.github.io/rfcs/2008-non-exhaustive.html
30+
[`stm32f1xx`]: https://github.com/stm32-rs/stm32f1xx-hal
31+
[`stm32f4xx`]: https://github.com/stm32-rs/stm32f4xx-hal
32+
[`stm32f7xx`]: https://github.com/stm32-rs/stm32f7xx-hal
33+
[`nrf-hal`]: https://github.com/nrf-rs/nrf-hal
34+
35+
## Breaking Changes
36+
37+
- Breaking changes are defined [here][breaking]
38+
- Do **not fear** to introduce a breaking change!
39+
- This crate is a long way of being stable API wise (v1.0.0) and the best
40+
practices in the embedded ecosystem are still evolving.
41+
Also, introducing new useful compiler features like [`const-generics`] means
42+
that there is no other way, then introducing them with a breaking change.
43+
(_[`min_const_generics`] are already usable_)
44+
45+
[breaking]: https://doc.rust-lang.org/cargo/reference/semver.html
46+
[`const-generics`]: https://rust-lang.github.io/rfcs/2000-const-generics.html
47+
[`min_const_generics`]: https://blog.rust-lang.org/2021/02/26/const-generics-mvp-beta.html
48+
49+
## Test your changes
50+
51+
If possible, test if your changes still work with the testsuite (see
52+
[here](testsuite/README.md)).
53+
54+
This for now requires a stm32f3-discovery board, which you might not have.
55+
[Adjustments](testsuite/README.md#using-a-different-board) can be made to be
56+
able to run it on your board.
57+
58+
If you are not sure and / or want to test your changes on the full testsuite
59+
either way, ask a contributor who should have a board available to test your
60+
changes on. (In the future, there might also be a job running, which automatically
61+
tests your changes on a physical board. 🚀)
62+
63+
## CHANGELOG entry
64+
65+
For any **user** visible change, please a note, what changed in the [CHANGELOG](CHANGELOG.md)
66+
67+
For easier traceability, a link to the corresponding PR implementing that
68+
change is appended, e.g.
69+
70+
```markdown
71+
### CHANGED
72+
73+
- Output pins have gained the `random()` method, which randomly chooses
74+
the output state. ([#123]) <!-- LINK to the PR -->
75+
76+
<!-- ... almost at the end of the file -->
77+
<!-- This is needed to make the link actually work! -->
78+
[#123]: https://github.com/stm32-rs/stm32f3xx-hal/pull/123
79+
```
80+
81+
## MSVR Job is failing
82+
83+
If the MSRV ("minimal supported rust version") CI job fails, feel free to update
84+
it. Places are:
85+
86+
- in the [ci.yml](.github/workflows/ci.yml)
87+
- in the [README](README.md)
88+
89+
## API Design
90+
91+
Some design patterns to take into consideration, while introducing crafting
92+
APIs.
93+
94+
_This part is written without much research and out of the position
95+
of the current experience of the author / maintainer, so take it with a grain of
96+
salt 🧂_
97+
98+
### Embedded Rust designing patterns
99+
100+
There are some designing patterns written down in "[The Embedded Rust Book]".
101+
This crate does not follow them for 100%, but the aim is to do so!
102+
103+
[The Embedded Rust Book]: https://docs.rust-embedded.org/book/design-patterns/hal/checklist.html
104+
105+
### Principle of least surprise
106+
107+
If adding a new feature does mean designing a new API try to follow the
108+
["Principle of least surprise"][POLS]. The type system should guide the user
109+
towards the right usage of the API and if that is not possible, try to document
110+
common pitfalls and surprising behavior.
111+
112+
[POLS]: https://en.wikipedia.org/wiki/Principle_of_least_astonishment
113+
114+
### Misc
115+
116+
- Add `#[derive(Debug)]` and `#[cfg_attr(feature = "defmt",
117+
derive(defmt::Format))]` to new `struct`s and `enum`s where possible. And add
118+
`#[derive(Copy, Clone)]` for `enum`s and small `struct`s, which is not bound
119+
to a resource (like a peripheral) where leveraging the move semantics does not
120+
make sense.
121+
122+
### Parametrization before nameability
123+
124+
E.g. don't introduce a bool for every Enum variant `fn is_enum_variant_1()`, `fn
125+
is_enum_variant_2()`, `...`, rather use `fn is_enum_variant(enum: Enum)` if
126+
possible.

testsuite/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,25 @@ cargo test -p testsuite
2323

2424
This will execute all tests sequentially on the target device.
2525

26+
The result _always_ shows a backtrace, even in the case of success.
27+
Exit code of 0 means that the run was successful.
28+
29+
### Using a different board
30+
2631
To run the tests on a different target than the STM32F3Discovery's
2732
`stm32f303xc`, specify a target as a feature:
2833

2934
```bash
3035
cargo test -p testsuite --no-default-features --features stm32f3xx-hal/stm32f301xb
3136
```
3237

33-
The result _always_ shows a backtrace, even in the case of success.
34-
Exit code of 0 means that the run was successful.
38+
If the wiring is different for your board, adjust the type definitions in
39+
`src/lib.rs`.
40+
41+
### Running a single test
42+
43+
Single test of the testsuite can be run, with the `cargo-test` familiar syntax.
44+
45+
```bash
46+
cargo test -p testsuite --test uart
47+
```

0 commit comments

Comments
 (0)