Skip to content

Commit 17b5d76

Browse files
author
Johannes Draaijer
committed
Fix startup order of pins, DMA and MAC
Make `new` functions pub(crate)
1 parent abc1a7f commit 17b5d76

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

src/dma.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
rx::{RxPacket, RxRing},
55
stm32::{Interrupt, ETHERNET_DMA},
66
tx::TxRing,
7-
EthernetMAC, RxError, RxRingEntry, TxError, TxRingEntry,
7+
RxError, RxRingEntry, TxError, TxRingEntry,
88
};
99

1010
/// Ethernet DMA.
@@ -21,12 +21,7 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
2121
/// - Make sure that the buffers reside in a memory region that is
2222
/// accessible by the peripheral. Core-Coupled Memory (CCM) is
2323
/// usually not accessible.
24-
//
25-
// NOTE: eth_mac is unused, but required for initialization as
26-
// owning an [`EthernetMAC`] requires that all of it's checks
27-
// (GPIO, clock speed) have passed.
28-
pub fn new(
29-
#[allow(unused)] eth_mac: &EthernetMAC,
24+
pub(crate) fn new(
3025
eth_dma: ETHERNET_DMA,
3126
rx_buffer: &'rx mut [RxRingEntry],
3227
tx_buffer: &'tx mut [TxRingEntry],
@@ -166,6 +161,8 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
166161

167162
/// A summary of the reasons for the interrupt
168163
/// that occured
164+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
165+
#[derive(Debug, Clone, Copy)]
169166
pub struct InterruptReasonSummary {
170167
pub is_rx: bool,
171168
pub is_tx: bool,

src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ where
8787
RXD0: RmiiRxD0 + AlternateVeryHighSpeed,
8888
RXD1: RmiiRxD1 + AlternateVeryHighSpeed,
8989
{
90-
let mac = EthernetMAC::new(eth_mac, eth_mmc, clocks, pins)?;
90+
pins.setup_pins();
91+
setup::setup();
9192

92-
let dma = EthernetDMA::new(&mac, eth_dma, rx_buffer, tx_buffer);
93+
let dma = EthernetDMA::new(eth_dma, rx_buffer, tx_buffer);
94+
let mac = EthernetMAC::new(eth_mac, eth_mmc, clocks)?;
9395

9496
Ok((dma, mac))
9597
}
@@ -133,9 +135,11 @@ where
133135
MDIO: mac::MdioPin,
134136
MDC: mac::MdcPin,
135137
{
136-
let mac = EthernetMAC::new(eth_mac, eth_mmc, clocks, pins)?.with_mii(mdio, mdc);
138+
pins.setup_pins();
139+
setup::setup();
137140

138-
let dma = EthernetDMA::new(&mac, eth_dma, rx_buffer, tx_buffer);
141+
let dma = EthernetDMA::new(eth_dma, rx_buffer, tx_buffer);
142+
let mac = EthernetMAC::new(eth_mac, eth_mmc, clocks)?.with_mii(mdio, mdc);
139143

140144
Ok((dma, mac))
141145
}

src/mac/mod.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use core::ops::Deref;
22

33
use crate::{
44
hal::rcc::Clocks,
5-
setup::*,
65
stm32::{ETHERNET_MAC, ETHERNET_MMC},
7-
EthPins,
86
};
97

108
mod miim;
@@ -45,25 +43,11 @@ impl EthernetMAC {
4543
///
4644
/// Additionally, an optional `impl` of the [`ieee802_3_miim::Miim`] trait is available
4745
/// with the `ieee802_3_miim` feature (enabled by default), for PHY communication.
48-
pub fn new<REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1>(
46+
pub(crate) fn new(
4947
eth_mac: ETHERNET_MAC,
5048
eth_mmc: ETHERNET_MMC,
5149
clocks: Clocks,
52-
pins: EthPins<REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1>,
53-
) -> Result<Self, WrongClock>
54-
where
55-
REFCLK: RmiiRefClk + AlternateVeryHighSpeed,
56-
CRS: RmiiCrsDv + AlternateVeryHighSpeed,
57-
TXEN: RmiiTxEN + AlternateVeryHighSpeed,
58-
TXD0: RmiiTxD0 + AlternateVeryHighSpeed,
59-
TXD1: RmiiTxD1 + AlternateVeryHighSpeed,
60-
RXD0: RmiiRxD0 + AlternateVeryHighSpeed,
61-
RXD1: RmiiRxD1 + AlternateVeryHighSpeed,
62-
{
63-
pins.setup_pins();
64-
65-
setup();
66-
50+
) -> Result<Self, WrongClock> {
6751
let clock_frequency = clocks.hclk().to_Hz();
6852

6953
let clock_range = match clock_frequency {

0 commit comments

Comments
 (0)