@@ -11,6 +11,20 @@ use crate::{
11
11
mod miim;
12
12
pub use miim:: * ;
13
13
14
+ /// Speeds at which this MAC can be configured
15
+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
16
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
17
+ pub enum Speed {
18
+ /// 10Base-T half duplex
19
+ HalfDuplexBase10T ,
20
+ /// 10Base-T full duplex
21
+ FullDuplexBase10T ,
22
+ /// 100Base-Tx half duplex
23
+ HalfDuplexBase100Tx ,
24
+ /// 100Base-Tx full duplex
25
+ FullDuplexBase100Tx ,
26
+ }
27
+
14
28
mod consts {
15
29
/* For HCLK 60-100 MHz */
16
30
pub const ETH_MACMIIAR_CR_HCLK_DIV_42 : u8 = 0 ;
@@ -54,6 +68,7 @@ impl EthernetMAC {
54
68
// this function.
55
69
#[ allow( unused) ] eth_dma : & EthernetDMA ,
56
70
clocks : Clocks ,
71
+ initial_speed : Speed ,
57
72
) -> Result < Self , WrongClock > {
58
73
let clock_frequency = clocks. hclk ( ) . to_Hz ( ) ;
59
74
@@ -132,7 +147,11 @@ impl EthernetMAC {
132
147
. mmctimr
133
148
. modify ( |r, w| unsafe { w. bits ( r. bits ( ) | ( 1 << 21 ) ) } ) ;
134
149
135
- Ok ( Self { eth_mac } )
150
+ let mut me = Self { eth_mac } ;
151
+
152
+ me. set_speed ( initial_speed) ;
153
+
154
+ Ok ( me)
136
155
}
137
156
138
157
/// Borrow access to the MAC's SMI.
@@ -166,6 +185,31 @@ impl EthernetMAC {
166
185
mdc,
167
186
}
168
187
}
188
+
189
+ /// Set the Ethernet Speed at which the MAC communicates
190
+ ///
191
+ /// Note that this does _not_ affect the PHY in any way. To
192
+ /// configure the PHY, use [`EthernetMACWithMii`] (see: [`Self::with_mii`])
193
+ /// or [`Stm32Mii`] (see: [`Self::mii`])
194
+ pub fn set_speed ( & mut self , speed : Speed ) {
195
+ self . eth_mac . maccr . modify ( |_, w| match speed {
196
+ Speed :: HalfDuplexBase10T => w. fes ( ) . clear_bit ( ) . dm ( ) . clear_bit ( ) ,
197
+ Speed :: FullDuplexBase10T => w. fes ( ) . clear_bit ( ) . dm ( ) . set_bit ( ) ,
198
+ Speed :: HalfDuplexBase100Tx => w. fes ( ) . set_bit ( ) . dm ( ) . clear_bit ( ) ,
199
+ Speed :: FullDuplexBase100Tx => w. fes ( ) . set_bit ( ) . dm ( ) . set_bit ( ) ,
200
+ } ) ;
201
+ }
202
+
203
+ /// Get the Ethernet Speed at which the MAC communicates
204
+ pub fn get_speed ( & self ) -> Speed {
205
+ let cr = self . eth_mac . maccr . read ( ) ;
206
+ match ( cr. fes ( ) . bit_is_set ( ) , cr. dm ( ) . bit_is_set ( ) ) {
207
+ ( false , false ) => Speed :: HalfDuplexBase10T ,
208
+ ( false , true ) => Speed :: FullDuplexBase10T ,
209
+ ( true , false ) => Speed :: HalfDuplexBase100Tx ,
210
+ ( true , true ) => Speed :: FullDuplexBase100Tx ,
211
+ }
212
+ }
169
213
}
170
214
171
215
/// Ethernet media access control (MAC) with owned MII
0 commit comments