Skip to content

Commit 13e2991

Browse files
Merge pull request #106 from stm32-rs/not-only-ref
Implement smoltcp::Device for owned EthernetDMA
2 parents 72acc60 + 693ec09 commit 13e2991

7 files changed

Lines changed: 39 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Unreleased
22

3+
## [0.8.2](https://github.com/stm32-rs/stm32-eth/tree/v0.8.2)
4+
* Implement `smoltcp::phy::Device` for non-borrowed `EthernetDMA` ([#106])
5+
6+
[#106]: https://github.com/stm32-rs/stm32-eth/pull/106
7+
38
## [0.8.1](https://github.com/stm32-rs/stm32-eth/tree/v0.8.1)
49
* Fixed bug in `smoltcp::phy::Device` implementation that caused panics on RX errors ([#102])
510

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name = "stm32-eth"
44
description = "Embedded Rust Ethernet driver for the STM32 MCU series"
55
license = "Apache-2.0"
66
authors = ["Astro <astro@spaceboyz.net>", "Johannes Draaijer <jcdra1@gmail.com>"]
7-
version = "0.8.1"
7+
version = "0.8.2"
88
keywords = ["ethernet", "eth", "stm32", "stm32f4", "stm32f7"]
99
repository = "https://github.com/stm32-rs/stm32-eth"
1010
documentation = "https://docs.rs/stm32-eth/"

examples/ip.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn main() -> ! {
6666
let ethernet_addr = EthernetAddress(SRC_MAC);
6767

6868
let config = Config::new(ethernet_addr.into());
69-
let mut iface = Interface::new(config, &mut &mut dma, Instant::ZERO);
69+
let mut iface = Interface::new(config, &mut dma, Instant::ZERO);
7070

7171
iface.update_ip_addrs(|addr| {
7272
addr.push(IpCidr::Ipv4(Ipv4Cidr::new(IP_ADDRESS, 24))).ok();
@@ -90,11 +90,7 @@ fn main() -> ! {
9090
*eth_pending = false;
9191
});
9292

93-
iface.poll(
94-
Instant::from_millis(time as i64),
95-
&mut &mut dma,
96-
&mut sockets,
97-
);
93+
iface.poll(Instant::from_millis(time as i64), &mut dma, &mut sockets);
9894

9995
let socket = sockets.get_mut::<TcpSocket>(server_handle);
10096

@@ -112,7 +108,7 @@ fn main() -> ! {
112108
// Poll to get the message out of the door
113109
iface.poll(
114110
Instant::from_millis(time as i64 + 1),
115-
&mut &mut dma,
111+
&mut dma,
116112
&mut sockets,
117113
);
118114
}
@@ -122,11 +118,7 @@ fn main() -> ! {
122118
socket.abort();
123119
defmt::info!("Transmitted hello! Closing socket...");
124120

125-
iface.poll(
126-
Instant::from_millis(time as i64),
127-
&mut &mut dma,
128-
&mut sockets,
129-
);
121+
iface.poll(Instant::from_millis(time as i64), &mut dma, &mut sockets);
130122
}
131123
Err(_) => {}
132124
}

examples/rtic-echo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mod app {
110110

111111
let config = iface::Config::new(EthernetAddress::from_bytes(&crate::MAC).into());
112112

113-
let mut interface = Interface::new(config, &mut &mut dma, smoltcp::time::Instant::ZERO);
113+
let mut interface = Interface::new(config, &mut dma, smoltcp::time::Instant::ZERO);
114114
interface.update_ip_addrs(|addr| {
115115
addr.push(IpCidr::Ipv4(Ipv4Cidr::new(crate::IP_ADDRESS, 24)))
116116
.ok();
@@ -123,7 +123,7 @@ mod app {
123123
let socket = sockets.get_mut::<TcpSocket>(tcp_handle);
124124
socket.listen(crate::SOCKET_ADDRESS).ok();
125125

126-
interface.poll(now_fn(), &mut &mut dma, &mut sockets);
126+
interface.poll(now_fn(), &mut dma, &mut sockets);
127127

128128
if let Ok(mut phy) = EthernetPhy::from_miim(mac, 0) {
129129
defmt::info!(

examples/smoltcp-timesync/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ mod app {
132132

133133
let cfg = Config::new(EthernetAddress(CLIENT_ADDR).into());
134134

135-
let mut interface = Interface::new(cfg, &mut &mut dma, smoltcp::time::Instant::ZERO);
135+
let mut interface = Interface::new(cfg, &mut dma, smoltcp::time::Instant::ZERO);
136136
interface.update_ip_addrs(|a| {
137137
a.push(IpCidr::new(IpAddress::v4(10, 0, 0, 2), 24)).ok();
138138
});

examples/smoltcp-timesync/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mod app {
100100

101101
let cfg = Config::new(EthernetAddress(SERVER_ADDR).into());
102102

103-
let mut interface = Interface::new(cfg, &mut &mut dma, smoltcp::time::Instant::ZERO);
103+
let mut interface = Interface::new(cfg, &mut dma, smoltcp::time::Instant::ZERO);
104104
interface.update_ip_addrs(|a| {
105105
a.push(IpCidr::new(IpAddress::v4(10, 0, 0, 1), 24)).ok();
106106
});

src/dma/smoltcp_phy.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,32 @@ use super::PacketId;
1010
use smoltcp::phy::{ChecksumCapabilities, Device, DeviceCapabilities, RxToken, TxToken};
1111
use smoltcp::time::Instant;
1212

13+
impl<'rx, 'tx, 'a> Device for &'a mut EthernetDMA<'rx, 'tx> {
14+
type RxToken<'token>
15+
= <EthernetDMA<'rx, 'tx> as Device>::RxToken<'token>
16+
where
17+
Self: 'token;
18+
19+
type TxToken<'token>
20+
= <EthernetDMA<'rx, 'tx> as Device>::TxToken<'token>
21+
where
22+
Self: 'token;
23+
24+
fn receive(&mut self, timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
25+
<EthernetDMA<'rx, 'tx> as Device>::receive(self, timestamp)
26+
}
27+
28+
fn transmit(&mut self, timestamp: Instant) -> Option<Self::TxToken<'_>> {
29+
<EthernetDMA<'rx, 'tx> as Device>::transmit(self, timestamp)
30+
}
31+
32+
fn capabilities(&self) -> DeviceCapabilities {
33+
<EthernetDMA<'rx, 'tx> as Device>::capabilities(self)
34+
}
35+
}
36+
1337
/// Use this Ethernet driver with [smoltcp](https://github.com/smoltcp-rs/smoltcp)
14-
impl<'a, 'rx, 'tx> Device for &'a mut EthernetDMA<'rx, 'tx> {
38+
impl<'rx, 'tx> Device for EthernetDMA<'rx, 'tx> {
1539
type RxToken<'token>
1640
= EthRxToken<'token, 'rx>
1741
where

0 commit comments

Comments
 (0)