Skip to content

Commit 73ebd7f

Browse files
committed
F4 GPIO
1 parent d76ab4c commit 73ebd7f

25 files changed

+3509
-1333
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: 217 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,225 @@ 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"]
8989

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+
]
90243

91-
gpio-g43x = []
92-
93-
gpio-g47x = []
94-
95-
gpio-g49x = []
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 = []
96302

97303
log-itm = ["cortex-m-log/itm"]
98304
log-rtt = []
@@ -106,9 +312,6 @@ defmt = [
106312
"embedded-io/defmt-03",
107313
]
108314
cordic = ["dep:fixed"]
109-
adc3 = []
110-
adc4 = []
111-
adc5 = []
112315

113316
# Device category
114317
cat2 = ["gpio-g43x"]

examples/adc-continious.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ fn main() -> ! {
4242

4343
info!("Setup Gpio");
4444
let gpioa = dp.GPIOA.split(&mut rcc);
45-
let pa0 = gpioa.pa0.into_analog();
4645

4746
info!("Setup Adc1");
4847
let mut delay = cp.SYST.delay(&rcc.clocks);
@@ -54,7 +53,7 @@ fn main() -> ! {
5453
adc.set_auto_delay(true);
5554
adc.set_continuous(Continuous::Continuous);
5655
adc.reset_sequence();
57-
adc.configure_channel(&pa0, Sequence::One, SampleTime::Cycles_640_5);
56+
adc.configure_channel(&gpioa.pa0, Sequence::One, SampleTime::Cycles_640_5);
5857
adc.configure_channel(&Vref, Sequence::Two, SampleTime::Cycles_640_5);
5958
adc.configure_channel(&Temperature, Sequence::Three, SampleTime::Cycles_640_5);
6059
let adc = adc.enable();

examples/adc-one-shot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ fn main() -> ! {
4343
info!("Setup Gpio");
4444

4545
let gpioa = dp.GPIOA.split(&mut rcc);
46-
let pa7 = gpioa.pa7.into_analog();
4746

4847
info!("Enter Loop");
4948

5049
loop {
5150
info!("Convert");
52-
let sample = adc.convert(&pa7, SampleTime::Cycles_640_5);
51+
let sample = adc.convert(&gpioa.pa7, SampleTime::Cycles_640_5);
5352
info!("sample to mv");
5453
let millivolts = adc.sample_to_millivolts(sample);
5554
info!("pa7: {}mV", millivolts);

examples/button.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use cortex_m_rt::entry;
1717

1818
type ButtonPin = gpio::PC13<Input>;
1919

20-
// Make LED pin globally available
20+
// Make LED and BUTTON pins globally available
2121
static G_BUTTON: Mutex<RefCell<Option<ButtonPin>>> = Mutex::new(RefCell::new(None));
2222
static G_LED_ON: AtomicBool = AtomicBool::new(true);
2323

examples/comp.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,47 @@
99
#![no_std]
1010

1111
mod utils;
12-
extern crate cortex_m_rt as rt;
1312

14-
use rt::entry;
13+
use cortex_m_rt::entry;
1514

1615
#[entry]
1716
fn main() -> ! {
18-
use hal::comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis};
19-
use hal::gpio::GpioExt;
20-
use hal::rcc::RccExt;
21-
use hal::stm32;
22-
use stm32g4xx_hal as hal;
23-
24-
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
17+
use stm32g4xx_hal::{
18+
comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis},
19+
gpio::{GpioExt, PushPull},
20+
pac,
21+
rcc::RccExt,
22+
};
23+
24+
let dp = pac::Peripherals::take().expect("cannot take peripherals");
2525
let mut rcc = dp.RCC.constrain();
2626

2727
let gpioa = dp.GPIOA.split(&mut rcc);
2828

2929
let (comp1, comp2, ..) = dp.COMP.split(&mut rcc);
3030

31-
let pa1 = gpioa.pa1.into_analog();
32-
let pa0 = gpioa.pa0.into_analog();
33-
let comp1 = comp1.comparator(pa1, pa0, Config::default(), &rcc.clocks);
31+
let comp1 = comp1.comparator(gpioa.pa1, gpioa.pa0, Config::default(), &rcc.clocks);
3432
let comp1 = comp1.enable();
3533

3634
// led1 pa1 will be updated manually when to match comp1 value
3735
let mut led1 = gpioa.pa5.into_push_pull_output();
3836

39-
let pa7 = gpioa.pa7.into_analog();
4037
let comp2 = comp2.comparator(
41-
pa7,
38+
gpioa.pa7,
4239
refint_input::VRefintM12,
4340
Config::default()
4441
.hysteresis(Hysteresis::None)
4542
.output_inverted(),
4643
&rcc.clocks,
4744
);
48-
let led2 = gpioa.pa12.into_push_pull_output();
45+
let led2 = gpioa.pa12;
4946
// Configure PA12 to the comparator's alternate function so it gets
5047
// changed directly by the comparator.
51-
comp2.output_pin(led2);
48+
comp2.output_pin::<PushPull>(led2);
5249
let _comp2 = comp2.enable().lock();
5350

5451
loop {
5552
// Read comp1 output and update led1 accordingly
56-
match comp1.output() {
57-
true => led1.set_high(),
58-
false => led1.set_low(),
59-
}
53+
led1.set_state(comp1.output().into());
6054
}
6155
}

0 commit comments

Comments
 (0)