Skip to content

Commit e122258

Browse files
committed
F4 GPIO
1 parent a77d7a4 commit e122258

29 files changed

+5612
-1592
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/blinky.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ fn main() -> ! {
2929
loop {
3030
info!("Set Led low");
3131
for _ in 0..10_000_000 {
32-
led.set_low().unwrap();
32+
led.set_low();
3333
}
3434

3535
info!("Set Led High");
3636
for _ in 0..10_000_000 {
37-
led.set_high().unwrap();
37+
led.set_high();
3838
}
3939
}
4040
}

examples/blinky_delay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ fn main() -> ! {
4040

4141
loop {
4242
info!("Toggle");
43-
led.toggle().unwrap();
43+
led.toggle();
4444
info!("SYST delay");
4545
delay_syst.delay(1000.millis());
4646
info!("Toggle");
47-
led.toggle().unwrap();
47+
led.toggle();
4848
info!("TIM2 delay");
4949
delay_tim2.delay_ms(1000);
5050
}

examples/button.rs

Lines changed: 4 additions & 5 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},
@@ -14,9 +14,8 @@ use core::cell::RefCell;
1414
use core::sync::atomic::{AtomicBool, Ordering};
1515
use cortex_m::{asm::wfi, interrupt::Mutex};
1616
use cortex_m_rt::entry;
17-
use embedded_hal::digital::OutputPin;
1817

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

2120
// Make LED pin globally available
2221
static G_BUTTON: Mutex<RefCell<Option<ButtonPin>>> = Mutex::new(RefCell::new(None));
@@ -86,10 +85,10 @@ fn main() -> ! {
8685

8786
if G_LED_ON.load(Ordering::Relaxed) {
8887
println!("Turn Led On!");
89-
led.set_high().unwrap();
88+
led.set_high();
9089
} else {
9190
println!("Turn Led Off!");
92-
led.set_low().unwrap();
91+
led.set_low();
9392
}
9493
}
9594
}

examples/can-echo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ fn main() -> ! {
5757

5858
let can1 = {
5959
info!("Init CAN 1");
60-
let rx = gpiob.pb8.into_alternate().set_speed(Speed::VeryHigh);
61-
let tx = gpiob.pb9.into_alternate().set_speed(Speed::VeryHigh);
60+
let rx = gpiob.pb8.into_alternate().speed(Speed::VeryHigh);
61+
let tx = gpiob.pb9.into_alternate().speed(Speed::VeryHigh);
6262

6363
info!("-- Create CAN 1 instance");
6464
let mut can = dp.FDCAN1.fdcan(tx, rx, &rcc);
@@ -82,8 +82,8 @@ fn main() -> ! {
8282

8383
// let can2 = {
8484
// info!("Init CAN 2");
85-
// let rx = gpiob.pb5.into_alternate().set_speed(Speed::VeryHigh);
86-
// let tx = gpiob.pb13.into_alternate().set_speed(Speed::VeryHigh);
85+
// let rx = gpiob.pb5.into_alternate().speed(Speed::VeryHigh);
86+
// let tx = gpiob.pb13.into_alternate().speed(Speed::VeryHigh);
8787

8888
// info!("-- Create CAN 2 instance");
8989
// let mut can = dp.FDCAN2.fdcan(tx, rx, &rcc);

examples/comp.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rt::entry;
1717
fn main() -> ! {
1818
use hal::comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis};
1919
use hal::gpio::GpioExt;
20-
use hal::prelude::OutputPin;
2120
use hal::rcc::RccExt;
2221
use hal::stm32;
2322
use stm32g4xx_hal as hal;
@@ -55,8 +54,8 @@ fn main() -> ! {
5554
loop {
5655
// Read comp1 output and update led1 accordingly
5756
match comp1.output() {
58-
true => led1.set_high().unwrap(),
59-
false => led1.set_low().unwrap(),
57+
true => led1.set_high(),
58+
false => led1.set_low(),
6059
}
6160
}
6261
}

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);

0 commit comments

Comments
 (0)