Skip to content

Commit 53ed7bf

Browse files
enautAfoHT
andauthored
fix included examples and markdown(book) (#912)
* fix included examples and markdown(book) fixes: #911 * fix footnote pre_init * more example link updates * Restore pool example name * Example: pool: Upgrade to heapless v0.8 * Example: pool: thumbv6 unsupported: wild cfg-if Experiment with multi-backend example contained in the example * Example: lm3s6965: Updated cargo.lock * Book: Use cargo xtask for by-example * Docs: Contributing: cargo xtask --------- Co-authored-by: Henrik Tjäder <[email protected]>
1 parent fa2a5b4 commit 53ed7bf

22 files changed

+431
-336
lines changed

CONTRIBUTING.md

+8-15
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,31 @@ Please make sure that tests passes locally before submitting.
3636
### Example check
3737

3838
```shell
39-
> cargo check --examples --target thumbv7m-none-eabi
39+
> cargo xtask example-check
4040
```
4141

42-
and/or
42+
### Run examples/tests on QEMU device
4343

4444
```shell
45-
> cargo check --examples --target thumbv6m-none-eabi
45+
> cargo xtask qemu
4646
```
4747

48-
### Run tests with xtask
48+
Will execute examples on your local `qemu` install.
4949

50-
```shell
51-
> cargo xtask --target all
52-
```
53-
54-
Will execute `run` tests on your local `qemu` install.
55-
(You may also pass a single target `--target thumbv6m-none-eabi/thumbv7m-none-eabi` during development).
56-
57-
#### Adding tests to xtask
50+
#### Adding examples/tests to xtask
5851

5952
If you have added further tests, you need to add the expected output in the `ci/expected` folder.
6053

6154
```shell
62-
> cargo run --example <NAME> --target thumbv7m-none-eabi > ci/expected/<NAME>.run
55+
> cargo xtask qemu --overwrite-expected
6356
```
6457

6558
### Internal tests
6659

6760
Run internal fail tests locally with:
6861

6962
```shell
70-
> cargo test --tests
63+
> cargo xtask test
7164
```
7265

7366
#### Adding tests to internal tests
@@ -76,7 +69,7 @@ If you have added fail tests or changed the expected behavior, the expected outp
7669
Inspect the error output, when sure that `ACTUAL OUTPUT` is correct you can re-run the test as:
7770

7871
```shell
79-
> TRYBUILD=overwrite cargo test --tests
72+
> TRYBUILD=overwrite cargo xtask test
8073
```
8174

8275
This will update the expected output to match the `ACTUAL OUTPUT`.

book/en/archive/by_example/monotonic.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ See the following example:
3939
```
4040

4141
``` console
42-
$ cargo run --target thumbv7m-none-eabi --example schedule
42+
$ cargo xtask qemu --verbose --example schedule
4343
{{#include ../../../../ci/expected/schedule.run}}
4444
```
4545

@@ -59,6 +59,6 @@ too late and that the task is already sent for execution. The following example
5959
```
6060

6161
``` console
62-
$ cargo run --target thumbv7m-none-eabi --example cancel-reschedule
62+
$ cargo xtask qemu --verbose --example cancel-reschedule
6363
{{#include ../../../../ci/expected/cancel-reschedule.run}}
6464
```

book/en/archive/by_example/tips/from_ram.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@ improve performance in some cases.
1111

1212
The example below shows how to place the higher priority task, `bar`, in RAM.
1313

14-
``` rust,noplayground
15-
{{#include ../../../../../rtic/examples/ramfunc.rs}}
14+
```rust,noplayground
15+
{{#include ../../../../../examples/lm3s6965/examples/ramfunc.rs}}
1616
```
1717

1818
Running this program produces the expected output.
1919

20-
``` console
21-
$ cargo run --target thumbv7m-none-eabi --example ramfunc
20+
```console
21+
$ cargo xtask qemu --verbose --example ramfunc
2222
```
2323

24-
``` console
25-
{{#include ../../../../../rtic/ci/expected/ramfunc.run}}
24+
```console
25+
{{#include ../../../../../ci/expected/lm3s6965/ramfunc.run}}
2626
```
2727

2828
One can look at the output of `cargo-nm` to confirm that `bar` ended in RAM
2929
(`0x2000_0000`), whereas `foo` ended in Flash (`0x0000_0000`).
3030

31-
``` console
31+
```console
3232
$ cargo nm --example ramfunc --release | grep ' foo::'
3333
```
3434

35-
``` console
36-
{{#include ../../../../../rtic/ci/expected/ramfunc.run.grep.foo}}
35+
```console
36+
{{#include ../../../../../ci/expected/lm3s6965/ramfunc.run.grep.foo}}
3737
```
3838

39-
``` console
39+
```console
4040
$ cargo nm --example ramfunc --target thumbv7m-none-eabi --release | grep '*bar::'
4141
```
4242

43-
``` console
44-
{{#include ../../../../../rtic/ci/expected/ramfunc.run.grep.bar}}
43+
```console
44+
{{#include ../../../../../ci/expected/lm3s6965/ramfunc.run.grep.bar}}
4545
```

book/en/src/by-example.md

+75-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
This part of the book introduces the RTIC framework to new users by walking them through examples of increasing complexity.
44

5-
All examples in this part of the book are accessible at the
6-
[GitHub repository][repoexamples].
5+
All examples in this part of the book are part of the
6+
[RTIC repository][repoexamples], found in the `examples` directory.
77
The examples are runnable on QEMU (emulating a Cortex M3 target),
88
thus no special hardware required to follow along.
99

@@ -17,24 +17,85 @@ embedded development environment that includes QEMU.
1717

1818
[the embedded Rust book]: https://rust-embedded.github.io/book/intro/install.html
1919

20-
To run the examples found in `examples/` locally, cargo needs a supported `target` and
21-
either `--examples` (run all examples) or `--example NAME` to run a specific example.
20+
To run the examples found in `examples/` locally using QEMU:
21+
22+
```
23+
cargo xtask qemu
24+
```
25+
26+
This runs all of the examples against the default `thumbv7m-none-eabi` device `lm3s6965`.
27+
28+
To limit which examples are being run, use the flag `--example <example name>`, the name being the filename of the example.
2229

2330
Assuming dependencies in place, running:
2431

25-
``` console
26-
$ cargo run --target thumbv7m-none-eabi --example locals
32+
```console
33+
$ cargo xtask qemu --example locals
2734
```
2835

2936
Yields this output:
3037

31-
``` console
32-
{{#include ../../../rtic/ci/expected/locals.run}}
38+
```console
39+
Finished dev [unoptimized + debuginfo] target(s) in 0.07s
40+
Running `target/debug/xtask qemu --example locals`
41+
INFO xtask > Testing for platform: Lm3s6965, backend: Thumbv7
42+
INFO xtask::run > 👟 Build example locals (thumbv7m-none-eabi, release, "test-critical-section,thumbv7-backend", in examples/lm3s6965)
43+
INFO xtask::run > ✅ Success.
44+
INFO xtask::run > 👟 Run example locals in QEMU (thumbv7m-none-eabi, release, "test-critical-section,thumbv7-backend", in examples/lm3s6965)
45+
INFO xtask::run > ✅ Success.
46+
INFO xtask::results > ✅ Success: Build example locals (thumbv7m-none-eabi, release, "test-critical-section,thumbv7-backend", in examples/lm3s6965)
47+
INFO xtask::results > ✅ Success: Run example locals in QEMU (thumbv7m-none-eabi, release, "test-critical-section,thumbv7-backend", in examples/lm3s6965)
48+
INFO xtask::results > 🚀🚀🚀 All tasks succeeded 🚀🚀🚀
49+
```
50+
51+
It is great that examples are passing and this is part of the RTIC CI setup too, but for the purposes of this book we must add the `--verbose` flag, or `-v` for short to see the actual program output:
52+
53+
```console
54+
cargo xtask qemu --verbose --example locals
55+
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
56+
Running `target/debug/xtask qemu --example locals --verbose`
57+
DEBUG xtask > Stderr of child processes is inherited: false
58+
DEBUG xtask > Partial features: false
59+
INFO xtask > Testing for platform: Lm3s6965, backend: Thumbv7
60+
INFO xtask::run > 👟 Build example locals (thumbv7m-none-eabi, release, "test-critical-section,thumbv7-backend", in examples/lm3s6965)
61+
INFO xtask::run > ✅ Success.
62+
INFO xtask::run > 👟 Run example locals in QEMU (thumbv7m-none-eabi, release, "test-critical-section,thumbv7-backend", in examples/lm3s6965)
63+
INFO xtask::run > ✅ Success.
64+
INFO xtask::results > ✅ Success: Build example locals (thumbv7m-none-eabi, release, "test-critical-section,thumbv7-backend", in examples/lm3s6965)
65+
cd examples/lm3s6965 && cargo build --target thumbv7m-none-eabi --features test-critical-section,thumbv7-backend --release --example locals
66+
DEBUG xtask::results >
67+
cd examples/lm3s6965 && cargo build --target thumbv7m-none-eabi --features test-critical-section,thumbv7-backend --release --example locals
68+
Stderr:
69+
Finished release [optimized] target(s) in 0.02s
70+
INFO xtask::results > ✅ Success: Run example locals in QEMU (thumbv7m-none-eabi, release, "test-critical-section,thumbv7-backend", in examples/lm3s6965)
71+
cd examples/lm3s6965 && cargo run --target thumbv7m-none-eabi --features test-critical-section,thumbv7-backend --release --example locals
72+
DEBUG xtask::results >
73+
cd examples/lm3s6965 && cargo run --target thumbv7m-none-eabi --features test-critical-section,thumbv7-backend --release --example locals
74+
Stdout:
75+
bar: local_to_bar = 1
76+
foo: local_to_foo = 1
77+
idle: local_to_idle = 1
78+
79+
Stderr:
80+
Finished release [optimized] target(s) in 0.02s
81+
Running `qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel target/thumbv7m-none-eabi/release/examples/locals`
82+
Timer with period zero, disabling
83+
84+
INFO xtask::results > 🚀🚀🚀 All tasks succeeded 🚀🚀🚀
85+
```
86+
87+
Look for the content following `Stdout:` towards the end ouf the output, the program output should have these lines:
88+
89+
```console
90+
{{#include ../../../ci/expected/lm3s6965/locals.run}}
3391
```
3492

35-
> **NOTE**: You can choose target device by passing a target
36-
> triple to cargo (e.g. `cargo run --example init --target thumbv7m-none-eabi`) or
37-
> configure a default target in `.cargo/config.toml`.
38-
>
39-
> For running the examples, we (typically) use a Cortex M3 emulated in QEMU, so the target is `thumbv7m-none-eabi`.
40-
> Since the M3 architecture is backwards compatible to the M0/M0+ architecture, you may also use the `thumbv6m-none-eabi`, in case you want to inspect generated assembly code for the M0/M0+ architecture.
93+
> **NOTE**:
94+
> For other useful options to `cargo xtask`, see:
95+
> ```
96+
> cargo xtask qemu --help
97+
> ```
98+
>
99+
> The `--platform` flag allows changing which device examples are run on,
100+
> currently `lm3s6965` is the best supported, work is ongoing to
101+
> increase support for other devices, including both ARM and RISC-V

book/en/src/by-example/app.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
All RTIC applications use the [`app`] attribute (`#[app(..)]`). This attribute only applies to a `mod`-item containing the RTIC application.
66

7-
The `app` attribute has a mandatory `device` argument that takes a *path* as a value. This must be a full path pointing to a *peripheral access crate* (PAC) generated using [`svd2rust`] **v0.14.x** or newer.
7+
The `app` attribute has a mandatory `device` argument that takes a _path_ as a value. This must be a full path pointing to a _peripheral access crate_ (PAC) generated using [`svd2rust`] **v0.14.x** or newer.
88

99
The `app` attribute will expand into a suitable entry point and thus replaces the use of the [`cortex_m_rt::entry`] attribute.
1010

@@ -14,13 +14,13 @@ The `app` attribute will expand into a suitable entry point and thus replaces th
1414

1515
## Structure and zero-cost concurrency
1616

17-
An RTIC `app` is an executable system model for single-core applications, declaring a set of `local` and `shared` resources operated on by a set of `init`, `idle`, *hardware* and *software* tasks.
17+
An RTIC `app` is an executable system model for single-core applications, declaring a set of `local` and `shared` resources operated on by a set of `init`, `idle`, _hardware_ and _software_ tasks.
1818

19-
* `init` runs before any other task, and returns the `local` and `shared` resources.
20-
* Tasks (both hardware and software) run preemptively based on their associated static priority.
21-
* Hardware tasks are bound to underlying hardware interrupts.
22-
* Software tasks are schedulied by an set of asynchronous executors, one for each software task priority.
23-
* `idle` has the lowest priority, and can be used for background work, and/or to put the system to sleep until it is woken by some event.
19+
- `init` runs before any other task, and returns the `local` and `shared` resources.
20+
- Tasks (both hardware and software) run preemptively based on their associated static priority.
21+
- Hardware tasks are bound to underlying hardware interrupts.
22+
- Software tasks are schedulied by an set of asynchronous executors, one for each software task priority.
23+
- `idle` has the lowest priority, and can be used for background work, and/or to put the system to sleep until it is woken by some event.
2424

2525
At compile time the task/resource model is analyzed under the Stack Resource Policy (SRP) and executable code generated with the following outstanding properties:
2626

@@ -41,6 +41,6 @@ Priorities in RTIC follow a higher value = more important scheme. For examples,
4141
To give a taste of RTIC, the following example contains commonly used features.
4242
In the following sections we will go through each feature in detail.
4343

44-
``` rust,noplayground
45-
{{#include ../../../../rtic/examples/common.rs}}
44+
```rust,noplayground
45+
{{#include ../../../../examples/lm3s6965/examples/common.rs}}
4646
```

book/en/src/by-example/app_idle.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# The background task `#[idle]`
22

3-
A function marked with the `idle` attribute can optionally appear in the module. This becomes the special *idle task* and must have signature `fn(idle::Context) -> !`.
3+
A function marked with the `idle` attribute can optionally appear in the module. This becomes the special _idle task_ and must have signature `fn(idle::Context) -> !`.
44

5-
When present, the runtime will execute the `idle` task after `init`. Unlike `init`, `idle` will run *with interrupts enabled* and must never return, as the `-> !` function signature indicates.
5+
When present, the runtime will execute the `idle` task after `init`. Unlike `init`, `idle` will run _with interrupts enabled_ and must never return, as the `-> !` function signature indicates.
66
[The Rust type `!` means “never”][nevertype].
77

88
[nevertype]: https://doc.rust-lang.org/core/primitive.never.html
@@ -11,25 +11,25 @@ Like in `init`, locally declared resources will have `'static` lifetimes that ar
1111

1212
The example below shows that `idle` runs after `init`.
1313

14-
``` rust,noplayground
15-
{{#include ../../../../rtic/examples/idle.rs}}
14+
```rust,noplayground
15+
{{#include ../../../../examples/lm3s6965/examples/idle.rs}}
1616
```
1717

18-
``` console
19-
$ cargo run --target thumbv7m-none-eabi --example idle
18+
```console
19+
$ cargo xtask qemu --verbose --example idle
2020
```
2121

22-
``` console
23-
{{#include ../../../../rtic/ci/expected/idle.run}}
22+
```console
23+
{{#include ../../../../ci/expected/lm3s6965/idle.run}}
2424
```
2525

2626
By default, the RTIC `idle` task does not try to optimize for any specific targets.
2727

2828
A common useful optimization is to enable the [SLEEPONEXIT] and allow the MCU to enter sleep when reaching `idle`.
2929

30-
>**Caution**: some hardware unless configured disables the debug unit during sleep mode.
30+
> **Caution**: some hardware unless configured disables the debug unit during sleep mode.
3131
>
32-
>Consult your hardware specific documentation as this is outside the scope of RTIC.
32+
> Consult your hardware specific documentation as this is outside the scope of RTIC.
3333
3434
The following example shows how to enable sleep by setting the
3535
[`SLEEPONEXIT`][SLEEPONEXIT] and providing a custom `idle` task replacing the default [`nop()`][NOP] with [`wfi()`][WFI].
@@ -38,16 +38,16 @@ The following example shows how to enable sleep by setting the
3838
[WFI]: https://developer.arm.com/documentation/dui0662/b/The-Cortex-M0--Instruction-Set/Miscellaneous-instructions/WFI
3939
[NOP]: https://developer.arm.com/documentation/dui0662/b/The-Cortex-M0--Instruction-Set/Miscellaneous-instructions/NOP
4040

41-
``` rust,noplayground
42-
{{#include ../../../../rtic/examples/idle-wfi.rs}}
41+
```rust,noplayground
42+
{{#include ../../../../examples/lm3s6965/examples/idle-wfi.rs}}
4343
```
4444

45-
``` console
46-
$ cargo run --target thumbv7m-none-eabi --example idle-wfi
45+
```console
46+
$ cargo xtask qemu --verbose --example idle-wfi
4747
```
4848

49-
``` console
50-
{{#include ../../../../rtic/ci/expected/idle-wfi.run}}
49+
```console
50+
{{#include ../../../../ci/expected/lm3s6965/idle-wfi.run}}
5151
```
5252

53-
> **Notice**: The `idle` task cannot be used together with *software* tasks running at priority zero. The reason is that `idle` is running as a non-returning Rust function at priority zero. Thus there would be no way for an executor at priority zero to give control to *software* tasks at the same priority.
53+
> **Notice**: The `idle` task cannot be used together with _software_ tasks running at priority zero. The reason is that `idle` is running as a non-returning Rust function at priority zero. Thus there would be no way for an executor at priority zero to give control to _software_ tasks at the same priority.

book/en/src/by-example/app_init.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@
33
An RTIC application requires an `init` task setting up the system. The corresponding `init` function must have the
44
signature `fn(init::Context) -> (Shared, Local)`, where `Shared` and `Local` are resource structures defined by the user.
55

6-
The `init` task executes after system reset, [after an optionally defined `pre-init` code section][pre-init] and an always occurring internal RTIC initialization.
7-
[pre-init]: https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.pre_init.html
6+
The `init` task executes after system reset, [after an optionally defined `pre-init` code section][^pre-init] and an always occurring internal RTIC initialization.
87

9-
The `init` and optional `pre-init` tasks runs *with interrupts disabled* and have exclusive access to Cortex-M (the `bare_metal::CriticalSection` token is available as `cs`).
8+
The `init` and optional `pre-init` tasks runs _with interrupts disabled_ and have exclusive access to Cortex-M (the `bare_metal::CriticalSection` token is available as `cs`).
109

1110
Device specific peripherals are available through the `core` and `device` fields of `init::Context`.
1211

12+
[^pre-init]: [https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.pre_init.html](https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.pre_init.html)
13+
1314
## Example
1415

1516
The example below shows the types of the `core`, `device` and `cs` fields, and showcases the use of a `local` variable with `'static` lifetime. Such variables can be delegated from the `init` task to other tasks of the RTIC application.
1617

1718
The `device` field is only available when the `peripherals` argument is set to the default value `true`.
1819
In the rare case you want to implement an ultra-slim application you can explicitly set `peripherals` to `false`.
1920

20-
``` rust,noplayground
21-
{{#include ../../../../rtic/examples/init.rs}}
21+
```rust,noplayground
22+
{{#include ../../../../examples/lm3s6965/examples/init.rs}}
2223
```
2324

2425
Running the example will print `init` to the console and then exit the QEMU process.
2526

26-
``` console
27-
$ cargo run --target thumbv7m-none-eabi --example init
27+
```console
28+
$ cargo xtask qemu --verbose --example init
2829
```
2930

30-
``` console
31-
{{#include ../../../../rtic/ci/expected/init.run}}
31+
```console
32+
{{#include ../../../../ci/expected/lm3s6965/init.run}}
3233
```

0 commit comments

Comments
 (0)