Skip to content

Commit 3448d25

Browse files
author
Johannes Draaijer
committed
Fix #40, changes taken from #41
1 parent 3751fa1 commit 3448d25

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

examples/arp-smoltcp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ fn main() -> ! {
7777
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
7878
let (mut eth_dma, mut eth_mac) = stm32_eth::new(
7979
p.ETHERNET_MAC,
80+
p.ETHERNET_MMC,
8081
p.ETHERNET_DMA,
8182
&mut rx_ring[..],
8283
&mut tx_ring[..],

examples/arp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ fn main() -> ! {
7373
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
7474
let (mut eth_dma, mut eth_mac) = stm32_eth::new(
7575
p.ETHERNET_MAC,
76+
p.ETHERNET_MMC,
7677
p.ETHERNET_DMA,
7778
&mut rx_ring[..],
7879
&mut tx_ring[..],

examples/ip.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ fn main() -> ! {
8787
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
8888
let (mut eth_dma, _eth_mac) = stm32_eth::new(
8989
p.ETHERNET_MAC,
90+
p.ETHERNET_MMC,
9091
p.ETHERNET_DMA,
9192
&mut rx_ring[..],
9293
&mut tx_ring[..],

examples/pktgen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn main() -> ! {
7070
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
7171
let (mut eth_dma, mut eth_mac) = stm32_eth::new(
7272
p.ETHERNET_MAC,
73+
p.ETHERNET_MMC,
7374
p.ETHERNET_DMA,
7475
&mut rx_ring[..],
7576
&mut tx_ring[..],

src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use stm32f4xx_hal as hal;
1515
pub use stm32f4xx_hal::stm32;
1616

1717
use hal::rcc::Clocks;
18-
use stm32::{Interrupt, ETHERNET_DMA, ETHERNET_MAC, NVIC};
18+
use stm32::{Interrupt, ETHERNET_DMA, ETHERNET_MAC, ETHERNET_MMC, NVIC};
1919

2020
mod ring;
2121
#[cfg(feature = "smi")]
@@ -94,6 +94,7 @@ pub struct EthernetMAC {
9494
/// - HCLK must be at least 25 MHz.
9595
pub fn new<'rx, 'tx, REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1>(
9696
eth_mac: ETHERNET_MAC,
97+
eth_mmc: ETHERNET_MMC,
9798
eth_dma: ETHERNET_DMA,
9899
rx_buffer: &'rx mut [RxRingEntry],
99100
tx_buffer: &'tx mut [TxRingEntry],
@@ -110,7 +111,7 @@ where
110111
RXD1: RmiiRxD1 + AlternateVeryHighSpeed,
111112
{
112113
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) }
114115
}
115116

116117
/// Create and initialise the ethernet driver (without GPIO configuration and validation).
@@ -127,6 +128,7 @@ where
127128
/// - HCLK must be at least 25MHz.
128129
pub unsafe fn new_unchecked<'rx, 'tx>(
129130
eth_mac: ETHERNET_MAC,
131+
eth_mmc: ETHERNET_MMC,
130132
eth_dma: ETHERNET_DMA,
131133
rx_buffer: &'rx mut [RxRingEntry],
132134
tx_buffer: &'tx mut [TxRingEntry],
@@ -150,9 +152,7 @@ pub unsafe fn new_unchecked<'rx, 'tx>(
150152
while eth_dma.dmabmr.read().sr().bit_is_set() {}
151153

152154
// 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));
156156

157157
// Configuration Register
158158
eth_mac.maccr.modify(|_, w| {
@@ -213,8 +213,21 @@ pub unsafe fn new_unchecked<'rx, 'tx>(
213213
.osf()
214214
.set_bit()
215215
});
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+
216229
// bus mode register
217-
eth_dma.dmabmr.modify(|_, w| unsafe {
230+
eth_dma.dmabmr.modify(|_, w|
218231
// Address-aligned beats
219232
w.aab()
220233
.set_bit()
@@ -232,8 +245,7 @@ pub unsafe fn new_unchecked<'rx, 'tx>(
232245
.bits(0b01)
233246
// Use separate PBL
234247
.usp()
235-
.set_bit()
236-
});
248+
.set_bit());
237249

238250
let mut dma = EthernetDMA {
239251
eth_dma,

0 commit comments

Comments
 (0)