Skip to content

Commit 74eb751

Browse files
Merge pull request #58 from stm32-rs/issue_57
Fix #57
2 parents f061a36 + 6ab260b commit 74eb751

File tree

9 files changed

+383
-25
lines changed

9 files changed

+383
-25
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Split MAC and DMA setup into their own separate modules
55
* Update stm32f1xx-hal and stm32f4xx-hal to their latests version as of 15-12-2022.
66
* Allow for configuration of MAC speed. ([#53](https://github.com/stm32-rs/stm32-eth/pull/53), fixes [#24](https://github.com/stm32-rs/stm32-eth/pull/24))
7+
* Fix [#57](https://github.com/stm32-rs/stm32-eth/issues/57). ([#58](https://github.com/stm32-rs/stm32-eth/pull/58))
78
* CI
89
* Test compilability of examples more extensively
910
* Move away from actions-rs

Cargo.toml

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ volatile-register = "0.2"
2323
aligned = "0.4"
2424
stm32f7xx-hal = { version = "0.7.0", optional = true }
2525
stm32f4xx-hal = { version = "0.14", optional = true }
26+
stm32f4 = { version = "0.15", optional = true }
2627
stm32f1xx-hal = { version = "0.10", optional = true }
2728
ieee802_3_miim = "0.7"
2829
cortex-m = "0.7"
@@ -41,14 +42,14 @@ fence = []
4142

4243
stm32f107 = ["stm32f1xx-hal/stm32f107", "device-selected"]
4344

44-
stm32f407 = ["stm32f4xx-hal/stm32f407", "device-selected"]
45-
stm32f417 = ["stm32f4xx-hal/stm32f417", "device-selected"]
46-
stm32f427 = ["stm32f4xx-hal/stm32f427", "device-selected"]
47-
stm32f429 = ["stm32f4xx-hal/stm32f429", "device-selected"]
48-
stm32f437 = ["stm32f4xx-hal/stm32f437", "device-selected"]
49-
stm32f439 = ["stm32f4xx-hal/stm32f439", "device-selected"]
50-
stm32f469 = ["stm32f4xx-hal/stm32f469", "device-selected"]
51-
stm32f479 = ["stm32f4xx-hal/stm32f479", "device-selected"]
45+
stm32f407 = ["stm32f4xx-hal/stm32f407", "stm32f4", "device-selected"]
46+
stm32f417 = ["stm32f4xx-hal/stm32f417", "stm32f4", "device-selected"]
47+
stm32f427 = ["stm32f4xx-hal/stm32f427", "stm32f4", "device-selected"]
48+
stm32f429 = ["stm32f4xx-hal/stm32f429", "stm32f4", "device-selected"]
49+
stm32f437 = ["stm32f4xx-hal/stm32f437", "stm32f4", "device-selected"]
50+
stm32f439 = ["stm32f4xx-hal/stm32f439", "stm32f4", "device-selected"]
51+
stm32f469 = ["stm32f4xx-hal/stm32f469", "stm32f4", "device-selected"]
52+
stm32f479 = ["stm32f4xx-hal/stm32f479", "stm32f4", "device-selected"]
5253

5354
stm32f745 = ["stm32f7xx-hal/stm32f745", "device-selected", "fence"]
5455
stm32f746 = ["stm32f7xx-hal/stm32f746", "device-selected", "fence"]

src/dma.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use core::borrow::Borrow;
2+
13
use cortex_m::peripheral::NVIC;
24

35
use crate::{
6+
peripherals::{ETHERNET_DMA, ETHERNET_MAC},
47
rx::{RxPacket, RxRing},
5-
stm32::{Interrupt, ETHERNET_DMA, ETHERNET_MAC},
8+
stm32::Interrupt,
69
tx::TxRing,
710
RxError, RxRingEntry, TxError, TxRingEntry,
811
};
@@ -128,8 +131,9 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
128131

129132
/// Calls [`eth_interrupt_handler()`](fn.eth_interrupt_handler.html)
130133
pub fn interrupt_handler(&self) -> InterruptReasonSummary {
131-
let status = eth_interrupt_handler(&self.eth_dma);
132-
eth_interrupt_handler(&self.eth_dma);
134+
let eth_dma = &self.eth_dma;
135+
let status = eth_interrupt_handler_impl(eth_dma);
136+
eth_interrupt_handler_impl(eth_dma);
133137
status
134138
}
135139

@@ -181,7 +185,12 @@ pub struct InterruptReasonSummary {
181185
///
182186
/// * Via the [`EthernetDMA`](struct.EthernetDMA.html) driver instance that your interrupt handler has access to.
183187
/// * By unsafely getting `Peripherals`.
184-
pub fn eth_interrupt_handler(eth_dma: &ETHERNET_DMA) -> InterruptReasonSummary {
188+
pub fn eth_interrupt_handler(eth_dma: &crate::hal::pac::ETHERNET_DMA) -> InterruptReasonSummary {
189+
let eth_dma: &ETHERNET_DMA = eth_dma.borrow();
190+
eth_interrupt_handler_impl(eth_dma)
191+
}
192+
193+
fn eth_interrupt_handler_impl(eth_dma: &ETHERNET_DMA) -> InterruptReasonSummary {
185194
let status = eth_dma.dmasr.read();
186195

187196
let status = InterruptReasonSummary {

src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ use setup::{
6767
AlternateVeryHighSpeed, RmiiCrsDv, RmiiRefClk, RmiiRxD0, RmiiRxD1, RmiiTxD0, RmiiTxD1, RmiiTxEN,
6868
};
6969

70+
#[cfg(feature = "device-selected")]
71+
mod peripherals;
72+
7073
#[cfg(all(feature = "smoltcp-phy", feature = "device-selected"))]
7174
pub use smoltcp;
7275
#[cfg(all(feature = "smoltcp-phy", feature = "device-selected"))]
@@ -123,11 +126,13 @@ where
123126
// Set up the clocks and reset the MAC periperhal
124127
setup::setup();
125128

129+
let eth_mac = eth_mac.into();
130+
126131
// Congfigure and start up the ethernet DMA.
127132
// Note: this _must_ happen before configuring the MAC.
128133
// It's not entirely clear why, but no interrupts are
129134
// generated if the order is reversed.
130-
let dma = EthernetDMA::new(eth_dma, &eth_mac, rx_buffer, tx_buffer);
135+
let dma = EthernetDMA::new(eth_dma.into(), &eth_mac, rx_buffer, tx_buffer);
131136

132137
// Configure the ethernet MAC
133138
let mac = EthernetMAC::new(eth_mac, eth_mmc, &dma, clocks, Speed::FullDuplexBase100Tx)?;
@@ -184,11 +189,13 @@ where
184189
// Set up the clocks and reset the MAC periperhal
185190
setup::setup();
186191

192+
let eth_mac = eth_mac.into();
193+
187194
// Congfigure and start up the ethernet DMA.
188195
// Note: this _must_ happen before configuring the MAC.
189196
// It's not entirely clear why, but no interrupts are
190197
// generated if the order is reversed.
191-
let dma = EthernetDMA::new(eth_dma, &eth_mac, rx_buffer, tx_buffer);
198+
let dma = EthernetDMA::new(eth_dma.into(), &eth_mac, rx_buffer, tx_buffer);
192199

193200
// Configure the ethernet MAC
194201
let mac = EthernetMAC::new(eth_mac, eth_mmc, &dma, clocks, Speed::FullDuplexBase100Tx)?

src/mac/miim.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ pub use ieee802_3_miim::Miim;
22

33
pub use ieee802_3_miim::*;
44

5-
use crate::{
6-
stm32::{ethernet_mac::MACMIIAR, ETHERNET_MAC},
7-
EthernetMAC,
8-
};
5+
use crate::{peripherals::ETHERNET_MAC, stm32::ethernet_mac::MACMIIAR, EthernetMAC};
96

107
/// MDIO pin types.
118
///

src/mac/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
33
use core::ops::{Deref, DerefMut};
44

5-
use crate::{
6-
hal::rcc::Clocks,
7-
stm32::{ETHERNET_MAC, ETHERNET_MMC},
8-
EthernetDMA,
9-
};
5+
use crate::{hal::rcc::Clocks, peripherals::ETHERNET_MAC, stm32::ETHERNET_MMC, EthernetDMA};
106

117
mod miim;
128
pub use miim::*;

0 commit comments

Comments
 (0)