Skip to content

Commit a085fa8

Browse files
authored
Merge pull request #23 from ijager/pac_update
Use updated PACs and make sure the crate compiles for each part
2 parents 47cb852 + 5e71302 commit a085fa8

File tree

12 files changed

+83
-54
lines changed

12 files changed

+83
-54
lines changed

Cargo.toml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ features = ["stm32g081", "rt"]
1616
default-target = "thumbv6m-none-eabi"
1717

1818
[dependencies]
19-
cortex-m = "0.6.1"
19+
cortex-m = "0.6.3"
2020
nb = "0.1.1"
21-
stm32g0 = "0.10.0"
22-
as-slice = "0.1.2"
21+
as-slice = "0.1.3"
22+
23+
[dependencies.stm32g0]
24+
git = "https://github.com/stm32-rs/stm32-rs-nightlies"
25+
# version = "0.12.0"
26+
features = ["rt"]
2327

2428
[dependencies.bare-metal]
25-
features = ["const-fn"]
26-
version = "0.2.5"
29+
version = "1.0.0"
2730

2831
[dependencies.embedded-hal]
2932
features = ["unproven"]
30-
version = "0.2.3"
33+
version = "0.2.4"
3134

3235
[dependencies.void]
3336
default-features = false
@@ -48,20 +51,16 @@ ws2812-spi = {git = "https://github.com/smart-leds-rs/ws2812-spi-rs"}
4851

4952
[features]
5053
rt = ["stm32g0/rt"]
51-
5254
stm32g030 = ["stm32g0/stm32g030", "stm32g0x0"]
53-
stm32g070 = ["stm32g0/stm32g07x", "stm32g0x0"]
55+
stm32g070 = ["stm32g0/stm32g070", "stm32g0x0"]
5456
stm32g031 = ["stm32g0/stm32g031", "stm32g0x1"]
5557
stm32g041 = ["stm32g0/stm32g041", "stm32g0x1"]
56-
stm32g071 = ["stm32g0/stm32g07x", "stm32g0x1"]
58+
stm32g071 = ["stm32g0/stm32g071", "stm32g0x1"]
5759
stm32g081 = ["stm32g0/stm32g081", "stm32g0x1"]
5860

5961
stm32g0x0 = []
6062
stm32g0x1 = []
6163

62-
# deprecated, map to "stm32g071" for now
63-
stm32g07x = ["stm32g0/stm32g07x", "stm32g071"]
64-
6564
[profile.dev]
6665
incremental = false
6766

examples/blinky_random.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ extern crate cortex_m_rt as rt;
88
extern crate panic_halt;
99
extern crate stm32g0xx_hal as hal;
1010

11+
#[cfg(not(any(
12+
feature = "stm32g041",
13+
feature = "stm32g081"
14+
)))]
15+
compile_error!(
16+
"Only stm32g041 and stm32g081 have the RNG peripheral"
17+
);
18+
1119
use cortex_m_semihosting::hprintln;
1220
use hal::prelude::*;
1321
use hal::rng::Config;

examples/dac.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
#![no_main]
44
#![no_std]
55

6+
#[cfg(not(any(
7+
feature = "stm32g071",
8+
feature = "stm32g081"
9+
)))]
10+
compile_error!(
11+
"Only stm32g071 and stm32g081 have the DAC peripheral"
12+
);
13+
614
extern crate cortex_m;
715
extern crate cortex_m_rt as rt;
816
extern crate panic_halt;

examples/stopwatch.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ fn main() -> ! {
2424

2525
let mut delay = cp.SYST.delay(&mut rcc);
2626
let mut timer = dp.TIM17.timer(&mut rcc);
27+
28+
#[cfg(feature = "stm32g0x1")]
2729
let mut stopwatch = dp.TIM2.stopwatch(&mut rcc);
30+
#[cfg(feature = "stm32g0x0")] // TODO: not tested yet with TIM3
31+
let mut stopwatch = dp.TIM3.stopwatch(&mut rcc);
2832

2933
let elapsed_us = stopwatch.trace(|| {
3034
delay.delay(10.us());

src/dma.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ macro_rules! dma {
241241

242242
dma! {
243243
DMA: (dmaen, dma1rst, {
244-
Channel1: ( ccr1, cndtr1, cpar1, cmar1, cgif0 ),
245-
Channel2: ( ccr2, cndtr2, cpar2, cmar2, cgif4 ),
246-
Channel3: ( ccr3, cndtr3, cpar3, cmar3, cgif8 ),
247-
Channel4: ( ccr4, cndtr4, cpar4, cmar4, cgif12 ),
248-
Channel5: ( ccr5, cndtr5, cpar5, cmar5, cgif16 ),
244+
Channel1: ( ccr1, cndtr1, cpar1, cmar1, cgif1 ),
245+
Channel2: ( ccr2, cndtr2, cpar2, cmar2, cgif2 ),
246+
Channel3: ( ccr3, cndtr3, cpar3, cmar3, cgif3 ),
247+
Channel4: ( ccr4, cndtr4, cpar4, cmar4, cgif4 ),
248+
Channel5: ( ccr5, cndtr5, cpar5, cmar5, cgif5 ),
249249
}),
250250
}

src/exti.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,23 @@ impl ExtiExt for EXTI {
103103
}
104104

105105
fn wakeup(&self, ev: Event) {
106-
#[cfg(any(feature = "stm32g030", feature = "stm32g031", feature = "stm32g041"))]
106+
#[cfg(any(feature = "stm32g030", feature = "stm32g070", feature = "stm32g031", feature = "stm32g041"))]
107107
self.imr1
108108
.modify(|r, w| unsafe { w.bits(r.bits() | 1 << ev as u8) });
109109

110-
// TODO: For some reason this is different between PACs:
111-
// imr1 vs imr1(). I think it is an SVD bug
112-
#[cfg(feature = "stm32g070")]
113-
self.imr1()
114-
.modify(|r, w| unsafe { w.bits(r.bits() | 1 << ev as u8) });
115-
116110
#[cfg(any(feature = "stm32g071", feature = "stm32g081"))]
117111
match ev as u8 {
118112
line if line < 32 => self
119-
.imr1()
120-
.modify(|r, w| unsafe { w.bits(r.bits() | 1 << line) }),
113+
.imr1.modify(|r, w| unsafe { w.bits(r.bits() | 1 << line) }),
121114
line => self
122-
.imr2
123-
.modify(|r, w| unsafe { w.bits(r.bits() | 1 << (line - 32)) }),
115+
.imr2.modify(|r, w| unsafe { w.bits(r.bits() | 1 << (line - 32)) }),
124116
}
125117
}
126118

127119
fn unlisten(&self, ev: Event) {
128120
self.unpend(ev);
129121

130-
#[cfg(any(feature = "stm32g030", feature = "stm32g031", feature = "stm32g041"))]
122+
#[cfg(any(feature = "stm32g030", feature = "stm32g070", feature = "stm32g031", feature = "stm32g041"))]
131123
{
132124
let line = ev as u8;
133125
let mask = !(1 << line);
@@ -138,24 +130,11 @@ impl ExtiExt for EXTI {
138130
}
139131
}
140132

141-
// TODO: For some reason this is different between PACs:
142-
// imr1 vs imr1(). I think it is an SVD bug
143-
#[cfg(feature = "stm32g070")]
144-
{
145-
let line = ev as u8;
146-
let mask = !(1 << line);
147-
self.imr1().modify(|r, w| unsafe { w.bits(r.bits() & mask) });
148-
if line <= TRIGGER_MAX {
149-
self.rtsr1.modify(|r, w| unsafe { w.bits(r.bits() & mask) });
150-
self.ftsr1.modify(|r, w| unsafe { w.bits(r.bits() & mask) });
151-
}
152-
}
153-
154133
#[cfg(any(feature = "stm32g071", feature = "stm32g081"))]
155134
match ev as u8 {
156135
line if line < 32 => {
157136
let mask = !(1 << line);
158-
self.imr1().modify(|r, w| unsafe { w.bits(r.bits() & mask) });
137+
self.imr1.modify(|r, w| unsafe { w.bits(r.bits() & mask) });
159138
if line <= TRIGGER_MAX {
160139
self.rtsr1.modify(|r, w| unsafe { w.bits(r.bits() & mask) });
161140
self.ftsr1.modify(|r, w| unsafe { w.bits(r.bits() & mask) });

src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ pub use nb::block;
2626
#[cfg(feature = "stm32g030")]
2727
pub use stm32g0::stm32g030 as stm32;
2828

29-
#[cfg(feature = "stm32g070")]
30-
pub use stm32g0::stm32g07x as stm32; // TODO will be stm32g070, to be fixed in next pac release
3129

3230
#[cfg(feature = "stm32g031")]
3331
pub use stm32g0::stm32g031 as stm32;
@@ -36,15 +34,20 @@ pub use stm32g0::stm32g031 as stm32;
3634
pub use stm32g0::stm32g041 as stm32;
3735

3836
#[cfg(feature = "stm32g071")]
39-
pub use stm32g0::stm32g07x as stm32; // TODO will be stm32g071, to be fixed in next pac release
37+
pub use stm32g0::stm32g071 as stm32;
4038

4139
#[cfg(feature = "stm32g081")]
4240
pub use stm32g0::stm32g081 as stm32;
4341

42+
43+
#[cfg(feature = "stm32g070")]
44+
pub use stm32g0::stm32g070 as stm32;
45+
4446
#[cfg(feature = "rt")]
4547
pub use crate::stm32::interrupt;
4648

4749
pub mod analog;
50+
// TODO fix
4851
// #[cfg(any(feature = "stm32g071", feature = "stm32g081"))]
4952
// pub mod comparator;
5053
pub mod crc;
@@ -55,6 +58,7 @@ pub mod gpio;
5558
pub mod i2c;
5659
pub mod prelude;
5760
pub mod rcc;
61+
#[cfg(any(feature = "stm32g041", feature = "stm32g081"))]
5862
pub mod rng;
5963
pub mod rtc;
6064
pub mod serial;

src/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ pub use crate::i2c::I2cExt as _;
2323
pub use crate::rcc::LSCOExt as _;
2424
pub use crate::rcc::MCOExt as _;
2525
pub use crate::rcc::RccExt as _;
26+
#[cfg(any(feature = "stm32g041", feature = "stm32g081"))]
2627
pub use crate::rng::RngCore as _;
28+
#[cfg(any(feature = "stm32g041", feature = "stm32g081"))]
2729
pub use crate::rng::RngExt as _;
2830
pub use crate::rtc::RtcExt as _;
2931
pub use crate::serial::SerialExt as _;

src/timer/opm.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ opm_hal! {
121121
TIM1: (Channel2, cc2e, ccmr1_output, oc2m, oc2fe, ccr2, arr),
122122
TIM1: (Channel3, cc3e, ccmr2_output, oc3m, oc3fe, ccr3, arr),
123123
TIM1: (Channel4, cc4e, ccmr2_output, oc4m, oc4fe, ccr4, arr),
124-
TIM2: (Channel1, cc1e, ccmr1_output, oc1m, oc1fe, ccr1, arr_l, arr_h),
125-
TIM2: (Channel2, cc2e, ccmr1_output, oc2m, oc2fe, ccr2, arr_l, arr_h),
126-
TIM2: (Channel3, cc3e, ccmr2_output, oc3m, oc3fe, ccr3, arr_l, arr_h),
127-
TIM2: (Channel4, cc4e, ccmr2_output, oc4m, oc4fe, ccr4, arr_l, arr_h),
128124
TIM3: (Channel1, cc1e, ccmr1_output, oc1m, oc1fe, ccr1, arr_l, arr_h),
129125
TIM3: (Channel2, cc2e, ccmr1_output, oc2m, oc2fe, ccr2, arr_l, arr_h),
130126
TIM3: (Channel3, cc3e, ccmr2_output, oc3m, oc3fe, ccr3, arr_l, arr_h),
@@ -134,16 +130,27 @@ opm_hal! {
134130
TIM17: (Channel1, cc1e, ccmr1_output, oc1m, oc1fe, ccr1, arr),
135131
}
136132

137-
//todo probably needs feature switches since not all parts have all these timers
133+
#[cfg(feature = "stm32g0x1")]
134+
opm_hal! {
135+
TIM2: (Channel1, cc1e, ccmr1_output, oc1m, oc1fe, ccr1, arr_l, arr_h),
136+
TIM2: (Channel2, cc2e, ccmr1_output, oc2m, oc2fe, ccr2, arr_l, arr_h),
137+
TIM2: (Channel3, cc3e, ccmr2_output, oc3m, oc3fe, ccr3, arr_l, arr_h),
138+
TIM2: (Channel4, cc4e, ccmr2_output, oc4m, oc4fe, ccr4, arr_l, arr_h),
139+
}
140+
138141
opm! {
139142
TIM1: (apbenr2, apbrstr2, tim1, tim1en, tim1rst),
140-
TIM2: (apbenr1, apbrstr1, tim2, tim2en, tim2rst),
141143
TIM3: (apbenr1, apbrstr1, tim3, tim3en, tim3rst),
142144
TIM14: (apbenr2, apbrstr2, tim14, tim14en, tim14rst),
143145
TIM16: (apbenr2, apbrstr2, tim16, tim16en, tim16rst),
144146
TIM17: (apbenr2, apbrstr2, tim17, tim17en, tim17rst),
145147
}
146148

149+
#[cfg(feature = "stm32g0x1")]
150+
opm! {
151+
TIM2: (apbenr1, apbrstr1, tim2, tim2en, tim2rst),
152+
}
153+
147154
#[cfg(any(feature = "stm32g070", feature = "stm32g071", feature = "stm32g081"))]
148155
opm! {
149156
TIM15: (apbenr2, apbrstr2, tim15, tim15en, tim15rst),

src/timer/pins.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ timer_pins!(TIM1, [
4040
(Channel4, PC11<DefaultMode>, AltFunction::AF2),
4141
]);
4242

43+
#[cfg(feature = "stm32g0x1")]
4344
timer_pins!(TIM2, [
4445
(Channel1, PA0<DefaultMode>, AltFunction::AF2),
4546
(Channel1, PA5<DefaultMode>, AltFunction::AF2),

src/timer/pwm.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,15 @@ pwm_hal! {
158158
TIM17: (Channel1, cc1e, ccmr1_output, oc1pe, oc1m, ccr1, moe),
159159
}
160160

161+
#[cfg(feature = "stm32g0x1")]
161162
pwm_hal! {
162163
TIM2: (Channel1, cc1e, ccmr1_output, oc1pe, oc1m, ccr1, ccr1_l, ccr1_h),
163164
TIM2: (Channel2, cc2e, ccmr1_output, oc2pe, oc2m, ccr2, ccr2_l, ccr2_h),
164165
TIM2: (Channel3, cc3e, ccmr2_output, oc3pe, oc3m, ccr3, ccr3_l, ccr3_h),
165166
TIM2: (Channel4, cc4e, ccmr2_output, oc4pe, oc4m, ccr4, ccr4_l, ccr4_h),
167+
}
168+
169+
pwm_hal! {
166170
TIM3: (Channel1, cc1e, ccmr1_output, oc1pe, oc1m, ccr1, ccr1_l, ccr1_h),
167171
TIM3: (Channel2, cc2e, ccmr1_output, oc2pe, oc2m, ccr2, ccr2_l, ccr2_h),
168172
TIM3: (Channel3, cc3e, ccmr2_output, oc3pe, oc3m, ccr3, ccr3_l, ccr3_h),
@@ -176,13 +180,17 @@ pwm_hal! {
176180

177181
pwm! {
178182
TIM1: (apbenr2, apbrstr2, tim1, tim1en, tim1rst, arr),
179-
TIM2: (apbenr1, apbrstr1, tim2, tim2en, tim2rst, arr_l, arr_h),
180183
TIM3: (apbenr1, apbrstr1, tim3, tim3en, tim3rst, arr_l, arr_h),
181184
TIM14: (apbenr2, apbrstr2, tim14, tim14en, tim14rst, arr),
182185
TIM16: (apbenr2, apbrstr2, tim16, tim16en, tim16rst, arr),
183186
TIM17: (apbenr2, apbrstr2, tim17, tim17en, tim17rst, arr),
184187
}
185188

189+
#[cfg(feature = "stm32g0x1")]
190+
pwm! {
191+
TIM2: (apbenr1, apbrstr1, tim2, tim2en, tim2rst, arr_l, arr_h),
192+
}
193+
186194
#[cfg(any(feature = "stm32g070", feature = "stm32g071", feature = "stm32g081"))]
187195
pwm! {
188196
TIM15: (apbenr2, apbrstr2, tim15, tim15en, tim15rst, arr),

src/timer/qei.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//! Quadrature Encoder Interface
22
use crate::hal::{self, Direction};
33
use crate::rcc::Rcc;
4+
5+
#[cfg(feature = "stm32g0x1")]
46
use crate::stm32::{TIM1, TIM2, TIM3};
7+
#[cfg(feature = "stm32g0x0")]
8+
use crate::stm32::{TIM1, TIM3};
9+
510
use crate::timer::pins::TimerPin;
611
use crate::timer::*;
712

@@ -103,6 +108,10 @@ macro_rules! qei {
103108

104109
qei! {
105110
TIM1: (tim1, tim1en, tim1rst, apbenr2, apbrstr2, arr, cnt),
106-
TIM2: (tim2, tim2en, tim2rst, apbenr1, apbrstr1, arr_l, cnt_l),
107111
TIM3: (tim3, tim3en, tim3rst, apbenr1, apbrstr1, arr_l, cnt_l),
108112
}
113+
114+
#[cfg(feature = "stm32g0x1")]
115+
qei! {
116+
TIM2: (tim2, tim2en, tim2rst, apbenr1, apbrstr1, arr_l, cnt_l),
117+
}

0 commit comments

Comments
 (0)