4
4
//!
5
5
//! Note that this module isn't an example by itself.
6
6
7
- use stm32_eth:: {
8
- hal:: { gpio:: GpioExt , rcc:: Clocks } ,
9
- PartsIn ,
10
- } ;
7
+ use stm32_eth:: { hal:: gpio:: GpioExt , PartsIn } ;
8
+
9
+ #[ cfg( feature = "f-series" ) ]
10
+ use stm32_eth:: hal:: rcc:: Clocks ;
11
+
12
+ #[ cfg( feature = "stm32h7xx-hal" ) ]
13
+ use stm32_eth:: hal:: rcc:: CoreClocks as Clocks ;
11
14
12
15
pub use pins:: { setup_pins, Gpio } ;
13
16
@@ -23,6 +26,9 @@ pub fn setup_peripherals(p: stm32_eth::stm32::Peripherals) -> (Clocks, Gpio, Par
23
26
let ethernet = PartsIn {
24
27
dma : p. ETHERNET_DMA ,
25
28
mac : p. ETHERNET_MAC ,
29
+ #[ cfg( feature = "stm32h7xx-hal" ) ]
30
+ mtl : p. ETHERNET_MTL ,
31
+ #[ cfg( feature = "f-series" ) ]
26
32
mmc : p. ETHERNET_MMC ,
27
33
#[ cfg( feature = "ptp" ) ]
28
34
ptp : p. ETHERNET_PTP ,
@@ -99,6 +105,40 @@ pub fn setup_peripherals(p: stm32_eth::stm32::Peripherals) -> (Clocks, Gpio, Par
99
105
100
106
( clocks, gpio, ethernet)
101
107
}
108
+
109
+ #[ cfg( feature = "stm32h7xx-hal" ) ]
110
+ {
111
+ use stm32_eth:: hal:: pwr:: PwrExt ;
112
+
113
+ let rcc = p. RCC . constrain ( ) ;
114
+ let pwr = p. PWR . constrain ( ) ;
115
+
116
+ let syscfg = p. SYSCFG ;
117
+
118
+ let pwrcfg = pwr. vos0 ( & syscfg) . freeze ( ) ;
119
+
120
+ let rcc = rcc. hclk ( 240 . MHz ( ) ) ;
121
+
122
+ let rcc = if cfg ! ( hse = "bypass" ) {
123
+ rcc. bypass_hse ( ) . use_hse ( 8 . MHz ( ) )
124
+ } else if cfg ! ( hse = "oscillator" ) {
125
+ rcc. use_hse ( 8 . MHz ( ) )
126
+ } else {
127
+ rcc
128
+ } ;
129
+
130
+ let ccdr = rcc. freeze ( pwrcfg, & syscfg) ;
131
+ let clocks = ccdr. clocks ;
132
+
133
+ let gpio = Gpio {
134
+ gpioa : p. GPIOA . split ( ccdr. peripheral . GPIOA ) ,
135
+ gpiob : p. GPIOB . split ( ccdr. peripheral . GPIOB ) ,
136
+ gpioc : p. GPIOC . split ( ccdr. peripheral . GPIOC ) ,
137
+ gpiog : p. GPIOG . split ( ccdr. peripheral . GPIOG ) ,
138
+ } ;
139
+
140
+ ( clocks, gpio, ethernet)
141
+ }
102
142
}
103
143
104
144
pub use pins:: * ;
@@ -280,6 +320,75 @@ mod pins {
280
320
}
281
321
}
282
322
323
+ #[ cfg( feature = "stm32h7xx-hal" ) ]
324
+ mod pins {
325
+ use stm32_eth:: {
326
+ hal:: gpio:: { Input , PushPull , * } ,
327
+ EthPins ,
328
+ } ;
329
+
330
+ pub struct Gpio {
331
+ pub gpioa : gpioa:: Parts ,
332
+ pub gpiob : gpiob:: Parts ,
333
+ pub gpioc : gpioc:: Parts ,
334
+ pub gpiog : gpiog:: Parts ,
335
+ }
336
+
337
+ pub type RefClk = PA1 < Input > ;
338
+ pub type Crs = PA7 < Input > ;
339
+ pub type TxEn = PG11 < Input > ;
340
+ pub type TxD0 = PG13 < Input > ;
341
+ pub type TxD1 = PB13 < Input > ;
342
+ pub type RxD0 = PC4 < Input > ;
343
+ pub type RxD1 = PC5 < Input > ;
344
+
345
+ pub type Pps = PB5 < Output < PushPull > > ;
346
+
347
+ pub type Mdio = ( ) ;
348
+ pub type Mdc = ( ) ;
349
+
350
+ pub fn setup_pins (
351
+ gpio : Gpio ,
352
+ ) -> (
353
+ EthPins < RefClk , Crs , TxEn , TxD0 , TxD1 , RxD0 , RxD1 > ,
354
+ Mdio ,
355
+ Mdc ,
356
+ Pps ,
357
+ ) {
358
+ let Gpio {
359
+ gpioa,
360
+ gpiob,
361
+ gpioc,
362
+ gpiog,
363
+ } = gpio;
364
+
365
+ let ref_clk = gpioa. pa1 . into_input ( ) ;
366
+ let crs = gpioa. pa7 . into_input ( ) ;
367
+ let rx_d0 = gpioc. pc4 . into_input ( ) ;
368
+ let rx_d1 = gpioc. pc5 . into_input ( ) ;
369
+ let tx_en = gpiog. pg11 . into_input ( ) ;
370
+ let tx_d0 = gpiog. pg13 . into_input ( ) ;
371
+ let tx_d1 = gpiob. pb13 . into_input ( ) ;
372
+
373
+ let mdc = ( ) ;
374
+ let mdio = ( ) ;
375
+
376
+ let pps = gpiob. pb5 . into_push_pull_output ( ) ;
377
+
378
+ let pins = EthPins {
379
+ ref_clk,
380
+ crs,
381
+ tx_en,
382
+ tx_d0,
383
+ tx_d1,
384
+ rx_d0,
385
+ rx_d1,
386
+ } ;
387
+
388
+ ( pins, mdio, mdc, pps)
389
+ }
390
+ }
391
+
283
392
use ieee802_3_miim:: {
284
393
phy:: {
285
394
lan87xxa:: { LAN8720A , LAN8742A } ,
0 commit comments