Skip to content

Commit 1730143

Browse files
datdenkiknietJohannes Cornelis Draaijer
authored andcommitted
We introduce an additional abstraction layer that, for STM32F4 parts, introduces a delay before writing to a register. This is to prevent the same register from being written to twice within 4 cycles of REF_CLK. It assumes worst-case setups (180 MHz clock, and 25 MHz REF_CLK), which comes out to a minimum of 30 cycles of delay. On F1 and F7 parts, the existing ETHERNET_DMA and ETHERNET_MAC are simply re-exported without any modifications
1 parent 4ff1932 commit 1730143

File tree

9 files changed

+386
-29
lines changed

9 files changed

+386
-29
lines changed

Cargo.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ features = ["smoltcp-phy", "smoltcp/socket-raw", "stm32f429"]
2222
volatile-register = "0.2"
2323
aligned = "0.4"
2424
stm32f7xx-hal = { version = "0.7.0", optional = true }
25-
stm32f4xx-hal = { version = "0.13", optional = true }
25+
stm32f4xx-hal = { version = "0.14", optional = true }
26+
stm32f4 = { version = "0.15", optional = true }
2627
stm32f1xx-hal = { git = "https://github.com/datdenkikniet/stm32f1xx-hal.git", branch = "gd32f107", optional = true }
2728
# stm32f1xx-hal = { path = "../stm32f1xx-hal", optional = true }
2829
ieee802_3_miim = "0.7"
@@ -44,14 +45,14 @@ fence = []
4445

4546
stm32f107 = ["stm32f1xx-hal/stm32f107", "device-selected"]
4647

47-
stm32f407 = ["stm32f4xx-hal/stm32f407", "device-selected"]
48-
stm32f417 = ["stm32f4xx-hal/stm32f417", "device-selected"]
49-
stm32f427 = ["stm32f4xx-hal/stm32f427", "device-selected"]
50-
stm32f429 = ["stm32f4xx-hal/stm32f429", "device-selected"]
51-
stm32f437 = ["stm32f4xx-hal/stm32f437", "device-selected"]
52-
stm32f439 = ["stm32f4xx-hal/stm32f439", "device-selected"]
53-
stm32f469 = ["stm32f4xx-hal/stm32f469", "device-selected"]
54-
stm32f479 = ["stm32f4xx-hal/stm32f479", "device-selected"]
48+
stm32f407 = ["stm32f4xx-hal/stm32f407", "stm32f4", "device-selected"]
49+
stm32f417 = ["stm32f4xx-hal/stm32f417", "stm32f4", "device-selected"]
50+
stm32f427 = ["stm32f4xx-hal/stm32f427", "stm32f4", "device-selected"]
51+
stm32f429 = ["stm32f4xx-hal/stm32f429", "stm32f4", "device-selected"]
52+
stm32f437 = ["stm32f4xx-hal/stm32f437", "stm32f4", "device-selected"]
53+
stm32f439 = ["stm32f4xx-hal/stm32f439", "stm32f4", "device-selected"]
54+
stm32f469 = ["stm32f4xx-hal/stm32f469", "stm32f4", "device-selected"]
55+
stm32f479 = ["stm32f4xx-hal/stm32f479", "stm32f4", "device-selected"]
5556

5657
stm32f745 = ["stm32f7xx-hal/stm32f745", "device-selected", "fence"]
5758
stm32f746 = ["stm32f7xx-hal/stm32f746", "device-selected", "fence"]

src/dma.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
use core::borrow::Borrow;
2+
13
use cortex_m::peripheral::NVIC;
24

35
use crate::{
46
packet_id::IntoPacketId,
7+
peripherals::{ETHERNET_DMA, ETHERNET_MAC},
58
ptp::Timestamp,
69
rx::{RxPacket, RxRing},
7-
stm32::{Interrupt, ETHERNET_DMA, ETHERNET_MAC},
10+
stm32::Interrupt,
811
tx::TxRing,
912
PacketId, RxError, RxRingEntry, TxError, TxRingEntry,
1013
};
@@ -141,8 +144,9 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
141144

142145
/// Calls [`eth_interrupt_handler()`](fn.eth_interrupt_handler.html)
143146
pub fn interrupt_handler(&mut self) -> InterruptReasonSummary {
144-
let status = eth_interrupt_handler(&self.eth_dma);
145-
eth_interrupt_handler(&self.eth_dma);
147+
let eth_dma = &self.eth_dma;
148+
let status = eth_interrupt_handler_impl(eth_dma);
149+
eth_interrupt_handler_impl(eth_dma);
146150
self.collect_timestamps();
147151
status
148152
}
@@ -222,7 +226,12 @@ pub struct InterruptReasonSummary {
222226
///
223227
/// * Via the [`EthernetDMA`](struct.EthernetDMA.html) driver instance that your interrupt handler has access to.
224228
/// * By unsafely getting `Peripherals`.
225-
pub fn eth_interrupt_handler(eth_dma: &ETHERNET_DMA) -> InterruptReasonSummary {
229+
pub fn eth_interrupt_handler(eth_dma: &crate::hal::pac::ETHERNET_DMA) -> InterruptReasonSummary {
230+
let eth_dma: &ETHERNET_DMA = eth_dma.borrow();
231+
eth_interrupt_handler_impl(eth_dma)
232+
}
233+
234+
fn eth_interrupt_handler_impl(eth_dma: &ETHERNET_DMA) -> InterruptReasonSummary {
226235
let status = eth_dma.dmasr.read();
227236

228237
let status = InterruptReasonSummary {

src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ use ptp::setup_ptp;
7878
#[cfg(feature = "device-selected")]
7979
pub use ptp::Timestamp;
8080

81+
#[cfg(feature = "device-selected")]
82+
mod peripherals;
83+
8184
#[cfg(all(feature = "smoltcp-phy", feature = "device-selected"))]
8285
pub use smoltcp;
8386
#[cfg(all(feature = "smoltcp-phy", feature = "device-selected"))]
@@ -133,13 +136,15 @@ where
133136
// Set up the clocks and reset the MAC periperhal
134137
setup::setup();
135138

139+
let eth_mac = eth_mac.into();
140+
136141
// Congfigure and start up the ethernet DMA.
137142
// Note: this _must_ happen before configuring the MAC.
138143
// It's not entirely clear why, but no interrupts are
139144
// generated if the order is reversed.
140-
let dma = EthernetDMA::new(eth_dma, &eth_mac, rx_buffer, tx_buffer);
145+
let dma = EthernetDMA::new(eth_dma.into(), &eth_mac, rx_buffer, tx_buffer);
141146

142-
setup_ptp(&eth_mac, eth_ptp, clocks);
147+
setup_ptp(&eth_mac, eth_ptp.into(), clocks);
143148

144149
let speed = initial_speed.unwrap_or(Speed::FullDuplexBase100Tx);
145150

@@ -197,13 +202,15 @@ where
197202
// Set up the clocks and reset the MAC periperhal
198203
setup::setup();
199204

205+
let eth_mac = eth_mac.into();
206+
200207
// Congfigure and start up the ethernet DMA.
201208
// Note: this _must_ happen before configuring the MAC.
202209
// It's not entirely clear why, but no interrupts are
203210
// generated if the order is reversed.
204-
let dma = EthernetDMA::new(eth_dma, &eth_mac, rx_buffer, tx_buffer);
211+
let dma = EthernetDMA::new(eth_dma.into(), &eth_mac, rx_buffer, tx_buffer);
205212

206-
setup_ptp(&eth_mac, eth_ptp, clocks);
213+
setup_ptp(&eth_mac, eth_ptp.into(), clocks);
207214

208215
let speed = initial_speed.unwrap_or(Speed::FullDuplexBase100Tx);
209216

src/mac/miim.rs

Lines changed: 1 addition & 4 deletions
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

Lines changed: 1 addition & 5 deletions
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)