Skip to content

Commit 7864134

Browse files
author
Henrik Snöman
committed
Added h523/h533 gpio module
1 parent 2c5c1f5 commit 7864134

File tree

3 files changed

+189
-23
lines changed

3 files changed

+189
-23
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ rm0481 = [] # STM32H52x/6x/7x
2929

3030
# Different subfamily groups have different selections of identical peripherals
3131
h56x_h573 = ["gpio-h56x_h573"] # STM32H56x/STM32H573
32-
h523_h533 = ["gpio-h56x_h573"] # STM32H523/STM32H533
32+
h523_h533 = ["gpio-h523_h533"] # STM32H523/STM32H533
3333

3434
# Different subfamily groups have different GPIOs available and different alternate functions
3535
# available
3636
gpio-h503 = []
37+
gpio-h523_h533 = []
3738
gpio-h56x_h573 = []
3839

3940
# Some peripherals are only present on specific MCUs within a subfamily group

src/gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub struct PushPull;
167167
/// Analog mode (type state)
168168
pub struct Analog;
169169

170-
/// JTAG/SWD mote (type state)
170+
/// JTAG/SWD mode (type state)
171171
pub type Debugger = Alternate<0, PushPull>;
172172

173173
mod marker {

src/gpio/gpio_def.rs

Lines changed: 186 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,187 @@ mod h503 {
133133

134134
impl<const P: char> Gpio<P> {
135135
pub(crate) const fn ptr() -> *const crate::pac::gpioa::RegisterBlock {
136-
match P {
137-
'A' => crate::pac::GPIOA::ptr(),
138-
'B' => crate::pac::GPIOB::ptr() as _,
139-
'C' => crate::pac::GPIOC::ptr() as _,
140-
'D' => crate::pac::GPIOD::ptr() as _,
141-
'H' => crate::pac::GPIOH::ptr() as _,
142-
_ => panic!("Unknown GPIO port"),
136+
const {
137+
match P {
138+
'A' => crate::pac::GPIOA::ptr(),
139+
'B' => crate::pac::GPIOB::ptr() as _,
140+
'C' => crate::pac::GPIOC::ptr() as _,
141+
'D' => crate::pac::GPIOD::ptr() as _,
142+
'H' => crate::pac::GPIOH::ptr() as _,
143+
_ => panic!("Unknown GPIO port"),
144+
}
145+
}
146+
}
147+
}
148+
}
149+
150+
#[cfg(feature = "gpio-h523_h533")]
151+
pub use h523_h533::*;
152+
153+
#[cfg(feature = "gpio-h523_h533")]
154+
mod h523_h533 {
155+
use super::Gpio;
156+
157+
gpio!(GPIOA, gpioa, Gpioa, PA, 'A', PAn, [
158+
PA0: (pa0, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 14, 15]),
159+
PA1: (pa1, 1, [1, 2, 4, 5, 6, 7, 8, 9, 14, 15]),
160+
PA2: (pa2, 2, [1, 2, 3, 4, 5, 7, 15]),
161+
PA3: (pa3, 3, [1, 2, 3, 4, 5, 6, 7, 15]),
162+
PA4: (pa4, 4, [2, 3, 4, 5, 6, 7, 13, 15]),
163+
PA5: (pa5, 5, [1, 3, 5, 13, 14, 15]),
164+
PA6: (pa6, 6, [1, 2, 3, 5, 6, 13, 15]),
165+
PA7: (pa7, 7, [1, 2, 3, 5, 10, 13, 15]),
166+
PA8: (pa8, 8, [0, 1, 3, 4, 5, 6, 7, 9, 10, 12, 13, 15]),
167+
PA9: (pa9, 9, [1, 3, 4, 5, 7, 12, 13, 15]),
168+
PA10: (pa10, 10, [1, 3, 4, 6, 7, 9, 12, 13, 15]),
169+
PA11: (pa11, 11, [1, 3, 5, 6, 7, 9, 10, 15]),
170+
PA12: (pa12, 12, [1, 3, 5, 6, 7, 9, 10, 15]),
171+
PA13: (pa13, 13, [0, 15], crate::gpio::Debugger),
172+
PA14: (pa14, 14, [0, 15], crate::gpio::Debugger),
173+
PA15: (pa15, 15, [0, 1, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15], crate::gpio::Debugger),
174+
]);
175+
176+
gpio!(GPIOB, gpiob, Gpiob, PB, 'B', PBn, [
177+
PB0: (pb0, 0, [1, 2, 3, 5, 6, 7, 8, 15]),
178+
PB1: (pb1, 1, [1, 2, 3, 4, 5, 6, 7, 15]),
179+
PB2: (pb2, 2, [0, 3, 4, 5, 6, 7, 9, 10, 12, 15]),
180+
PB3: (pb3, 3, [0, 1, 3, 4, 5, 6, 8, 9, 10, 14, 15], crate::gpio::Debugger),
181+
PB4: (pb4, 4, [0, 2, 3, 4, 5, 6, 7, 9, 10, 13, 15], crate::gpio::Debugger),
182+
PB5: (pb5, 5, [2, 3, 4, 5, 6, 7, 9, 10, 13, 14, 15]),
183+
PB6: (pb6, 6, [2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15]),
184+
PB7: (pb7, 7, [2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 15]),
185+
PB8: (pb8, 8, [2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 15]),
186+
PB9: (pb9, 9, [2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 15]),
187+
PB10: (pb10, 10, [1, 2, 3, 4, 5, 7, 9, 15]),
188+
PB12: (pb12, 12, [1, 2, 3, 4, 5, 6, 7, 9, 14, 15]),
189+
PB13: (pb13, 13, [1, 2, 3, 4, 5, 7, 8, 9, 12, 14, 15]),
190+
PB14: (pb14, 14, [1, 2, 3, 4, 5, 7, 8, 15]),
191+
PB15: (pb15, 15, [0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 14, 15]),
192+
]);
193+
194+
gpio!(GPIOC, gpioc, Gpioc, PC, 'C', PCn, [
195+
PC0: (pc0, 0, [6, 7, 9, 10, 15]),
196+
PC1: (pc1, 1, [0, 5, 6, 10, 15]),
197+
PC2: (pc2, 2, [0, 2, 5, 6, 9, 15]),
198+
PC3: (pc3, 3, [0, 3, 5, 6, 9, 15]),
199+
PC4: (pc4, 4, [1, 3, 5, 7, 15]),
200+
PC5: (pc5, 5, [1, 4, 6, 10, 15]),
201+
PC6: (pc6, 6, [2, 3, 5, 7, 8, 9, 10, 11, 12, 13, 15]),
202+
PC7: (pc7, 7, [0, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 15]), //TRGIO (AF0) was missing from autogenerated code
203+
PC8: (pc8, 8, [0, 2, 3, 7, 8, 9, 10, 11, 12, 13, 15]),
204+
PC9: (pc9, 9, [0, 2, 3, 4, 5, 8, 9, 11, 12, 13, 15]),
205+
PC10: (pc10, 10, [3, 6, 7, 8, 9, 12, 13, 15]),
206+
PC11: (pc11, 11, [3, 6, 7, 8, 9, 12, 13, 15]),
207+
PC12: (pc12, 12, [0, 2, 3, 6, 7, 8, 12, 13, 15]),
208+
PC13: (pc13, 13, [15]),
209+
PC14: (pc14, 14, [15]),
210+
PC15: (pc15, 15, [15]),
211+
]);
212+
213+
gpio!(GPIOD, gpiod, Gpiod, PD, 'D', PDn, [
214+
PD0: (pd0, 0, [3, 8, 9, 12, 15]),
215+
PD1: (pd1, 1, [8, 9, 12, 15]),
216+
PD2: (pd2, 2, [0, 2, 4, 8, 12, 13, 15]),
217+
PD3: (pd3, 3, [5, 7, 12, 13, 15]),
218+
PD4: (pd4, 4, [7, 10, 12, 15]),
219+
PD5: (pd5, 5, [1, 5, 7, 9, 10, 12, 15]),
220+
PD6: (pd6, 6, [3, 4, 5, 7, 10, 11, 12, 13, 15]),
221+
PD7: (pd7, 7, [3, 4, 5, 6, 7, 10, 11, 12, 15]),
222+
PD8: (pd8, 8, [7, 12, 15]),
223+
PD9: (pd9, 9, [7, 9, 12, 15]),
224+
PD10: (pd10, 10, [3, 7, 12, 15]),
225+
PD11: (pd11, 11, [3, 7, 8, 9, 12, 15]),
226+
PD12: (pd12, 12, [1, 2, 3, 5, 7, 8, 9, 12, 13, 15]),
227+
PD13: (pd13, 13, [1, 2, 3, 5, 9, 12, 13, 15]),
228+
PD14: (pd14, 14, [2, 12, 15]),
229+
PD15: (pd15, 15, [2, 12, 15]),
230+
]);
231+
232+
gpio!(GPIOE, gpioe, Gpioe, PE, 'E', PEn, [
233+
PE0: (pe0, 0, [1, 2, 3, 4, 6, 9, 12, 13, 15]),
234+
PE2: (pe2, 2, [0, 1, 5, 9, 12, 13, 15]),
235+
PE3: (pe3, 3, [0, 4, 12, 15]),
236+
PE4: (pe4, 4, [0, 4, 5, 12, 13, 15]),
237+
PE5: (pe5, 5, [0, 4, 5, 12, 13, 15]),
238+
PE6: (pe6, 6, [0, 1, 4, 5, 12, 13, 15]),
239+
PE7: (pe7, 7, [1, 10, 12, 15]),
240+
PE8: (pe8, 8, [1, 10, 12, 15]),
241+
PE9: (pe9, 9, [1, 10, 12, 15]),
242+
PE10: (pe10, 10, [1, 10, 12, 15]),
243+
PE11: (pe11, 11, [1, 4, 5, 6, 12, 15]),
244+
PE12: (pe12, 12, [1, 5, 12, 15]),
245+
PE13: (pe13, 13, [1, 5, 12, 15]),
246+
PE14: (pe14, 14, [1, 5, 12, 15]),
247+
PE15: (pe15, 15, [1, 3, 12, 15]),
248+
]);
249+
250+
gpio!(GPIOF, gpiof, Gpiof, PF, 'F', PFn, [
251+
PF0: (pf0, 0, [3, 4, 12, 15]),
252+
PF1: (pf1, 1, [3, 4, 12, 15]),
253+
PF2: (pf2, 2, [4, 12, 15]),
254+
PF3: (pf3, 3, [12, 15]),
255+
PF4: (pf4, 4, [12, 15]),
256+
PF5: (pf5, 5, [5, 12, 15]),
257+
PF6: (pf6, 6, [10, 15]),
258+
PF7: (pf7, 7, [10, 15]),
259+
PF8: (pf8, 8, [10, 15]),
260+
PF9: (pf9, 9, [10, 15]),
261+
PF10: (pf10, 10, [4, 9, 13, 15]),
262+
PF11: (pf11, 11, [9, 13, 15]),
263+
PF12: (pf12, 12, [12, 15]),
264+
PF13: (pf13, 13, [12, 15]),
265+
PF14: (pf14, 14, [12, 15]),
266+
PF15: (pf15, 15, [5, 12, 15]),
267+
]);
268+
269+
gpio!(GPIOG, gpiog, Gpiog, PG, 'G', PGn, [
270+
PG0: (pg0, 0, [12, 15]),
271+
PG1: (pg1, 1, [7, 12, 15]),
272+
PG2: (pg2, 2, [3, 12, 15]),
273+
PG3: (pg3, 3, [3, 12, 15]),
274+
PG4: (pg4, 4, [1, 12, 15]),
275+
PG5: (pg5, 5, [1, 12, 15]),
276+
PG6: (pg6, 6, [3, 5, 10, 11, 12, 13, 15]),
277+
PG7: (pg7, 7, [3, 7, 11, 12, 13, 15]),
278+
PG8: (pg8, 8, [3, 5, 7, 15]),
279+
PG9: (pg9, 9, [5, 7, 9, 11, 12, 13, 15]),
280+
PG10: (pg10, 10, [5, 11, 12, 13, 15]),
281+
PG11: (pg11, 11, [1, 5, 10, 13, 15]),
282+
PG12: (pg12, 12, [1, 4, 7, 10, 12, 13, 15]),
283+
PG13: (pg13, 13, [0, 1, 7, 12, 15]),
284+
PG14: (pg14, 14, [0, 1, 4, 7, 9, 12, 15]),
285+
PG15: (pg15, 15, [5, 7, 13, 15]),
286+
]);
287+
288+
gpio!(GPIOH, gpioh, Gpioh, PH, 'H', PHn, [
289+
PH0: (ph0, 0, [15]),
290+
PH1: (ph1, 1, [15]),
291+
]);
292+
293+
impl<const P: char> Gpio<P> {
294+
pub(crate) const fn ptr() -> *const crate::pac::gpioa::RegisterBlock {
295+
const {
296+
match P {
297+
'A' => crate::pac::GPIOA::ptr(),
298+
'B' => crate::pac::GPIOB::ptr() as _,
299+
'C' => crate::pac::GPIOC::ptr() as _,
300+
'D' => crate::pac::GPIOD::ptr() as _,
301+
'E' => crate::pac::GPIOE::ptr() as _,
302+
'F' => crate::pac::GPIOF::ptr() as _,
303+
'G' => crate::pac::GPIOG::ptr() as _,
304+
'H' => crate::pac::GPIOH::ptr() as _,
305+
_ => panic!("Unknown GPIO port"),
306+
}
143307
}
144308
}
145309
}
146310
}
147311

148312
#[cfg(feature = "gpio-h56x_h573")]
149-
pub use h523_h533_h56x_h573::*;
313+
pub use h56x_h573::*;
150314

151315
#[cfg(feature = "gpio-h56x_h573")]
152-
mod h523_h533_h56x_h573 {
316+
mod h56x_h573 {
153317
use super::Gpio;
154318

155319
gpio!(GPIOA, gpioa, Gpioa, PA, 'A', PAn, [
@@ -321,18 +485,19 @@ mod h523_h533_h56x_h573 {
321485

322486
impl<const P: char> Gpio<P> {
323487
pub(crate) const fn ptr() -> *const crate::pac::gpioa::RegisterBlock {
324-
match P {
325-
'A' => crate::pac::GPIOA::ptr(),
326-
'B' => crate::pac::GPIOB::ptr() as _,
327-
'C' => crate::pac::GPIOC::ptr() as _,
328-
'D' => crate::pac::GPIOD::ptr() as _,
329-
'E' => crate::pac::GPIOE::ptr() as _,
330-
'F' => crate::pac::GPIOF::ptr() as _,
331-
'G' => crate::pac::GPIOG::ptr() as _,
332-
'H' => crate::pac::GPIOH::ptr() as _,
333-
#[cfg(feature = "h56x_h573")]
334-
'I' => crate::pac::GPIOI::ptr() as _,
335-
_ => panic!("Unknown GPIO port"),
488+
const {
489+
match P {
490+
'A' => crate::pac::GPIOA::ptr(),
491+
'B' => crate::pac::GPIOB::ptr() as _,
492+
'C' => crate::pac::GPIOC::ptr() as _,
493+
'D' => crate::pac::GPIOD::ptr() as _,
494+
'E' => crate::pac::GPIOE::ptr() as _,
495+
'F' => crate::pac::GPIOF::ptr() as _,
496+
'G' => crate::pac::GPIOG::ptr() as _,
497+
'H' => crate::pac::GPIOH::ptr() as _,
498+
'I' => crate::pac::GPIOI::ptr() as _,
499+
_ => panic!("Unknown GPIO port"),
500+
}
336501
}
337502
}
338503
}

0 commit comments

Comments
 (0)