Skip to content

Commit 3f050fe

Browse files
committed
F4 GPIO
1 parent 996f47c commit 3f050fe

24 files changed

+5573
-1626
lines changed

.vscode/settings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"rust-analyzer.check.allTargets": false,
3-
"rust-analyzer.check.extraArgs": [
4-
"--examples",
5-
],
3+
"rust-analyzer.check.extraArgs": ["--examples"],
64
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
75
"rust-analyzer.cargo.features": [
86
"stm32g484",

Cargo.toml

Lines changed: 224 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ authors = ["Vitaly Domnikov <[email protected]>"]
33
categories = ["embedded", "hardware-support", "no-std"]
44
description = "Peripheral access API for STM32G4 series microcontrollers"
55
documentation = "https://docs.rs/stm32g4xx-hal"
6-
edition = "2018"
6+
edition = "2021"
77
keywords = ["arm", "cortex-m", "stm32g4xx", "hal"]
88
license = "MIT/Apache-2.0"
99
name = "stm32g4xx-hal"
@@ -80,12 +80,226 @@ rt = ["stm32g4/rt"]
8080
usb = ["dep:stm32-usbd"]
8181
stm32g431 = ["stm32g4/stm32g431", "cat2"]
8282
stm32g441 = ["stm32g4/stm32g441", "cat2"]
83-
stm32g473 = ["stm32g4/stm32g473", "cat3", "adc3", "adc4", "adc5"]
84-
stm32g474 = ["stm32g4/stm32g474", "cat3", "adc3", "adc4", "adc5"]
85-
stm32g483 = ["stm32g4/stm32g483", "cat3", "adc3", "adc4", "adc5"]
86-
stm32g484 = ["stm32g4/stm32g484", "cat3", "adc3", "adc4", "adc5"]
87-
stm32g491 = ["stm32g4/stm32g491", "cat4", "adc3"]
88-
stm32g4a1 = ["stm32g4/stm32g4a1", "cat4", "adc3"]
83+
stm32g473 = ["stm32g4/stm32g473", "cat3"]
84+
stm32g474 = ["stm32g4/stm32g474", "cat3"]
85+
stm32g483 = ["stm32g4/stm32g483", "cat3"]
86+
stm32g484 = ["stm32g4/stm32g484", "cat3"]
87+
stm32g491 = ["stm32g4/stm32g491", "cat4"]
88+
stm32g4a1 = ["stm32g4/stm32g4a1", "cat4"]
89+
90+
gpio-g43x = [
91+
"comp1",
92+
"comp2",
93+
"comp3",
94+
"comp4",
95+
"crs",
96+
"fdcan1",
97+
"gpioa",
98+
"gpiob",
99+
"gpioc",
100+
"gpiod",
101+
"gpioe",
102+
"gpiof",
103+
"gpiog",
104+
"i2c1",
105+
"i2c2",
106+
"i2c3",
107+
"i2s",
108+
"i2s2",
109+
"i2s3",
110+
"ir",
111+
"lptim1",
112+
"lpuart1",
113+
"rcc",
114+
"rtc",
115+
"sai1",
116+
"spi1",
117+
"spi2",
118+
"spi3",
119+
"sys",
120+
"tim1",
121+
"tim15",
122+
"tim16",
123+
"tim17",
124+
"tim2",
125+
"tim3",
126+
"tim4",
127+
"tim8",
128+
"uart4",
129+
"ucpd1",
130+
"usart1",
131+
"usart2",
132+
"usart3",
133+
]
134+
gpio-g47x = [
135+
"adc3",
136+
"adc4",
137+
"adc5",
138+
"comp1",
139+
"comp2",
140+
"comp3",
141+
"comp4",
142+
"comp5",
143+
"comp6",
144+
"comp7",
145+
"crs",
146+
"fdcan1",
147+
"fdcan2",
148+
"fdcan3",
149+
"fmc",
150+
"gpioa",
151+
"gpiob",
152+
"gpioc",
153+
"gpiod",
154+
"gpioe",
155+
"gpiof",
156+
"gpiog",
157+
"hrtim1",
158+
"i2c1",
159+
"i2c2",
160+
"i2c3",
161+
"i2c4",
162+
"i2s",
163+
"i2s2",
164+
"i2s3",
165+
"ir",
166+
"lptim1",
167+
"lpuart1",
168+
"quadspi1",
169+
"rcc",
170+
"rtc",
171+
"sai1",
172+
"spi1",
173+
"spi2",
174+
"spi3",
175+
"spi4",
176+
"sys",
177+
"tim1",
178+
"tim15",
179+
"tim16",
180+
"tim17",
181+
"tim2",
182+
"tim20",
183+
"tim3",
184+
"tim4",
185+
"tim5",
186+
"tim8",
187+
"uart4",
188+
"uart5",
189+
"ucpd1",
190+
"usart1",
191+
"usart2",
192+
"usart3",
193+
]
194+
gpio-g49x = [
195+
"adc3",
196+
"comp1",
197+
"comp2",
198+
"comp3",
199+
"comp4",
200+
"crs",
201+
"fdcan1",
202+
"fdcan2",
203+
"gpioa",
204+
"gpiob",
205+
"gpioc",
206+
"gpiod",
207+
"gpioe",
208+
"gpiof",
209+
"gpiog",
210+
"i2c1",
211+
"i2c2",
212+
"i2c3",
213+
"i2s",
214+
"i2s2",
215+
"i2s3",
216+
"ir",
217+
"lptim1",
218+
"lpuart1",
219+
"quadspi1",
220+
"rcc",
221+
"rtc",
222+
"sai1",
223+
"spi1",
224+
"spi2",
225+
"spi3",
226+
"sys",
227+
"tim1",
228+
"tim15",
229+
"tim16",
230+
"tim17",
231+
"tim2",
232+
"tim20",
233+
"tim3",
234+
"tim4",
235+
"tim8",
236+
"uart4",
237+
"uart5",
238+
"ucpd1",
239+
"usart1",
240+
"usart2",
241+
"usart3",
242+
]
243+
244+
adc3 = []
245+
adc4 = []
246+
adc5 = []
247+
comp1 = []
248+
comp2 = []
249+
comp3 = []
250+
comp4 = []
251+
comp5 = []
252+
comp6 = []
253+
comp7 = []
254+
crs = []
255+
fdcan1 = []
256+
fdcan2 = []
257+
fdcan3 = []
258+
fmc = []
259+
gpioa = []
260+
gpiob = []
261+
gpioc = []
262+
gpiod = []
263+
gpioe = []
264+
gpiof = []
265+
gpiog = []
266+
hrtim1 = []
267+
i2c1 = []
268+
i2c2 = []
269+
i2c3 = []
270+
i2c4 = []
271+
i2s = []
272+
i2s2 = []
273+
i2s3 = []
274+
ir = []
275+
lptim1 = []
276+
lpuart1 = []
277+
quadspi1 = []
278+
rcc = []
279+
rtc = []
280+
sai1 = []
281+
spi1 = []
282+
spi2 = []
283+
spi3 = []
284+
spi4 = []
285+
sys = []
286+
tim1 = []
287+
tim15 = []
288+
tim16 = []
289+
tim17 = []
290+
tim2 = []
291+
tim20 = []
292+
tim3 = []
293+
tim4 = []
294+
tim5 = []
295+
tim8 = []
296+
uart4 = []
297+
uart5 = []
298+
ucpd1 = []
299+
usart1 = []
300+
usart2 = []
301+
usart3 = []
302+
89303
log-itm = ["cortex-m-log/itm"]
90304
log-rtt = []
91305
log-semihost = ["cortex-m-log/semihosting"]
@@ -98,14 +312,11 @@ defmt = [
98312
"embedded-io/defmt-03",
99313
]
100314
cordic = ["dep:fixed"]
101-
adc3 = []
102-
adc4 = []
103-
adc5 = []
104315

105316
# Device category
106-
cat2 = []
107-
cat3 = []
108-
cat4 = []
317+
cat2 = ["gpio-g43x"]
318+
cat3 = ["gpio-g47x"]
319+
cat4 = ["gpio-g49x"]
109320

110321
can = ["dep:fdcan"]
111322

examples/button.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use stm32g4xx_hal::{
55
//delay::{DelayExt, SYSTDelayExt},
6-
gpio::{self, ExtiPin, GpioExt, Input, PullDown, SignalEdge},
6+
gpio::{self, ExtiPin, GpioExt, Input, SignalEdge},
77
rcc::RccExt,
88
stm32,
99
stm32::{interrupt, Interrupt},
@@ -15,7 +15,7 @@ use core::sync::atomic::{AtomicBool, Ordering};
1515
use cortex_m::{asm::wfi, interrupt::Mutex};
1616
use cortex_m_rt::entry;
1717

18-
type ButtonPin = gpio::PC13<Input<PullDown>>;
18+
type ButtonPin = gpio::PC13<Input>;
1919

2020
// Make LED pin globally available
2121
static G_BUTTON: Mutex<RefCell<Option<ButtonPin>>> = Mutex::new(RefCell::new(None));

examples/i2c.rs

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

6-
use hal::i2c::Config;
76
use hal::prelude::*;
87
use hal::stm32;
98
use hal::time::RateExtU32;
@@ -23,12 +22,13 @@ fn main() -> ! {
2322
let mut rcc = dp.RCC.constrain();
2423
let gpiob = dp.GPIOB.split(&mut rcc);
2524

26-
let sda = gpiob.pb9.into_alternate_open_drain();
27-
let scl = gpiob.pb8.into_alternate_open_drain();
25+
let sda = gpiob.pb9;
26+
let scl = gpiob.pb8;
2827

29-
let mut i2c = dp.I2C1.i2c(sda, scl, Config::new(40.kHz()), &mut rcc);
28+
let mut i2c = dp.I2C1.i2c(sda, scl, 40.kHz(), &mut rcc);
3029
// Alternatively, it is possible to specify the exact timing as follows (see the documentation
3130
// of with_timing() for an explanation of the constant):
31+
//use hal::i2c::Config;
3232
//let mut i2c = dp
3333
// .I2C1
3434
// .i2c(sda, scl, Config::with_timing(0x3042_0f13), &mut rcc);

examples/spi-dma.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use crate::hal::{
88
delay::DelayFromCountDownTimer,
9-
gpio::{AF5, PA5, PA6, PA7},
109
prelude::*,
1110
pwr::PwrExt,
1211
rcc::Config,
@@ -40,9 +39,9 @@ fn main() -> ! {
4039
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
4140

4241
let gpioa = dp.GPIOA.split(&mut rcc);
43-
let sclk: PA5<AF5> = gpioa.pa5.into_alternate();
44-
let miso: PA6<AF5> = gpioa.pa6.into_alternate();
45-
let mosi: PA7<AF5> = gpioa.pa7.into_alternate();
42+
let sclk = gpioa.pa5;
43+
let miso = gpioa.pa6;
44+
let mosi = gpioa.pa7;
4645

4746
let spi = dp
4847
.SPI1

examples/spi-sd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() -> ! {
3434
let gpiof = dp.GPIOF.split(&mut rcc);
3535

3636
let cs = {
37-
let mut cs = gpiof.pf8.into_push_pull_output();
37+
let mut cs = gpiof.pf0.into_push_pull_output();
3838
cs.set_high();
3939
cs
4040
};

src/comparator.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ output_pin! {
621621
COMP1: PA6, 8,
622622
COMP1: PA11, 8,
623623
COMP1: PB8, 8,
624-
COMP1: PF4, 2,
625624

626625
COMP2: PA2, 8,
627626
COMP2: PA7, 8,
@@ -637,13 +636,10 @@ output_pin! {
637636
COMP4: PB14, 8,
638637
}
639638

640-
#[cfg(any(
641-
feature = "stm32g473",
642-
feature = "stm32g483",
643-
feature = "stm32g474",
644-
feature = "stm32g484",
645-
))]
639+
#[cfg(feature = "gpio-g47x")]
646640
output_pin! {
641+
COMP1: PF4, 2,
642+
647643
COMP5: PA9, 8,
648644
COMP5: PC7, 7,
649645

src/delay.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,12 @@ impl DelayMs<u8> for SystDelay {
119119
}
120120

121121
pub trait DelayExt {
122-
fn delay<T>(&mut self, delay: T)
123-
where
124-
T: Into<MicroSecond>;
122+
fn delay(&mut self, delay: MicroSecond);
125123
}
126124

127125
impl DelayExt for SystDelay {
128-
fn delay<T>(&mut self, delay: T)
129-
where
130-
T: Into<MicroSecond>,
131-
{
132-
self.0.delay_us(delay.into().ticks())
126+
fn delay(&mut self, delay: MicroSecond) {
127+
self.0.delay_us(delay.ticks())
133128
}
134129
}
135130

0 commit comments

Comments
 (0)