Skip to content

Commit e9828f4

Browse files
committed
Make f series compile again
1 parent a2e3061 commit e9828f4

File tree

10 files changed

+102
-115
lines changed

10 files changed

+102
-115
lines changed

src/dma/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ use cortex_m::peripheral::NVIC;
66

77
use crate::{peripherals::ETHERNET_DMA, stm32::Interrupt};
88

9-
#[cfg(feature = "f-series")]
10-
type ETHERNET_MTL = ();
11-
12-
#[cfg(feature = "stm32h7xx-hal")]
13-
use crate::stm32::ETHERNET_MTL;
14-
159
#[cfg(feature = "smoltcp-phy")]
1610
mod smoltcp_phy;
1711
#[cfg(feature = "smoltcp-phy")]
@@ -77,7 +71,7 @@ pub struct EthernetDMA<'rx, 'tx> {
7771
pub(crate) struct DmaParts {
7872
pub eth_dma: ETHERNET_DMA,
7973
#[cfg(feature = "stm32h7xx-hal")]
80-
pub eth_mtl: ETHERNET_MTL,
74+
pub eth_mtl: crate::stm32::ETHERNET_MTL,
8175
}
8276

8377
impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {

src/dma/rx/f_series_desc.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ impl RxDescriptor {
5959
}
6060

6161
pub(super) fn setup(&mut self, buffer: &mut [u8]) {
62-
self.set_buffer(buffer);
63-
self.set_owned();
62+
self.set_owned(buffer);
6463
}
6564

6665
/// Is owned by the DMA engine?
@@ -71,7 +70,9 @@ impl RxDescriptor {
7170
/// Pass ownership to the DMA engine
7271
///
7372
/// Overrides old timestamp data
74-
pub(super) fn set_owned(&mut self) {
73+
pub(super) fn set_owned(&mut self, buffer: &mut [u8]) {
74+
self.set_buffer(buffer);
75+
7576
// "Preceding reads and writes cannot be moved past subsequent writes."
7677
#[cfg(feature = "fence")]
7778
atomic::fence(Ordering::Release);
@@ -125,11 +126,15 @@ impl RxDescriptor {
125126
((self.inner_raw.read(0) >> RXDESC_0_FL_SHIFT) & RXDESC_0_FL_MASK) as usize
126127
}
127128

128-
pub(super) fn take_received(&mut self, packet_id: Option<PacketId>) -> Result<(), RxError> {
129+
pub(super) fn take_received(
130+
&mut self,
131+
packet_id: Option<PacketId>,
132+
buffer: &mut [u8],
133+
) -> Result<(), RxError> {
129134
if self.is_owned() {
130135
Err(RxError::WouldBlock)
131136
} else if self.has_error() {
132-
self.set_owned();
137+
self.set_owned(buffer);
133138
Err(RxError::DmaError)
134139
} else if self.is_first() && self.is_last() {
135140
// "Subsequent reads and writes cannot be moved ahead of preceding reads."
@@ -143,22 +148,22 @@ impl RxDescriptor {
143148

144149
Ok(())
145150
} else {
146-
self.set_owned();
151+
self.set_owned(buffer);
147152
Err(RxError::Truncated)
148153
}
149154
}
150155

151156
pub(super) fn set_end_of_ring(&mut self) {
152157
unsafe { self.inner_raw.modify(1, |w| w | RXDESC_1_RER) }
153158
}
159+
}
154160

161+
#[cfg(feature = "ptp")]
162+
impl RxDescriptor {
155163
pub(super) fn packet_id(&self) -> Option<&PacketId> {
156164
self.packet_id.as_ref()
157165
}
158-
}
159166

160-
#[cfg(feature = "ptp")]
161-
impl RxDescriptor {
162167
/// Get PTP timestamps if available
163168
pub(super) fn read_timestamp(&self) -> Option<Timestamp> {
164169
#[cfg(not(feature = "stm32f1xx-hal"))]

src/dma/rx/h_desc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ impl RxDescriptor {
136136
}
137137

138138
pub(super) fn setup(&mut self, buffer: &[u8]) {
139-
self.set_owned(buffer.as_ptr());
139+
self.set_owned(buffer);
140140
}
141141

142142
/// Pass ownership to the DMA engine
143-
pub(super) fn set_owned(&mut self, buffer: *const u8) {
143+
pub(super) fn set_owned(&mut self, buffer: &[u8]) {
144+
let buffer = buffer.as_ptr();
144145
self.set_buffer(buffer);
145146

146147
// "Preceding reads and writes cannot be moved past subsequent writes."
@@ -205,7 +206,7 @@ impl RxDescriptor {
205206

206207
Ok(())
207208
} else {
208-
self.set_owned(buffer.as_ptr());
209+
self.set_owned(buffer);
209210
Err(RxError::Truncated)
210211
}
211212
}

src/dma/rx/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'a> core::ops::DerefMut for RxPacket<'a> {
280280

281281
impl<'a> Drop for RxPacket<'a> {
282282
fn drop(&mut self) {
283-
self.entry.set_owned(self.buffer.as_ptr());
283+
self.entry.set_owned(self.buffer);
284284
}
285285
}
286286

src/dma/tx/f_series_desc.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ impl TxDescriptor {
6767

6868
pub(super) fn setup(&mut self, buffer: &mut [u8]) {
6969
self.set_buffer(buffer);
70-
unsafe {
71-
self.inner_raw.write(
72-
0,
73-
TXDESC_0_CIC0 | TXDESC_0_CIC1 | TXDESC_0_FS | TXDESC_0_LS | TXDESC_0_IC,
74-
);
75-
}
7670
}
7771

7872
#[allow(unused)]
@@ -112,7 +106,17 @@ impl TxDescriptor {
112106
atomic::fence(Ordering::Release);
113107
atomic::compiler_fence(Ordering::Release);
114108

115-
unsafe { self.inner_raw.modify(0, |w| w | extra_flags | TXDESC_0_OWN) };
109+
unsafe {
110+
self.inner_raw.modify(0, |w| {
111+
w | extra_flags
112+
| TXDESC_0_OWN
113+
| TXDESC_0_CIC0
114+
| TXDESC_0_CIC1
115+
| TXDESC_0_FS
116+
| TXDESC_0_LS
117+
| TXDESC_0_IC
118+
})
119+
};
116120

117121
// Used to flush the store buffer as fast as possible to make the buffer available for the
118122
// DMA.
@@ -144,14 +148,14 @@ impl TxDescriptor {
144148
pub(super) fn set_end_of_ring(&mut self) {
145149
unsafe { self.inner_raw.modify(0, |w| w | TXDESC_0_TER) };
146150
}
151+
}
147152

153+
#[cfg(feature = "ptp")]
154+
impl TxDescriptor {
148155
pub(super) fn packet_id(&self) -> Option<&PacketId> {
149156
self.packet_id.as_ref()
150157
}
151-
}
152158

153-
#[cfg(feature = "ptp")]
154-
impl TxDescriptor {
155159
fn read_timestamp(&mut self) -> Option<Timestamp> {
156160
let tdes0 = self.inner_raw.read(0);
157161

src/dma/tx/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) struct TxRing<'data, STATE> {
4141
impl<'data, STATE> TxRing<'data, STATE> {
4242
pub fn running_state(&self, eth_dma: &ETHERNET_DMA) -> RunningState {
4343
#[cfg(feature = "f-series")]
44-
let tx_status = eth_dma.dmasr().read().tps().bits();
44+
let tx_status = eth_dma.dmasr.read().tps().bits();
4545

4646
#[cfg(feature = "stm32h7xx-hal")]
4747
let tx_status = eth_dma.dmadsr.read().tps0().bits();
@@ -97,7 +97,7 @@ impl<'data> TxRing<'data, NotRunning> {
9797

9898
#[cfg(feature = "f-series")]
9999
// Set end of ring register
100-
self.ring.last_descriptor().set_end_of_ring();
100+
self.ring.last_descriptor_mut().set_end_of_ring();
101101

102102
let ring_ptr = self.ring.descriptors_start_address();
103103

@@ -235,20 +235,20 @@ impl<'data> TxRing<'data, Running> {
235235
impl<'data> TxRing<'data, Running> {
236236
pub(crate) fn collect_timestamps(&mut self) {
237237
for descriptor in self.ring.descriptors_mut() {
238-
f_descriptor.attach_timestamp();
238+
descriptor.attach_timestamp();
239239
}
240240
}
241241

242242
pub(crate) fn get_timestamp_for_id(&self, id: PacketId) -> Result<Timestamp, TimestampError> {
243243
let descriptor = if let Some(descriptor) =
244244
self.ring.descriptors().find(|d| d.packet_id() == Some(&id))
245245
{
246-
f_descriptor
246+
descriptor
247247
} else {
248248
return Err(TimestampError::IdNotFound);
249249
};
250250

251-
f_descriptor
251+
descriptor
252252
.timestamp()
253253
.map(|t| *t)
254254
.ok_or(TimestampError::NotYetTimestamped)

src/lib.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,32 +108,27 @@ where
108108
// Set up the clocks and reset the MAC periperhal
109109
setup::setup();
110110

111+
let dma_parts = DmaParts {
112+
eth_dma: parts.dma.into(),
113+
#[cfg(feature = "stm32h7xx-hal")]
114+
eth_mtl: parts.mtl,
115+
};
116+
117+
let mac_parts = MacParts {
118+
eth_mac: parts.mac.into(),
119+
#[cfg(feature = "f-series")]
120+
eth_mmc: parts.mmc.into(),
121+
};
122+
111123
// Congfigure and start up the ethernet DMA.
112-
let dma = EthernetDMA::new(
113-
DmaParts {
114-
eth_dma: parts.dma,
115-
#[cfg(feature = "stm32h7xx-hal")]
116-
eth_mtl: parts.mtl,
117-
},
118-
rx_buffer,
119-
tx_buffer,
120-
);
124+
let dma = EthernetDMA::new(dma_parts, rx_buffer, tx_buffer);
121125

122126
// Configure the ethernet PTP
123127
#[cfg(feature = "ptp")]
124128
let ptp = EthernetPTP::new(parts.ptp.into(), clocks, &dma);
125129

126130
// Configure the ethernet MAC
127-
let mac = EthernetMAC::new(
128-
MacParts {
129-
eth_mac: parts.mac.into(),
130-
#[cfg(feature = "f-series")]
131-
eth_mmc: parts.mmc.into(),
132-
},
133-
clocks,
134-
Speed::FullDuplexBase100Tx,
135-
&dma,
136-
)?;
131+
let mac = EthernetMAC::new(mac_parts, clocks, Speed::FullDuplexBase100Tx, &dma)?;
137132

138133
let parts = Parts {
139134
mac,
@@ -192,23 +187,25 @@ where
192187
// Set up the clocks and reset the MAC periperhal
193188
setup::setup();
194189

195-
let eth_mac = parts.mac.into();
190+
let dma_parts = DmaParts {
191+
eth_dma: parts.dma.into(),
192+
};
193+
194+
let mac_parts = MacParts {
195+
eth_mac: parts.mac.into(),
196+
eth_mmc: parts.mmc.into(),
197+
};
196198

197199
// Congfigure and start up the ethernet DMA.
198-
let dma = EthernetDMA::new(parts.dma.into(), rx_buffer, tx_buffer);
200+
let dma = EthernetDMA::new(dma_parts, rx_buffer, tx_buffer);
199201

200202
// Configure the ethernet PTP
201203
#[cfg(feature = "ptp")]
202204
let ptp = EthernetPTP::new(parts.ptp.into(), clocks, &dma);
203205

204206
// Configure the ethernet MAC
205-
let mac = EthernetMAC::new(
206-
MacParts { eth_mac, eth_mmc },
207-
clocks,
208-
Speed::FullDuplexBase100Tx,
209-
&dma,
210-
)?
211-
.with_mii(mdio, mdc);
207+
let mac =
208+
EthernetMAC::new(mac_parts, clocks, Speed::FullDuplexBase100Tx, &dma)?.with_mii(mdio, mdc);
212209

213210
let parts = Parts {
214211
mac,

src/mac/miim.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
pub use ieee802_3_miim::Miim;
2-
32
pub use ieee802_3_miim::*;
43

4+
use core::ops::{Deref, DerefMut};
5+
56
use crate::{peripherals::ETHERNET_MAC, stm32::ethernet_mac::MACMIIAR};
67

78
use super::EthernetMAC;
@@ -157,7 +158,7 @@ where
157158
MDIO: MdioPin,
158159
MDC: MdcPin,
159160
{
160-
pub(crate) eth_mac: EthernetMAC,
161+
eth_mac: EthernetMAC,
161162
mdio: MDIO,
162163
mdc: MDC,
163164
}
@@ -226,7 +227,7 @@ where
226227
}
227228
}
228229

229-
impl<MDIO, MDC> miim::Miim for EthernetMACWithMii<MDIO, MDC>
230+
impl<MDIO, MDC> Miim for EthernetMACWithMii<MDIO, MDC>
230231
where
231232
MDIO: MdioPin,
232233
MDC: MdcPin,

0 commit comments

Comments
 (0)