@@ -15,7 +15,7 @@ pub use stm32f4xx_hal as hal;
15
15
pub use stm32f4xx_hal:: stm32;
16
16
17
17
use hal:: rcc:: Clocks ;
18
- use stm32:: { Interrupt , ETHERNET_DMA , ETHERNET_MAC , NVIC } ;
18
+ use stm32:: { Interrupt , ETHERNET_DMA , ETHERNET_MAC , ETHERNET_MMC , NVIC } ;
19
19
20
20
mod ring;
21
21
#[ cfg( feature = "smi" ) ]
@@ -94,6 +94,7 @@ pub struct EthernetMAC {
94
94
/// - HCLK must be at least 25 MHz.
95
95
pub fn new < ' rx , ' tx , REFCLK , CRS , TXEN , TXD0 , TXD1 , RXD0 , RXD1 > (
96
96
eth_mac : ETHERNET_MAC ,
97
+ eth_mmc : ETHERNET_MMC ,
97
98
eth_dma : ETHERNET_DMA ,
98
99
rx_buffer : & ' rx mut [ RxRingEntry ] ,
99
100
tx_buffer : & ' tx mut [ TxRingEntry ] ,
@@ -110,7 +111,7 @@ where
110
111
RXD1 : RmiiRxD1 + AlternateVeryHighSpeed ,
111
112
{
112
113
pins. setup_pins ( ) ;
113
- unsafe { new_unchecked ( eth_mac, eth_dma, rx_buffer, tx_buffer, clocks) }
114
+ unsafe { new_unchecked ( eth_mac, eth_mmc , eth_dma, rx_buffer, tx_buffer, clocks) }
114
115
}
115
116
116
117
/// Create and initialise the ethernet driver (without GPIO configuration and validation).
@@ -127,6 +128,7 @@ where
127
128
/// - HCLK must be at least 25MHz.
128
129
pub unsafe fn new_unchecked < ' rx , ' tx > (
129
130
eth_mac : ETHERNET_MAC ,
131
+ eth_mmc : ETHERNET_MMC ,
130
132
eth_dma : ETHERNET_DMA ,
131
133
rx_buffer : & ' rx mut [ RxRingEntry ] ,
132
134
tx_buffer : & ' tx mut [ TxRingEntry ] ,
@@ -150,9 +152,7 @@ pub unsafe fn new_unchecked<'rx, 'tx>(
150
152
while eth_dma. dmabmr . read ( ) . sr ( ) . bit_is_set ( ) { }
151
153
152
154
// set clock range in MAC MII address register
153
- eth_mac
154
- . macmiiar
155
- . modify ( |_, w| unsafe { w. cr ( ) . bits ( clock_range) } ) ;
155
+ eth_mac. macmiiar . modify ( |_, w| w. cr ( ) . bits ( clock_range) ) ;
156
156
157
157
// Configuration Register
158
158
eth_mac. maccr . modify ( |_, w| {
@@ -213,8 +213,21 @@ pub unsafe fn new_unchecked<'rx, 'tx>(
213
213
. osf ( )
214
214
. set_bit ( )
215
215
} ) ;
216
+
217
+ // disable all MMC RX interrupts
218
+ eth_mmc
219
+ . mmcrimr
220
+ . write ( |w| w. rgufm ( ) . set_bit ( ) . rfaem ( ) . set_bit ( ) . rfcem ( ) . set_bit ( ) ) ;
221
+ // disable all MMC TX interrupts
222
+ eth_mmc
223
+ . mmctimr
224
+ . write ( |w| w. tgfm ( ) . set_bit ( ) . tgfmscm ( ) . set_bit ( ) . tgfscm ( ) . set_bit ( ) ) ;
225
+ // fix incorrect TGFM bit position until https://github.com/stm32-rs/stm32-rs/pull/689
226
+ // is released and used by HALs.
227
+ eth_mmc. mmctimr . modify ( |r, w| w. bits ( r. bits ( ) | ( 1 << 21 ) ) ) ;
228
+
216
229
// bus mode register
217
- eth_dma. dmabmr . modify ( |_, w| unsafe {
230
+ eth_dma. dmabmr . modify ( |_, w|
218
231
// Address-aligned beats
219
232
w. aab ( )
220
233
. set_bit ( )
@@ -232,8 +245,7 @@ pub unsafe fn new_unchecked<'rx, 'tx>(
232
245
. bits ( 0b01 )
233
246
// Use separate PBL
234
247
. usp ( )
235
- . set_bit ( )
236
- } ) ;
248
+ . set_bit ( ) ) ;
237
249
238
250
let mut dma = EthernetDMA {
239
251
eth_dma,
0 commit comments