Skip to content

Commit b6b9054

Browse files
committed
Fix compile error
fix(09-clocks-and-timers): Compile failed in release mode docs: Update putting-it-all-together.md fix: compile error in chapter 11 fix: compile error in chapter 14 fix: compile error in chapter 15 fix: compile error in chapter 16 chore: handle `Result` with unwrap rather than ok chore: remove useless dependencies fix: restore main.rs
1 parent 3132ecd commit b6b9054

File tree

22 files changed

+160
-99
lines changed

22 files changed

+160
-99
lines changed

src/09-clocks-and-timers/auxiliary/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ version = "0.1.0"
88
cortex-m = "0.6.3"
99
cortex-m-rt = "0.6.3"
1010
panic-itm = "0.4.0"
11+
stm32f3-discovery = "0.6.0"
1112

12-
[dependencies.f3]
13-
features = ["rt"]
14-
version = "0.6.1"
13+
[dependencies.stm32f3]
14+
version = "0.12.1"
15+
features = ["stm32f303", "rt"]

src/09-clocks-and-timers/auxiliary/src/lib.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,37 @@ extern crate panic_itm; // panic handler
77

88
pub use cortex_m::asm::{bkpt, nop};
99
pub use cortex_m_rt::entry;
10-
pub use f3::{
11-
hal::stm32f30x::{rcc, tim6},
12-
led::Leds,
13-
};
10+
pub use stm32f3::stm32f303::{rcc, tim6, RCC, TIM6};
11+
pub use stm32f3_discovery::switch_hal;
1412

15-
use f3::hal::{
16-
prelude::*,
17-
stm32f30x::{self, RCC, TIM6},
13+
use stm32f3_discovery::{
14+
leds::Leds,
15+
stm32f3xx_hal::{prelude::*, stm32},
1816
};
1917

2018
pub fn init() -> (
2119
Leds,
2220
&'static rcc::RegisterBlock,
2321
&'static tim6::RegisterBlock,
2422
) {
25-
let p = stm32f30x::Peripherals::take().unwrap();
23+
let p = stm32::Peripherals::take().unwrap();
2624

2725
let mut rcc = p.RCC.constrain();
2826

29-
let leds = Leds::new(p.GPIOE.split(&mut rcc.ahb));
27+
let mut gpioe = p.GPIOE.split(&mut rcc.ahb);
28+
29+
let leds = Leds::new(
30+
gpioe.pe8,
31+
gpioe.pe9,
32+
gpioe.pe10,
33+
gpioe.pe11,
34+
gpioe.pe12,
35+
gpioe.pe13,
36+
gpioe.pe14,
37+
gpioe.pe15,
38+
&mut gpioe.moder,
39+
&mut gpioe.otyper,
40+
);
3041

3142
(leds, unsafe { &*RCC::ptr() }, unsafe { &*TIM6::ptr() })
3243
}

src/09-clocks-and-timers/putting-it-all-together.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![no_main]
55
#![no_std]
66

7-
use aux9::{entry, tim6};
7+
use aux9::{entry, switch_hal::OutputSwitch, tim6};
88

99
#[inline(never)]
1010
fn delay(tim6: &tim6::RegisterBlock, ms: u16) {
@@ -24,7 +24,8 @@ fn delay(tim6: &tim6::RegisterBlock, ms: u16) {
2424

2525
#[entry]
2626
fn main() -> ! {
27-
let (mut leds, rcc, tim6) = aux9::init();
27+
let (leds, rcc, tim6) = aux9::init();
28+
let mut leds = leds.into_array();
2829

2930
// Power on the TIM6 timer
3031
rcc.apb1enr.modify(|_, w| w.tim6en().set_bit());
@@ -45,9 +46,9 @@ fn main() -> ! {
4546
for curr in 0..8 {
4647
let next = (curr + 1) % 8;
4748

48-
leds[next].on();
49+
leds[next].on().unwrap();
4950
delay(tim6, ms);
50-
leds[curr].off();
51+
leds[curr].off().unwrap();
5152
delay(tim6, ms);
5253
}
5354
}

src/09-clocks-and-timers/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![no_main]
22
#![no_std]
33

4-
use aux9::{entry, tim6};
4+
use aux9::{entry, switch_hal::OutputSwitch, tim6};
55

66
#[inline(never)]
77
fn delay(tim6: &tim6::RegisterBlock, ms: u16) {
@@ -10,7 +10,8 @@ fn delay(tim6: &tim6::RegisterBlock, ms: u16) {
1010

1111
#[entry]
1212
fn main() -> ! {
13-
let (mut leds, rcc, tim6) = aux9::init();
13+
let (leds, rcc, tim6) = aux9::init();
14+
let mut leds = leds.into_array();
1415

1516
// TODO initialize TIM6
1617

@@ -19,9 +20,9 @@ fn main() -> ! {
1920
for curr in 0..8 {
2021
let next = (curr + 1) % 8;
2122

22-
leds[next].on();
23+
leds[next].on().unwrap();
2324
delay(tim6, ms);
24-
leds[curr].off();
25+
leds[curr].off().unwrap();
2526
delay(tim6, ms);
2627
}
2728
}

src/11-usart/auxiliary/Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ name = "aux11"
55
version = "0.1.0"
66

77
[dependencies]
8-
cortex-m = "=0.5.6" # 0.5.11 introduces a breaking change. Use 0.5.6, since we know it works for this example
8+
cortex-m = "0.6.3"
99
cortex-m-rt = "0.6.3"
1010
panic-itm = "0.4.0"
11-
12-
[dependencies.f3]
13-
features = ["rt"]
14-
version = "0.6.1"
11+
stm32f3-discovery = "0.6.0"
1512

1613
[features]
17-
adapter = []
14+
adapter = []

src/11-usart/auxiliary/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ extern crate panic_itm; // panic handler
77

88
pub use cortex_m::{asm::bkpt, iprint, iprintln, peripheral::ITM};
99
pub use cortex_m_rt::entry;
10-
pub use f3::hal::{prelude, serial::Serial, stm32f30x::usart1, time::MonoTimer};
10+
pub use stm32f3_discovery::stm32f3xx_hal::stm32::usart1;
1111

12-
use f3::hal::{
12+
use stm32f3_discovery::stm32f3xx_hal::{
1313
prelude::*,
14-
stm32f30x::{self, USART1},
14+
serial::Serial,
15+
stm32::{self, USART1},
16+
time::MonoTimer,
1517
};
1618

1719
pub fn init() -> (&'static mut usart1::RegisterBlock, MonoTimer, ITM) {
1820
let cp = cortex_m::Peripherals::take().unwrap();
19-
let dp = stm32f30x::Peripherals::take().unwrap();
21+
let dp = stm32::Peripherals::take().unwrap();
2022

2123
let mut flash = dp.FLASH.constrain();
2224
let mut rcc = dp.RCC.constrain();

src/11-usart/buffer-overrun.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
If you wrote your program like this:
44

55
``` rust
6-
#![deny(unsafe_code)]
76
#![no_main]
87
#![no_std]
98

@@ -16,7 +15,9 @@ fn main() -> ! {
1615

1716
// Send a string
1817
for byte in b"The quick brown fox jumps over the lazy dog.".iter() {
19-
usart1.tdr.write(|w| w.tdr().bits(u16::from(*byte)));
18+
usart1
19+
.tdr
20+
.write(|w| unsafe { w.tdr().bits(u16::from(*byte)) });
2021
}
2122

2223
loop {}
@@ -108,7 +109,6 @@ to write to the `TDR` register without incurring in data loss.
108109
Let's use that to slowdown the processor.
109110

110111
``` rust
111-
#![deny(unsafe_code)]
112112
#![no_main]
113113
#![no_std]
114114

@@ -125,7 +125,9 @@ fn main() -> ! {
125125
// wait until it's safe to write to TDR
126126
while usart1.isr.read().txe().bit_is_clear() {} // <- NEW!
127127

128-
usart1.tdr.write(|w| w.tdr().bits(u16::from(*byte)));
128+
usart1
129+
.tdr
130+
.write(|w| unsafe { w.tdr().bits(u16::from(*byte)) });
129131
}
130132
let elapsed = instant.elapsed(); // in ticks
131133

src/11-usart/my-solution.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# My solution
22

33
```rust
4-
#![deny(unsafe_code)]
54
#![no_main]
65
#![no_std]
76

@@ -27,7 +26,9 @@ fn main() -> ! {
2726
// buffer full
2827
for byte in b"error: buffer full\n\r" {
2928
while usart1.isr.read().txe().bit_is_clear() {}
30-
usart1.tdr.write(|w| w.tdr().bits(u16::from(*byte)));
29+
usart1
30+
.tdr
31+
.write(|w| unsafe { w.tdr().bits(u16::from(*byte)) });
3132
}
3233

3334
break;
@@ -38,7 +39,9 @@ fn main() -> ! {
3839
// Respond
3940
for byte in buffer.iter().rev().chain(&[b'\n', b'\r']) {
4041
while usart1.isr.read().txe().bit_is_clear() {}
41-
usart1.tdr.write(|w| w.tdr().bits(u16::from(*byte)));
42+
usart1
43+
.tdr
44+
.write(|w| unsafe { w.tdr().bits(u16::from(*byte)) });
4245
}
4346

4447
break;

src/11-usart/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![deny(unsafe_code)]
21
#![no_main]
32
#![no_std]
43

@@ -10,7 +9,9 @@ fn main() -> ! {
109
let (usart1, mono_timer, itm) = aux11::init();
1110

1211
// Send a single character
13-
usart1.tdr.write(|w| w.tdr().bits(u16::from(b'X')));
12+
usart1
13+
.tdr
14+
.write(|w| unsafe { w.tdr().bits(u16::from(b'X')) });
1415

1516
loop {}
1617
}

src/14-i2c/auxiliary/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ name = "aux14"
55
version = "0.1.0"
66

77
[dependencies]
8-
cortex-m = "=0.5.6"
8+
cortex-m = "0.6.3"
99
cortex-m-rt = "0.6.3"
1010
panic-itm = "0.4.0"
11-
12-
[dependencies.f3]
13-
features = ["rt"]
14-
version = "0.6.1"
11+
stm32f3-discovery = "0.6.0"

0 commit comments

Comments
 (0)