Skip to content

Commit 389586d

Browse files
committed
2 parents b944ae2 + 922c6a1 commit 389586d

File tree

13 files changed

+441
-223
lines changed

13 files changed

+441
-223
lines changed

.travis.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ language: rust
22
matrix:
33
include:
44
- rust: nightly
5-
env: FEATURES='stm32f4xx-hal/stm32f407'
5+
env: FEATURES='stm32f407'
66
- rust: nightly
7-
env: FEATURES='stm32f4xx-hal/stm32f417'
7+
env: FEATURES='stm32f417'
88
- rust: nightly
9-
env: FEATURES='stm32f4xx-hal/stm32f427'
9+
env: FEATURES='stm32f427'
1010
- rust: nightly
11-
env: FEATURES='stm32f4xx-hal/stm32f429'
11+
env: FEATURES='stm32f429'
1212
- rust: nightly
13-
env: FEATURES='stm32f4xx-hal/stm32f437'
13+
env: FEATURES='stm32f437'
1414
- rust: nightly
15-
env: FEATURES='stm32f4xx-hal/stm32f439'
15+
env: FEATURES='stm32f439'
1616
- rust: nightly
17-
env: FEATURES='stm32f4xx-hal/stm32f469'
17+
env: FEATURES='stm32f469'
1818
- rust: nightly
19-
env: FEATURES='stm32f4xx-hal/stm32f479'
19+
env: FEATURES='stm32f479'
2020
- rust: nightly
21-
env: FEATURES='stm32f4xx-hal/rt nucleo-f429zi' ARGS="--release --target=thumbv7em-none-eabihf --example=pktgen"
21+
env: FEATURES='stm32f429' ARGS="--release --target=thumbv7em-none-eabihf --example=pktgen"
2222
- rust: nightly
23-
env: FEATURES='stm32f4xx-hal/rt nucleo-f429zi smoltcp-phy' ARGS="--release --target=thumbv7em-none-eabihf --example=ip"
23+
env: FEATURES='stm32f429 smoltcp-phy smoltcp-log smoltcp-verbose' ARGS="--release --target=thumbv7em-none-eabihf --example=ip"
2424
script:
2525
- "cargo build --target=`uname -m`-unknown-linux-gnu --no-default-features --features \"$FEATURES\""

Cargo.toml

Lines changed: 24 additions & 11 deletions
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 <[email protected]>"]
7-
version = "0.1.2"
7+
version = "0.2.0"
88
keywords = ["ethernet", "eth", "stm32", "stm32f4", "stm32f7"]
99
repository = "https://github.com/stm32-rs/stm32-eth"
1010
documentation = "https://docs.rs/stm32-eth/"
@@ -15,36 +15,49 @@ travis-ci = { repository = "astro/stm32-eth", branch = "master" }
1515
maintenance = { status = "experimental" }
1616

1717
[package.metadata.docs.rs]
18-
features = [ "smoltcp-phy", "nucleo-f429zi", "nucleo-f767zi" ]
18+
features = [ "smoltcp-phy", "stm32f429" ]
1919

2020
[dependencies]
2121
volatile-register = "0.2"
2222
aligned = "0.3"
2323
stm32f7xx-hal = {version = "0.2.0", optional = true}
24-
stm32f4xx-hal = {version = "0.7", optional = true}
24+
stm32f4xx-hal = {version = "0.8.3", optional = true}
2525
cortex-m = "0.6.0"
2626

27-
smoltcp = { version = "0.6", default-features = false, features = ["proto-ipv4", "proto-ipv6", "socket-icmp", "socket-udp", "socket-tcp", "log", "verbose", "ethernet"], optional = true }
27+
smoltcp = { version = "0.6.0", default-features = false, features = ["proto-ipv4", "proto-ipv6", "socket-icmp", "socket-udp", "socket-tcp", "ethernet"], optional = true }
2828
log = { version = "0.4", optional = true }
2929

3030
[features]
31-
smoltcp-phy = ["smoltcp", "log"]
32-
default = []
33-
nucleo-f767zi = ["stm32f7xx-hal", "stm32f7xx-hal/stm32f767", "stm32f7xx-hal/rt"]
34-
nucleo-f429zi = ["stm32f4xx-hal", "stm32f4xx-hal/stm32f429", "stm32f4xx-hal/rt"]
31+
device-selected = []
32+
stm32f407 = ["stm32f4xx-hal/stm32f407", "device-selected"]
33+
stm32f417 = ["stm32f4xx-hal/stm32f417", "device-selected"]
34+
stm32f427 = ["stm32f4xx-hal/stm32f427", "device-selected"]
35+
stm32f429 = ["stm32f4xx-hal/stm32f429", "device-selected"]
36+
stm32f437 = ["stm32f4xx-hal/stm32f437", "device-selected"]
37+
stm32f439 = ["stm32f4xx-hal/stm32f439", "device-selected"]
38+
stm32f469 = ["stm32f4xx-hal/stm32f469", "device-selected"]
39+
stm32f479 = ["stm32f4xx-hal/stm32f479", "device-selected"]
40+
41+
stm32f767 = ["stm32f7xx-hal/stm32f767", "device-selected"]
42+
43+
smoltcp-phy = ["smoltcp"]
44+
smoltcp-log = ["log", "smoltcp/log"]
45+
smoltcp-verbose = ["smoltcp/verbose"]
3546

3647
[dev-dependencies]
37-
cortex-m = "0.5"
48+
cortex-m = "0.6.2"
3849
cortex-m-rt = "0.6"
3950
panic-itm = "0.4"
40-
cortex-m-semihosting = "0.3.3"
51+
cortex-m-semihosting = "0.3.5"
52+
stm32f4xx-hal = {version = "0.8.3", features = ["rt"] }
4153

4254
[[example]]
4355
name = "pktgen"
56+
required-features = ["stm32f429"]
4457

4558
[[example]]
4659
name = "ip"
47-
required-features = ["smoltcp-phy"]
60+
required-features = ["stm32f429", "smoltcp-phy", "smoltcp-log", "smoltcp-verbose"]
4861

4962
[profile.release]
5063
debug = 2

README.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ cargo build --example="ip" --features="nucleo-f767zi" --features="smoltcp-phy"
1919

2020
Add to the `[dependencies]` section in your `Cargo.toml`:
2121
```rust
22-
stm32f4xx-hal = { version = "*", features = ["stm32f429"] }
23-
stm32-eth = { version = "0.1.1", features = ["nucleo-f429zi"] }
22+
stm32f4xx-hal = { version = "0.8.3", features = ["stm32f429"] }
23+
stm32-eth = { version = "0.2.0", features = ["stm32f429"] }
2424
```
2525
or
2626
```rust
@@ -42,35 +42,45 @@ use stm32_eth::{Eth, RingEntry};
4242
fn main() {
4343
let p = Peripherals::take().unwrap();
4444

45-
// Setup pins and initialize clocks.
46-
stm32_eth::setup(&p.RCC, &p.SYSCFG);
45+
let rcc = p.RCC.constrain();
46+
// HCLK must be between 25MHz and 168MHz to use the ethernet peripheral
47+
let clocks = rcc.cfgr.sysclk(32.mhz()).hclk(32.mhz()).freeze();
48+
4749
let gpioa = p.GPIOA.split();
4850
let gpiob = p.GPIOB.split();
4951
let gpioc = p.GPIOC.split();
5052
let gpiog = p.GPIOG.split();
51-
stm32_eth::setup_pins(
52-
gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1,
53-
gpioc.pc4, gpioc.pc5, gpiog.pg11, gpiog.pg13
54-
);
55-
// Allocate the ring buffers
56-
let mut rx_ring: [RingEntry<_>; 8] = Default::default();
57-
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
58-
let clocks = p.RCC.constrain().cfgr.freeze();
59-
// Instantiate driver
60-
let mut eth = Eth::new(
61-
p.ETHERNET_MAC, p.ETHERNET_DMA,
62-
&mut rx_ring[..], &mut tx_ring[..],
63-
&clocks
64-
);
65-
// If you have a handler, enable interrupts
66-
eth.enable_interrupt(&mut cp.NVIC);
6753

54+
let eth_pins = EthPins {
55+
ref_clk: gpioa.pa1,
56+
md_io: gpioa.pa2,
57+
md_clk: gpioc.pc1,
58+
crs: gpioa.pa7,
59+
tx_en: gpiog.pg11,
60+
tx_d0: gpiog.pg13,
61+
tx_d1: gpiob.pb13,
62+
rx_d0: gpioc.pc4,
63+
rx_d1: gpioc.pc5,
64+
};
65+
66+
let mut rx_ring: [RingEntry<_>; 16] = Default::default();
67+
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
68+
let mut eth = Eth::new(
69+
p.ETHERNET_MAC,
70+
p.ETHERNET_DMA,
71+
&mut rx_ring[..],
72+
&mut tx_ring[..],
73+
PhyAddress::_0,
74+
clocks,
75+
eth_pins,
76+
)
77+
.unwrap();
78+
eth.enable_interrupt();
6879

6980
if let Ok(pkt) = eth.recv_next() {
7081
// handle received pkt
7182
}
7283

73-
7484
eth.send(size, |buf| {
7585
// write up to `size` bytes into buf before it is being sent
7686
}).expect("send");

examples/ip.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern crate panic_itm;
66
use cortex_m::asm;
77
use cortex_m_rt::{entry, exception};
88
use stm32_eth::{
9+
hal::time::U32Ext,
910
hal::gpio::GpioExt,
1011
hal::rcc::RccExt,
1112
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
@@ -23,7 +24,7 @@ use smoltcp::socket::{SocketSet, TcpSocket, TcpSocketBuffer};
2324
use smoltcp::time::Instant;
2425
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};
2526

26-
use stm32_eth::{Eth, RingEntry};
27+
use stm32_eth::{Eth, EthPins, PhyAddress, RingEntry};
2728

2829
static mut LOGGER: HioLogger = HioLogger {};
2930

@@ -60,29 +61,42 @@ fn main() -> ! {
6061
let p = Peripherals::take().unwrap();
6162
let mut cp = CorePeripherals::take().unwrap();
6263

64+
let rcc = p.RCC.constrain();
65+
// HCLK must be between 25MHz and 168MHz to use the ethernet peripheral
66+
let clocks = rcc.cfgr.sysclk(32.mhz()).hclk(32.mhz()).freeze();
67+
6368
setup_systick(&mut cp.SYST);
6469

6570
writeln!(stdout, "Enabling ethernet...").unwrap();
66-
stm32_eth::setup(&p.RCC, &p.SYSCFG);
6771
let gpioa = p.GPIOA.split();
6872
let gpiob = p.GPIOB.split();
6973
let gpioc = p.GPIOC.split();
7074
let gpiog = p.GPIOG.split();
71-
stm32_eth::setup_pins(
72-
gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1, gpioc.pc4, gpioc.pc5, gpiog.pg11,
73-
gpiog.pg13,
74-
);
75+
76+
let eth_pins = EthPins {
77+
ref_clk: gpioa.pa1,
78+
md_io: gpioa.pa2,
79+
md_clk: gpioc.pc1,
80+
crs: gpioa.pa7,
81+
tx_en: gpiog.pg11,
82+
tx_d0: gpiog.pg13,
83+
tx_d1: gpiob.pb13,
84+
rx_d0: gpioc.pc4,
85+
rx_d1: gpioc.pc5,
86+
};
7587

7688
let mut rx_ring: [RingEntry<_>; 8] = Default::default();
7789
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
78-
let clocks = p.RCC.constrain().cfgr.freeze();
7990
let mut eth = Eth::new(
8091
p.ETHERNET_MAC,
8192
p.ETHERNET_DMA,
8293
&mut rx_ring[..],
8394
&mut tx_ring[..],
84-
&clocks,
85-
);
95+
PhyAddress::_0,
96+
clocks,
97+
eth_pins,
98+
)
99+
.unwrap();
86100
eth.enable_interrupt();
87101

88102
let local_addr = Ipv4Address::new(10, 0, 0, 1);

examples/pktgen.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use cortex_m_rt::{entry, exception};
1010
use cortex_m::asm;
1111
use cortex_m::interrupt::Mutex;
1212
use stm32_eth::{
13+
hal::time::U32Ext,
1314
hal::gpio::GpioExt,
1415
hal::rcc::RccExt,
1516
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
@@ -18,7 +19,7 @@ use stm32_eth::{
1819
use core::fmt::Write;
1920
use cortex_m_semihosting::hio;
2021

21-
use stm32_eth::{Eth, RingEntry, TxError};
22+
use stm32_eth::{Eth, EthPins, PhyAddress, RingEntry, TxError};
2223

2324
const SRC_MAC: [u8; 6] = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
2425
const DST_MAC: [u8; 6] = [0x00, 0x00, 0xBE, 0xEF, 0xDE, 0xAD];
@@ -34,29 +35,42 @@ fn main() -> ! {
3435
let p = Peripherals::take().unwrap();
3536
let mut cp = CorePeripherals::take().unwrap();
3637

38+
let rcc = p.RCC.constrain();
39+
// HCLK must be between 25MHz and 168MHz to use the ethernet peripheral
40+
let clocks = rcc.cfgr.sysclk(32.mhz()).hclk(32.mhz()).freeze();
41+
3742
setup_systick(&mut cp.SYST);
3843

3944
writeln!(stdout, "Enabling ethernet...").unwrap();
40-
stm32_eth::setup(&p.RCC, &p.SYSCFG);
4145
let gpioa = p.GPIOA.split();
4246
let gpiob = p.GPIOB.split();
4347
let gpioc = p.GPIOC.split();
4448
let gpiog = p.GPIOG.split();
45-
stm32_eth::setup_pins(
46-
gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1, gpioc.pc4, gpioc.pc5, gpiog.pg11,
47-
gpiog.pg13,
48-
);
49+
50+
let eth_pins = EthPins {
51+
ref_clk: gpioa.pa1,
52+
md_io: gpioa.pa2,
53+
md_clk: gpioc.pc1,
54+
crs: gpioa.pa7,
55+
tx_en: gpiog.pg11,
56+
tx_d0: gpiog.pg13,
57+
tx_d1: gpiob.pb13,
58+
rx_d0: gpioc.pc4,
59+
rx_d1: gpioc.pc5,
60+
};
4961

5062
let mut rx_ring: [RingEntry<_>; 16] = Default::default();
5163
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
52-
let clocks = p.RCC.constrain().cfgr.freeze();
5364
let mut eth = Eth::new(
5465
p.ETHERNET_MAC,
5566
p.ETHERNET_DMA,
5667
&mut rx_ring[..],
5768
&mut tx_ring[..],
58-
&clocks,
59-
);
69+
PhyAddress::_0,
70+
clocks,
71+
eth_pins,
72+
)
73+
.unwrap();
6074
eth.enable_interrupt();
6175

6276
// Main loop

run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if [[ "$EXAMPLE" = "" ]]; then
1313
fi
1414

1515
cargo build --target=thumbv7em-none-eabihf --release \
16-
--features="stm32f4xx-hal/rt nucleo-f429zi smoltcp-phy" \
16+
--features="stm32f429 smoltcp-phy smoltcp-log smoltcp-verbose" \
1717
--example=$EXAMPLE \
1818
|| exit 1
1919

src/desc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct Descriptor {
1111
impl Clone for Descriptor {
1212
fn clone(&self) -> Self {
1313
Descriptor {
14-
desc: Aligned((*self.desc).clone()),
14+
desc: Aligned(*self.desc),
1515
}
1616
}
1717
}

0 commit comments

Comments
 (0)