Skip to content

Commit 730275a

Browse files
Merge pull request #13 from dtjones190/master
Added STM32F767 Support
2 parents 922c6a1 + fdf3670 commit 730275a

File tree

13 files changed

+169
-32
lines changed

13 files changed

+169
-32
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
target/
2-
Cargo.lock
2+
Cargo.lock

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,24 @@ matrix:
2121
env: FEATURES='stm32f429' ARGS="--release --target=thumbv7em-none-eabihf --example=pktgen"
2222
- rust: nightly
2323
env: FEATURES='stm32f429 smoltcp-phy smoltcp-log smoltcp-verbose' ARGS="--release --target=thumbv7em-none-eabihf --example=ip"
24+
- rust: nightly
25+
env: FEATURES='stm32f745'
26+
- rust: nightly
27+
env: FEATURES='stm32f746'
28+
- rust: nightly
29+
env: FEATURES='stm32f756'
30+
- rust: nightly
31+
env: FEATURES='stm32f765'
32+
- rust: nightly
33+
env: FEATURES='stm32f767'
34+
- rust: nightly
35+
env: FEATURES='stm32f769'
36+
- rust: nightly
37+
env: FEATURES='stm32f777'
38+
- rust: nightly
39+
env: FEATURES='stm32f778'
40+
- rust: nightly
41+
env: FEATURES='stm32f779'
42+
2443
script:
2544
- "cargo build --target=`uname -m`-unknown-linux-gnu --no-default-features --features \"$FEATURES\""

Cargo.toml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Embedded Rust Ethernet driver for the STM32 MCU series"
55
license = "Apache-2.0"
66
authors = ["Astro <[email protected]>"]
77
version = "0.2.0"
8-
keywords = ["ethernet", "eth", "stm32", "stm32f4"]
8+
keywords = ["ethernet", "eth", "stm32", "stm32f4", "stm32f7"]
99
repository = "https://github.com/stm32-rs/stm32-eth"
1010
documentation = "https://docs.rs/stm32-eth/"
1111
edition = "2018"
@@ -20,7 +20,9 @@ features = [ "smoltcp-phy", "stm32f429" ]
2020
[dependencies]
2121
volatile-register = "0.2"
2222
aligned = "0.3"
23-
stm32f4xx-hal = "0.8.3"
23+
stm32f7xx-hal = {version = "0.2.0", optional = true}
24+
stm32f4xx-hal = {version = "0.8.3", optional = true}
25+
cortex-m = "0.6.0"
2426

2527
smoltcp = { version = "0.6.0", default-features = false, features = ["proto-ipv4", "proto-ipv6", "socket-icmp", "socket-udp", "socket-tcp", "ethernet"], optional = true }
2628
log = { version = "0.4", optional = true }
@@ -35,6 +37,17 @@ stm32f437 = ["stm32f4xx-hal/stm32f437", "device-selected"]
3537
stm32f439 = ["stm32f4xx-hal/stm32f439", "device-selected"]
3638
stm32f469 = ["stm32f4xx-hal/stm32f469", "device-selected"]
3739
stm32f479 = ["stm32f4xx-hal/stm32f479", "device-selected"]
40+
41+
stm32f745 = ["stm32f7xx-hal/stm32f745", "device-selected"]
42+
stm32f746 = ["stm32f7xx-hal/stm32f746", "device-selected"]
43+
stm32f756 = ["stm32f7xx-hal/stm32f756", "device-selected"]
44+
stm32f765 = ["stm32f7xx-hal/stm32f765", "device-selected"]
45+
stm32f767 = ["stm32f7xx-hal/stm32f767", "device-selected"]
46+
stm32f769 = ["stm32f7xx-hal/stm32f769", "device-selected"]
47+
stm32f777 = ["stm32f7xx-hal/stm32f777", "device-selected"]
48+
stm32f778 = ["stm32f7xx-hal/stm32f778", "device-selected"]
49+
stm32f779 = ["stm32f7xx-hal/stm32f779", "device-selected"]
50+
3851
smoltcp-phy = ["smoltcp"]
3952
smoltcp-log = ["log", "smoltcp/log"]
4053
smoltcp-verbose = ["smoltcp/verbose"]

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
## Supported microcontrollers
66

77
* STM32F4xx
8+
* STM32F7xx
89

910
Please send pull requests.
1011

12+
## Building Examples
13+
```
14+
cargo build --example="pktgen" --features="stm32f429"
15+
cargo build --example="ip" --features="stm32f429" --features="smoltcp-phy smoltcp-log smoltcp-verbose"
16+
```
1117

1218
## Usage
1319

@@ -16,13 +22,21 @@ Add to the `[dependencies]` section in your `Cargo.toml`:
1622
stm32f4xx-hal = { version = "0.8.3", features = ["stm32f429"] }
1723
stm32-eth = { version = "0.2.0", features = ["stm32f429"] }
1824
```
25+
or
26+
```rust
27+
stm32f7xx-hal = { version = "0.2.0", features = ["stm32f767"] }
28+
stm32-eth = { version = "0.2.0", features = ["stm32f767"]}
29+
```
1930

2031
In `src/main.rs` add:
2132
```rust
22-
use stm32f4xx_hal::{
23-
gpio::GpioExt,
33+
use stm32_eth::{
34+
hal::gpio::GpioExt,
35+
hal::rcc::RccExt,
2436
stm32::Peripherals,
2537
};
38+
39+
2640
use stm32_eth::{Eth, RingEntry};
2741

2842
fn main() {

examples/ip.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ extern crate panic_itm;
55

66
use cortex_m::asm;
77
use cortex_m_rt::{entry, exception};
8-
use stm32f4xx_hal::{
9-
gpio::GpioExt,
10-
prelude::*,
8+
use stm32_eth::{
9+
hal::gpio::GpioExt,
10+
hal::rcc::RccExt,
11+
hal::time::U32Ext,
1112
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
1213
};
1314

examples/pktgen.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use cortex_m_rt::{entry, exception};
99

1010
use cortex_m::asm;
1111
use cortex_m::interrupt::Mutex;
12-
use stm32f4xx_hal::{
13-
gpio::GpioExt,
14-
prelude::*,
12+
use stm32_eth::{
13+
hal::gpio::GpioExt,
14+
hal::rcc::RccExt,
15+
hal::time::U32Ext,
1516
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
1617
};
1718

src/lib.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
#![no_std]
22

33
/// Re-export
4+
#[cfg(feature = "stm32f7xx-hal")]
5+
pub use stm32f7xx_hal as hal;
6+
/// Re-export
7+
#[cfg(feature = "stm32f7xx-hal")]
8+
pub use stm32f7xx_hal::device as stm32;
9+
10+
/// Re-export
11+
#[cfg(feature = "stm32f4xx-hal")]
412
pub use stm32f4xx_hal as hal;
513
/// Re-export
14+
#[cfg(feature = "stm32f4xx-hal")]
615
pub use stm32f4xx_hal::stm32;
7-
use stm32f4xx_hal::{
8-
rcc::Clocks,
9-
stm32::{Interrupt, ETHERNET_DMA, ETHERNET_MAC, NVIC},
10-
};
16+
17+
use hal::rcc::Clocks;
18+
use stm32::{Interrupt, ETHERNET_DMA, ETHERNET_MAC, NVIC};
19+
20+
use cortex_m::asm;
1121

1222
pub mod phy;
1323
use phy::{Phy, PhyStatus};
@@ -78,8 +88,10 @@ impl<'rx, 'tx> Eth<'rx, 'tx> {
7888
///
7989
/// Make sure that the buffers reside in a memory region that is
8090
/// accessible by the peripheral. Core-Coupled Memory (CCM) is
81-
/// usually not accessible. Also, HCLK must be between 25MHz and 168MHz to use the ethernet
82-
/// peripheral.
91+
/// usually not accessible. HCLK must be between 25MHz and 168MHz for STM32F4xx
92+
/// or 25MHz to 216MHz for STM32F7xx.
93+
///
94+
/// Uses an interrupt free critical section to turn on the ethernet clock for STM32F7xx.
8395
///
8496
/// Other than that, initializes and starts the Ethernet hardware
8597
/// so that you can [`send()`](#method.send) and
@@ -125,7 +137,10 @@ impl<'rx, 'tx> Eth<'rx, 'tx> {
125137
100_000_000..=149_999_999 => ETH_MACMIIAR_CR_HCLK_DIV_62,
126138
25_000_000..=34_999_999 => ETH_MACMIIAR_CR_HCLK_DIV_16,
127139
35_000_000..=59_999_999 => ETH_MACMIIAR_CR_HCLK_DIV_26,
140+
#[cfg(feature = "stm32f4xx-hal")]
128141
150_000_000..=168_000_000 => ETH_MACMIIAR_CR_HCLK_DIV_102,
142+
#[cfg(feature = "stm32f7xx-hal")]
143+
150_000_000..=216_000_000 => ETH_MACMIIAR_CR_HCLK_DIV_102,
129144
_ => return Err(WrongClock),
130145
};
131146
self.reset_dma_and_wait();
@@ -249,10 +264,8 @@ impl<'rx, 'tx> Eth<'rx, 'tx> {
249264
});
250265

251266
// Enable ethernet interrupts
252-
let interrupt = Interrupt::ETH;
253-
254267
unsafe {
255-
NVIC::unmask(interrupt);
268+
NVIC::unmask(Interrupt::ETH);
256269
}
257270
}
258271

@@ -301,6 +314,8 @@ impl<'rx, 'tx> Eth<'rx, 'tx> {
301314
f: F,
302315
) -> Result<R, TxError> {
303316
let result = self.tx_ring.send(length, f);
317+
//Make sure the memory write occurs before triggering DMA
318+
asm::dmb();
304319
self.tx_ring.demand_poll(&self.eth_dma);
305320
result
306321
}

src/phy.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
#[cfg(feature = "stm32f4xx-hal")]
2+
use stm32f4xx_hal::stm32;
3+
#[cfg(feature = "stm32f7xx-hal")]
4+
use stm32f7xx_hal::device as stm32;
5+
6+
use stm32::ethernet_mac::{MACMIIAR, MACMIIDR};
7+
18
use core::option::Option;
2-
use stm32f4xx_hal::stm32::ethernet_mac::{MACMIIAR, MACMIIDR};
39

410
use crate::smi::SMI;
511

src/rx.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
#[cfg(feature = "stm32f4xx-hal")]
2+
use stm32f4xx_hal::stm32;
3+
#[cfg(feature = "stm32f7xx-hal")]
4+
use stm32f7xx_hal::device as stm32;
5+
6+
use stm32::ETHERNET_DMA;
7+
18
use core::default::Default;
29
use core::ops::{Deref, DerefMut};
3-
use stm32f4xx_hal::stm32::ETHERNET_DMA;
410

511
use crate::{
612
desc::Descriptor,

src/setup.rs

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(feature = "device-selected")]
1+
#[cfg(feature = "stm32f4xx-hal")]
22
use stm32f4xx_hal::{
33
bb,
44
gpio::{
@@ -12,15 +12,31 @@ use stm32f4xx_hal::{
1212
stm32::{RCC, SYSCFG},
1313
};
1414

15-
const SYSCFG_BIT: u8 = 14;
16-
const ETH_MAC_BIT: u8 = 25;
17-
const ETH_TX_BIT: u8 = 26;
18-
const ETH_RX_BIT: u8 = 27;
19-
const MII_RMII_BIT: u8 = 23;
15+
#[cfg(feature = "stm32f7xx-hal")]
16+
use cortex_m::interrupt;
17+
#[cfg(feature = "stm32f7xx-hal")]
18+
use stm32f7xx_hal::{
19+
device::{RCC, SYSCFG},
20+
gpio::{
21+
gpioa::{PA1, PA2, PA7},
22+
gpiob::{PB11, PB12, PB13},
23+
gpioc::{PC1, PC4, PC5},
24+
gpiog::{PG11, PG13, PG14},
25+
Floating, Input,
26+
Speed::VeryHigh,
27+
},
28+
};
2029

2130
// Enable syscfg and ethernet clocks. Reset the Ethernet MAC.
2231
pub(crate) fn setup() {
32+
#[cfg(feature = "stm32f4xx-hal")]
2333
unsafe {
34+
const SYSCFG_BIT: u8 = 14;
35+
const ETH_MAC_BIT: u8 = 25;
36+
const ETH_TX_BIT: u8 = 26;
37+
const ETH_RX_BIT: u8 = 27;
38+
const MII_RMII_BIT: u8 = 23;
39+
2440
//NOTE(unsafe) This will only be used for atomic writes with no side-effects
2541
let rcc = &*RCC::ptr();
2642
let syscfg = &*SYSCFG::ptr();
@@ -45,6 +61,38 @@ pub(crate) fn setup() {
4561
bb::set(&rcc.ahb1rstr, ETH_MAC_BIT);
4662
bb::clear(&rcc.ahb1rstr, ETH_MAC_BIT);
4763
}
64+
#[cfg(feature = "stm32f7xx-hal")]
65+
//stm32f7xx-hal does not currently have bitbanding
66+
interrupt::free(|_| unsafe {
67+
//NOTE(unsafe) Interrupt free and we only modify mac bits
68+
let rcc = &*RCC::ptr();
69+
let syscfg = &*SYSCFG::ptr();
70+
// enable syscfg clock
71+
rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit());
72+
73+
if rcc.ahb1enr.read().ethmacen().bit_is_set() {
74+
// pmc must be changed with the ethernet controller disabled or under reset
75+
rcc.ahb1enr.modify(|_, w| w.ethmacen().clear_bit());
76+
}
77+
78+
// select MII or RMII mode
79+
// 0 = MII, 1 = RMII
80+
syscfg.pmc.modify(|_, w| w.mii_rmii_sel().set_bit());
81+
82+
// enable ethernet clocks
83+
rcc.ahb1enr.modify(|_, w| {
84+
w.ethmacen()
85+
.set_bit()
86+
.ethmactxen()
87+
.set_bit()
88+
.ethmacrxen()
89+
.set_bit()
90+
});
91+
92+
//reset pulse
93+
rcc.ahb1rstr.modify(|_, w| w.ethmacrst().set_bit());
94+
rcc.ahb1rstr.modify(|_, w| w.ethmacrst().clear_bit());
95+
});
4896
}
4997

5098
/// RMII Reference Clock.

0 commit comments

Comments
 (0)