Skip to content

Commit 263dcfb

Browse files
bors[bot]japaric
andcommitted
Merge #114
114: 2018 edition r=therealprof a=japaric This PR: - moves the code to the 2018 edition and to cortex-m-rt v0.6.x - simplifies setting up correct permissions (i.e. udev rules) for the st-link and the serial adapter closes #102 r? @rust-embedded/resources (anyone) Co-authored-by: Jorge Aparicio <[email protected]>
2 parents d40b491 + 1e9b885 commit 263dcfb

File tree

103 files changed

+729
-1514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+729
-1514
lines changed

ci/script.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ main() {
1515
pushd $chapter
1616
case $(basename $chapter) in
1717
05-led-roulette | 06-hello-world)
18-
cargo check --target thumbv7em-none-eabihf
18+
RUSTFLAGS="-D rust_2018_compatibility -D rust_2018_idioms" cargo check --target thumbv7em-none-eabihf
1919
;;
2020
WIP-async-io-the-future)
2121
popd
2222
continue
2323
;;
2424
*)
25-
cargo check
25+
RUSTFLAGS="-D rust_2018_compatibility -D rust_2018_idioms" cargo check
2626
;;
2727
esac
2828
popd

src/02-requirements/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Hardware/knowledge requirements
22

3-
The only knowledge requirement to read this book is to know *some* Rust. It's hard for me to
4-
quantify *some* but at least I can tell you that you don't need to fully grok generics but you do
5-
need to know how to *use* closures.
3+
The only knowledge requirement to read this book is to know *some* Rust. It's
4+
hard for me to quantify *some* but at least I can tell you that you don't need
5+
to fully grok generics but you do need to know how to *use* closures. You also
6+
need to be familiar with the idioms of the [2018 edition], in particular with
7+
the fact that `extern crate` is not necessary in the 2018 edition.
8+
9+
[2018 edition]: https://rust-lang-nursery.github.io/edition-guide/
610

711
Also, to follow this material you'll need the following hardware:
812

src/03-setup/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ several MBs in size.
3030
We'll use all the tools listed below. Where a minimum version is not specified, any recent version
3131
should work but we have listed the version we have tested.
3232

33-
- Cargo & `rustc` >= nightly-2018-08-02
33+
- Rust 1.30, 1.30-beta, nightly-2018-09-13, or a newer toolchain.
3434

3535
- [`itmdump`] v0.2.1
3636

@@ -39,7 +39,7 @@ should work but we have listed the version we have tested.
3939
- `arm-none-eabi-gdb`. Version 7.12 or newer highly recommended. Tested versions: 7.10, 7.11,
4040
7.12 and 8.1
4141

42-
- [`cargo-binutils`]. Version 0.1.2 or newer.
42+
- [`cargo-binutils`]. Version 0.1.4 or newer.
4343

4444
[`cargo-binutils`]: https://github.com/japaric/cargo-binutils
4545

@@ -73,12 +73,12 @@ Then, install or switch to the nightly channel.
7373
$ rustup default nightly
7474
```
7575

76-
**NOTE** Make sure you have a nightly newer than `nightly-2018-08-02`. `rustc -V` should return a
76+
**NOTE** Make sure you have a nightly newer than `nightly-2018-09-13`. `rustc -V` should return a
7777
date newer than the one shown below:
7878

7979
``` console
8080
$ rustc -V
81-
rustc 1.29.0-nightly (97085f9fb 2018-08-01)
81+
rustc 1.30.0-nightly (f2302daef 2018-09-12)
8282
```
8383

8484
### `itmdump`
@@ -95,11 +95,11 @@ itmdump 0.3.1
9595
``` console
9696
$ rustup component add llvm-tools-preview
9797

98-
$ cargo install cargo-binutils --vers 0.1.2
98+
$ cargo install cargo-binutils --vers 0.1.4
9999

100-
$ cargo size -- --version
100+
$ cargo size -- -version
101101
LLVM (http://llvm.org/):
102-
LLVM version 7.0.0svn
102+
LLVM version 8.0.0svn
103103
Optimized build.
104104
Default target: x86_64-unknown-linux-gnu
105105
Host CPU: skylake

src/03-setup/linux.md

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ $ cat /etc/udev/rules.d/99-ftdi.rules
9090

9191
``` text
9292
# FT232 - USB <-> Serial Converter
93-
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", GROUP="uucp"
93+
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE:="0666"
9494
```
9595

9696
``` console
@@ -99,10 +99,10 @@ $ cat /etc/udev/rules.d/99-openocd.rules
9999

100100
``` text
101101
# STM32F3DISCOVERY rev A/B - ST-LINK/V2
102-
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3748", GROUP="uucp"
102+
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3748", MODE:="0666"
103103
104104
# STM32F3DISCOVERY rev C+ - ST-LINK/V2-1
105-
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", GROUP="uucp"
105+
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", MODE:="0666"
106106
```
107107

108108
Then reload the udev rules with:
@@ -113,47 +113,6 @@ $ sudo udevadm control --reload-rules
113113

114114
If you had any board plugged to your laptop, unplug them and then plug them in again.
115115

116-
Finally, check if you are in the `uucp` group.
117-
118-
``` console
119-
$ groups $(id -nu)
120-
(..) uucp (..)
121-
$ # ^^^^
122-
```
123-
124-
(`$(id -nu)` returns your user name. In my case it's `japaric`.)
125-
126-
If `uucp` appears in the output. You are all set! Go to the [next section]. Otherwise, keep reading:
116+
Now, go to the [next section].
127117

128118
[next section]: /03-setup/verify.html
129-
130-
- Add yourself to the `uucp` group.
131-
132-
``` console
133-
$ sudo usermod -a -G uucp $(id -u -n)
134-
```
135-
136-
- Check again the output of `groups`. `uucp` should be there this time!
137-
138-
``` console
139-
$ groups $(id -nu)
140-
(..) uucp (..)
141-
$ # ^^^^
142-
```
143-
144-
You'll have to re-log for these changes to take effect. You have two options:
145-
146-
You can reboot or log out from your current session and then log in; this will close all the
147-
programs you have open right now.
148-
149-
The other option is to use the command below:
150-
151-
``` console
152-
$ su - $(id -nu)
153-
```
154-
155-
to re-log *only in the current shell* and get access to `uucp` devices *only on that shell*. Other
156-
shells *won't* have access to `uucp` devices unless you manually re-log on them with the same `su`
157-
command.
158-
159-
Now, go to the [next section].

src/03-setup/verify.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ file `/dev/bus/usb/003/004` *is* the F3. Let's check its permissions:
2323

2424
``` console
2525
$ ls -l /dev/bus/usb/003/004
26-
crw-rw-r-- 1 root uucp 189, 262 Oct 27 00:00 /dev/bus/usb/003/004
26+
crw-rw-rw- 1 root root 189, 20 Sep 13 00:00 /dev/bus/usb/003/004
2727
```
2828

29-
The group should be `uucp`. If it's not ... then check your [udev rules] and try re-loading them
30-
with:
29+
The permissions should be `crw-rw-rw-`. If it's not ... then check your [udev
30+
rules] and try re-loading them with:
3131

3232
[udev rules]: /03-setup/linux.html#udev%20rules
3333

@@ -48,10 +48,10 @@ In my case, it's the `/dev/bus/usb/003/005`. Now, check its permissions:
4848

4949
``` console
5050
$ ls -l /dev/bus/usb/003/005
51-
crw-rw-r--+ 1 root uucp 189, 261 Oct 27 00:00 /dev/bus/usb/003/005
51+
crw-rw-r-- 1 root root 189, 21 Sep 13 00:00 /dev/bus/usb/003/005
5252
```
5353

54-
As before, the group should be `uucp`.
54+
As before, the permissions should be `crw-rw-r--`.
5555

5656
## All
5757

src/05-led-roulette/.cargo/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[target.thumbv7em-none-eabihf]
2-
runner = "arm-none-eabi-gdb"
2+
runner = "arm-none-eabi-gdb -q"
33
rustflags = [
44
"-C", "linker=rust-lld",
55
"-C", "link-arg=-Tlink.x",

src/05-led-roulette/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
authors = ["Jorge Aparicio <[email protected]>"]
3+
edition = "2018"
34
name = "led-roulette"
45
version = "0.1.0"
56

67
[dependencies]
78
aux5 = { path = "auxiliary" }
8-
cortex-m-rt = "0.5.3"

src/05-led-roulette/README.md

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,7 @@ projects.
2222
Now, jump into the `src/05-led-roulette` directory. Check the `src/main.rs` file:
2323

2424
``` rust
25-
#![deny(unsafe_code)]
26-
#![no_main]
27-
#![no_std]
28-
29-
extern crate aux5;
30-
#[macro_use]
31-
extern crate cortex_m_rt;
32-
33-
entry!(main);
34-
35-
fn main() -> ! {
36-
let _y;
37-
let x = 42;
38-
_y = x;
39-
40-
// infinite loop; just so we don't leave this stack frame
41-
loop {}
42-
}
25+
{{#include src/main.rs}}
4326
```
4427

4528
Microcontroller programs are different from standard programs in two aspects: `#![no_std]` and
@@ -51,7 +34,7 @@ systems (i.e., systems without OS abstractions like files and sockets).
5134

5235
The `no_main` attribute says that this program won't use the standard `main` interface, which is
5336
tailored for command line applications that receive arguments. Instead of the standard `main` we'll
54-
use the `entry!` macro from the [`cortex-m-rt`] crate to define a custom entry point. In this
37+
use the `entry` attribute from the [`cortex-m-rt`] crate to define a custom entry point. In this
5538
program we have named the entry point "main", but any other name could have been used. The entry
5639
point function must have signature `fn() -> !`; this type indicates that the function can't return
5740
-- this means that the program never terminates.

src/05-led-roulette/auxiliary/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[package]
22
authors = ["Jorge Aparicio <[email protected]>"]
3+
edition = "2018"
34
name = "aux5"
45
version = "0.1.0"
56

67
[dependencies]
78
cortex-m = "0.5.6"
8-
panic-abort = "0.2.0"
9-
cortex-m-rt = "0.5.3"
9+
panic-halt = "0.2.0"
10+
cortex-m-rt = "0.6.3"
1011

1112
[dependencies.f3]
1213
features = ["rt"]

src/05-led-roulette/auxiliary/src/lib.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@
22
33
#![no_std]
44

5-
extern crate cortex_m;
6-
#[macro_use]
7-
extern crate cortex_m_rt;
8-
extern crate f3;
9-
extern crate panic_abort;
10-
11-
use core::sync::atomic::{self, Ordering};
12-
13-
use cortex_m::asm;
14-
use cortex_m_rt::ExceptionFrame;
15-
pub use f3::hal::delay::Delay;
16-
pub use f3::hal::prelude;
17-
use f3::hal::prelude::*;
18-
use f3::hal::stm32f30x;
19-
pub use f3::led::Leds;
5+
#[allow(unused_extern_crates)] // NOTE(allow) bug rust-lang/rust#53964
6+
extern crate panic_halt; // panic handler
7+
8+
pub use cortex_m_rt::entry;
9+
pub use f3::{
10+
hal::{delay::Delay, prelude},
11+
led::Leds,
12+
};
13+
14+
use f3::hal::{prelude::*, stm32f30x};
2015

2116
pub fn init() -> (Delay, Leds) {
2217
let cp = cortex_m::Peripherals::take().unwrap();
@@ -33,23 +28,3 @@ pub fn init() -> (Delay, Leds) {
3328

3429
(delay, leds)
3530
}
36-
37-
exception!(HardFault, hard_fault);
38-
39-
fn hard_fault(_ef: &ExceptionFrame) -> ! {
40-
asm::bkpt();
41-
42-
loop {
43-
// add some side effect to prevent LLVM from turning this into a UDF (abort) instruction
44-
// see rust-lang/rust#28728 for details
45-
atomic::compiler_fence(Ordering::SeqCst)
46-
}
47-
}
48-
49-
exception!(*, default_handler);
50-
51-
fn default_handler(_irqn: i16) {
52-
loop {
53-
atomic::compiler_fence(Ordering::SeqCst)
54-
}
55-
}

0 commit comments

Comments
 (0)