Skip to content

Commit 2354f43

Browse files
Merge pull request #66 from stm32-rs/newer-ptp-support
Newer ptp support
2 parents e03d2cc + 061496a commit 2354f43

25 files changed

+1692
-248
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
toolchain:
3232
- stable
3333
features:
34-
- stm32f745
34+
- stm32f745,ptp
3535
runs-on: ubuntu-20.04
3636
steps:
3737
- name: Checkout
@@ -90,6 +90,33 @@ jobs:
9090
run: |
9191
cargo build --release --target=${{ matrix.target }} --features ${{ matrix.features }}
9292
93+
build-ptp:
94+
name: build-no-ptp
95+
runs-on: ubuntu-20.04
96+
strategy:
97+
matrix:
98+
target:
99+
- x86_64-unknown-linux-gnu
100+
toolchain:
101+
- stable
102+
features:
103+
- stm32f107
104+
- stm32f407
105+
- stm32f745
106+
steps:
107+
- name: Checkout
108+
uses: actions/checkout@v3
109+
110+
- name: Install Rust ${{ matrix.toolchain }} with target (${{ matrix.target }})
111+
run: |
112+
rustup set profile minimal
113+
rustup override set ${{ matrix.toolchain }}
114+
rustup target add ${{ matrix.target }}
115+
116+
- name: cargo build
117+
run: |
118+
cargo build --release --target=${{ matrix.target }} --features ${{ matrix.features }} --no-default-features
119+
93120
# Examples
94121
examples:
95122
name: examples

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
* General
33
* Remove the `smi` feature and always enable miim/smi. Use `ieee802_3_miim` for SMI access
44
* Split MAC and DMA setup into their own separate modules
5+
* Move all DMA related files into modules under `dma`
56
* Update stm32f1xx-hal and stm32f4xx-hal to their latests version as of 15-12-2022.
67
* 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))
78
* Fix [#57](https://github.com/stm32-rs/stm32-eth/issues/57). ([#58](https://github.com/stm32-rs/stm32-eth/pull/58))
9+
* Add support for the PTP peripheral
810
* CI
911
* Test compilability of examples more extensively
1012
* Move away from actions-rs
@@ -16,6 +18,7 @@
1618
* Remove arp-smoltcp example
1719
* Add `rtic-echo` example
1820
* Use a more simple `memory.x` that works for all supported MCUs
21+
* Add `rtic-timestamp` example
1922

2023
## [0.3.0](https://github.com/stm32-rs/stm32-eth/tree/v0.3.0)
2124

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ stm32f7xx-hal = { version = "0.7.0", optional = true }
2525
stm32f4xx-hal = { version = "0.14", optional = true }
2626
stm32f4 = { version = "0.15", optional = true }
2727
stm32f1xx-hal = { version = "0.10", optional = true }
28-
ieee802_3_miim = "0.7"
28+
ieee802_3_miim = "0.8"
2929
cortex-m = "0.7"
3030
log = { version = "0.4", optional = true }
3131
defmt = { version = "0.3", optional = true }
3232

3333
[dependencies.smoltcp]
34-
version = "0.8"
34+
version = "0.8.2"
3535
default-features = false
3636
optional = true
3737

3838
[features]
39-
default = [ "defmt" ]
39+
default = [ "defmt", "ptp" ]
4040
device-selected = []
4141
fence = []
42+
ptp = [ ]
4243

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

@@ -89,6 +90,10 @@ required-features = [ "defmt" ]
8990
name = "rtic-echo"
9091
required-features = [ "defmt" , "smoltcp-phy" ]
9192

93+
[[example]]
94+
name = "rtic-timestamp"
95+
required-features = [ "defmt", "ptp" ]
96+
9297
[profile.release]
9398
debug = 2
9499
lto = true

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use stm32_eth::{
2929
hal::gpio::GpioExt,
3030
hal::rcc::RccExt,
3131
stm32::Peripherals,
32-
RingEntry,
32+
dma::{RxRingEntry, TxRingEntry},
3333
EthPins,
3434
};
3535
use fugit::RateExtU32;
@@ -56,12 +56,18 @@ fn main() {
5656
rx_d1: gpioc.pc5,
5757
};
5858
59-
let mut rx_ring: [RingEntry<_>; 16] = Default::default();
60-
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
61-
let (mut eth_dma, _eth_mac) = stm32_eth::new(
62-
p.ETHERNET_MAC,
63-
p.ETHERNET_MMC,
64-
p.ETHERNET_DMA,
59+
let mut rx_ring: [RxRingEntry; 16] = Default::default();
60+
let mut tx_ring: [TxRingEntry; 8] = Default::default();
61+
62+
let parts = stm32_eth::PartsIn {
63+
mac: p.ETHERNET_MAC,
64+
mmc: p.ETHERNET_MMC,
65+
dma: p.ETHERNET_DMA,
66+
ptp: p.ETHERNET_PTP,
67+
};
68+
69+
let stm32_eth::Parts { dma: mut eth_dma, mac: _, ptp: _ } = stm32_eth::new(
70+
parts,
6571
&mut rx_ring[..],
6672
&mut tx_ring[..],
6773
clocks,
@@ -70,12 +76,12 @@ fn main() {
7076
.unwrap();
7177
eth_dma.enable_interrupt();
7278
73-
if let Ok(pkt) = eth_dma.recv_next() {
79+
if let Ok(pkt) = eth_dma.recv_next(None) {
7480
// handle received pkt
7581
}
7682
7783
let size = 42;
78-
eth_dma.send(size, |buf| {
84+
eth_dma.send(size, None, |buf| {
7985
// write up to `size` bytes into buf before it is being sent
8086
}).expect("send");
8187
}

examples/arp.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ use cortex_m::interrupt::Mutex;
1818
use stm32_eth::{
1919
mac::{phy::BarePhy, Phy},
2020
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
21+
Parts,
2122
};
2223

2324
pub mod common;
2425

25-
use stm32_eth::{RingEntry, TxError};
26+
use stm32_eth::dma::{RxRingEntry, TxError, TxRingEntry};
2627

2728
const PHY_ADDR: u8 = 0;
2829

@@ -42,24 +43,27 @@ fn main() -> ! {
4243

4344
let (eth_pins, mdio, mdc) = common::setup_pins(gpio);
4445

45-
let mut rx_ring: [RingEntry<_>; 2] = Default::default();
46-
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
46+
let mut rx_ring: [RxRingEntry; 2] = Default::default();
47+
let mut tx_ring: [TxRingEntry; 2] = Default::default();
4748

48-
let (mut eth_dma, eth_mac) = stm32_eth::new(
49-
ethernet.mac,
50-
ethernet.mmc,
51-
ethernet.dma,
49+
let Parts {
50+
mut dma,
51+
mac,
52+
#[cfg(feature = "ptp")]
53+
ptp: _,
54+
} = stm32_eth::new(
55+
ethernet,
5256
&mut rx_ring[..],
5357
&mut tx_ring[..],
5458
clocks,
5559
eth_pins,
5660
)
5761
.unwrap();
58-
eth_dma.enable_interrupt();
62+
dma.enable_interrupt();
5963

6064
let mut last_link_up = false;
6165

62-
let mut bare_phy = BarePhy::new(eth_mac.with_mii(mdio, mdc), PHY_ADDR, Default::default());
66+
let mut bare_phy = BarePhy::new(mac.with_mii(mdio, mdc), PHY_ADDR, Default::default());
6367

6468
loop {
6569
let link_up = bare_phy.phy_link_up();
@@ -88,7 +92,7 @@ fn main() -> ! {
8892
const TARGET_MAC: [u8; 6] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
8993
const TARGET_IP: [u8; 4] = [0x0A, 0x00, 0x00, 0x02]; // 10.0.0.2
9094

91-
let r = eth_dma.send(SIZE, |buf| {
95+
let r = dma.send(SIZE, None, |buf| {
9296
buf[0..6].copy_from_slice(&DST_MAC);
9397
buf[6..12].copy_from_slice(&SRC_MAC);
9498
buf[12..14].copy_from_slice(&ETH_TYPE);

examples/common.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,26 @@
66
77
use stm32_eth::{
88
hal::{gpio::GpioExt, rcc::Clocks},
9-
stm32::{ETHERNET_DMA, ETHERNET_MAC, ETHERNET_MMC},
9+
PartsIn,
1010
};
1111

1212
pub use pins::{setup_pins, Gpio};
1313

1414
use fugit::RateExtU32;
1515
use stm32_eth::hal::rcc::RccExt;
1616

17-
pub struct EthernetPeripherals {
18-
pub dma: ETHERNET_DMA,
19-
pub mac: ETHERNET_MAC,
20-
pub mmc: ETHERNET_MMC,
21-
}
22-
2317
/// Setup the clocks and return clocks and a GPIO struct that
2418
/// can be used to set up all of the pins.
2519
///
2620
/// This configures HCLK to be at least 25 MHz, which is the minimum required
2721
/// for ethernet operation to be valid.
28-
pub fn setup_peripherals(p: stm32_eth::stm32::Peripherals) -> (Clocks, Gpio, EthernetPeripherals) {
29-
let ethernet = EthernetPeripherals {
22+
pub fn setup_peripherals(p: stm32_eth::stm32::Peripherals) -> (Clocks, Gpio, PartsIn) {
23+
let ethernet = PartsIn {
3024
dma: p.ETHERNET_DMA,
3125
mac: p.ETHERNET_MAC,
3226
mmc: p.ETHERNET_MMC,
27+
#[cfg(feature = "ptp")]
28+
ptp: p.ETHERNET_PTP,
3329
};
3430

3531
#[cfg(any(feature = "stm32f7xx-hal", feature = "stm32f4xx-hal"))]
@@ -316,15 +312,19 @@ impl<M: Miim> EthernetPhy<M> {
316312
///
317313
/// Returns an error if the PHY does not support the extended register
318314
/// set, or if the PHY's identifier does not correspond to a known PHY.
319-
pub fn from_miim(miim: M, phy_addr: u8) -> Result<Self, ()> {
315+
pub fn from_miim(miim: M, phy_addr: u8) -> Result<Self, M> {
320316
let mut bare = BarePhy::new(miim, phy_addr, Pause::NoPause);
321-
let phy_ident = bare.phy_ident().ok_or(())?;
317+
let phy_ident = if let Some(id) = bare.phy_ident() {
318+
id.raw_u32()
319+
} else {
320+
return Err(bare.release());
321+
};
322322
let miim = bare.release();
323323
match phy_ident & 0xFFFFFFF0 {
324324
0x0007C0F0 => Ok(Self::LAN8720A(LAN8720A::new(miim, phy_addr))),
325325
0x0007C130 => Ok(Self::LAN8742A(LAN8742A::new(miim, phy_addr))),
326326
0x00221560 => Ok(Self::KSZ8081R(KSZ8081R::new(miim, phy_addr))),
327-
_ => Err(()),
327+
_ => Err(miim),
328328
}
329329
}
330330

@@ -356,4 +356,13 @@ impl<M: Miim> EthernetPhy<M> {
356356
EthernetPhy::KSZ8081R(phy) => phy.link_speed(),
357357
}
358358
}
359+
360+
#[allow(dead_code)]
361+
pub fn release(self) -> M {
362+
match self {
363+
EthernetPhy::LAN8720A(phy) => phy.release(),
364+
EthernetPhy::LAN8742A(phy) => phy.release(),
365+
EthernetPhy::KSZ8081R(phy) => phy.release(),
366+
}
367+
}
359368
}

examples/ip.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};
2222

2323
pub mod common;
2424

25-
use stm32_eth::RingEntry;
25+
use stm32_eth::{
26+
dma::{RxRingEntry, TxRingEntry},
27+
Parts,
28+
};
2629

2730
const SRC_MAC: [u8; 6] = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
2831

@@ -42,19 +45,22 @@ fn main() -> ! {
4245

4346
let (eth_pins, _mdio, _mdc) = common::setup_pins(gpio);
4447

45-
let mut rx_ring: [RingEntry<_>; 2] = Default::default();
46-
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
47-
let (mut eth_dma, _eth_mac) = stm32_eth::new(
48-
ethernet.mac,
49-
ethernet.mmc,
50-
ethernet.dma,
48+
let mut rx_ring: [RxRingEntry; 2] = Default::default();
49+
let mut tx_ring: [TxRingEntry; 2] = Default::default();
50+
let Parts {
51+
mut dma,
52+
mac: _,
53+
#[cfg(feature = "ptp")]
54+
ptp: _,
55+
} = stm32_eth::new(
56+
ethernet,
5157
&mut rx_ring[..],
5258
&mut tx_ring[..],
5359
clocks,
5460
eth_pins,
5561
)
5662
.unwrap();
57-
eth_dma.enable_interrupt();
63+
dma.enable_interrupt();
5864

5965
let local_addr = Ipv4Address::new(10, 0, 0, 1);
6066
let ip_addr = IpCidr::new(IpAddress::from(local_addr), 24);
@@ -64,7 +70,7 @@ fn main() -> ! {
6470
let ethernet_addr = EthernetAddress(SRC_MAC);
6571

6672
let mut sockets: [_; 1] = Default::default();
67-
let mut iface = InterfaceBuilder::new(&mut eth_dma, &mut sockets[..])
73+
let mut iface = InterfaceBuilder::new(&mut dma, &mut sockets[..])
6874
.hardware_addr(ethernet_addr.into())
6975
.ip_addrs(&mut ip_addrs[..])
7076
.neighbor_cache(neighbor_cache)

0 commit comments

Comments
 (0)