Skip to content

Commit 9469cf4

Browse files
bors[bot]robamurichardeoin
authored
Merge #272
272: Example README update r=richardeoin a=robamu I think it makes more sense to give users instructions on how to build the example applications in their own binary crate. This is how some other HAL crates did it. This PR restructures the `README.md` file a bit and provides complete instructions on how to create a new binary crate and build the blinky example in it. Co-authored-by: Robin Mueller <robin.mueller.m@gmail.com> Co-authored-by: Richard Meadows <962920+richardeoin@users.noreply.github.com>
2 parents 2c16f46 + c2f9b29 commit 9469cf4

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

examples/README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ with the correct power configuration and power cycle the board.
2525

2626
## Logging
2727

28-
Example specific features have been defined to enable different logging outputs for the examples. If no logging feature is selected logging will be disabled and the panic handler will be halt. Supported logging methods are:
28+
Example specific features have been defined to enable different logging outputs for the examples.
29+
If no logging feature is selected logging will be disabled and the panic handler will be halt.
30+
Supported logging methods are:
2931

3032
### RTT (Real Time Trace)
3133

@@ -57,3 +59,56 @@ configure the ITM yourself. See [ITM.md](ITM.md)
5759
If you select this feature flag, then the call to `logger::init()` internally
5860
configures the ITM peripheral. If you also interact with the ITM peripheral
5961
yourself, you should be aware that it has already been configured.
62+
63+
64+
# Starting your own project
65+
66+
Although you can compile the provided examples directly, for your own project it
67+
is recommended to make a new binary crate or start one based on existing board
68+
specific examples / BSPs. Most examples will require tweaks to work for your
69+
particular board. You should copy the examples into your binary crate and make
70+
any necessary adjustments.
71+
72+
If you can find a suitable BSP, these usually also supply files which make
73+
development easier. They might also contain board specific code or adaptions
74+
required to make the examples work for your particular board.
75+
76+
The hello world of embedded development is usually to blink a LED. This example
77+
is contained within the [examples folder](https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/blinky.rs).
78+
79+
1. Make sure you have the required Rust cross-compiler installed. If you have not
80+
done this yet, you can run the following command to install it
81+
82+
```sh
83+
rustup target add thumbv7em-none-eabihf
84+
```
85+
86+
2. Create a new binary crate with `cargo init`
87+
3. To ensure that `cargo build` cross-compiles, it is recommended to create
88+
a `.cargo/config.toml` file. You can use the [`config.toml` provided
89+
in the cortex-m-quickstart](https://github.com/rust-embedded/cortex-m-quickstart/blob/master/.cargo/config.toml)
90+
repository and uncomment `target = "thumbv7em-none-eabihf"`.
91+
4. Copy `memory.x` into your project. This file contains information required by
92+
the linker.
93+
5. Copy `blinky.rs` to the `src/main.rs` in your binary crate and remove
94+
references to the `utilities` module.
95+
6. Add a dependency on the HAL in `Cargo.toml`. Make sure to replace
96+
the configuration feature `stm32h743v` to match the part you are using:
97+
98+
```toml
99+
[dependencies.stm32h7xx-hal]
100+
version = "^0"
101+
features = ["stm32h743v"]
102+
```
103+
104+
You should also add dependencies for the other crates you need, such as
105+
`cortex-m-rt` or `embedded-hal`.
106+
107+
7. Build the application with
108+
109+
```sh
110+
cargo build
111+
```
112+
113+
8. Flashing the MCU typically works differently for different boards. You can
114+
usually find instructions in the board specific crates or BSPs.

0 commit comments

Comments
 (0)