Skip to content

Commit 00d86b2

Browse files
author
ru
committed
example ip-f107 updated
1 parent a89eb23 commit 00d86b2

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ log = { version = "0.4", optional = true }
2828

2929
[dependencies.smoltcp]
3030
version = "0.7.0"
31+
# git = "https://github.com/smoltcp-rs/smoltcp"
32+
# branch = "master"
3133
default-features = false
3234
features = ["ethernet", "proto-ipv4"]
3335
optional = true

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,31 @@
1010
Please send pull requests.
1111

1212
## Building Examples
13-
```
13+
14+
```bash
1415
cargo build --example="pktgen" --features="stm32f429"
1516
cargo build --example="ip" --features="stm32f429 smoltcp-phy log smoltcp/socket-tcp smoltcp/socket-icmp smoltcp/log smoltcp/verbose"
17+
cargo build --example="ip-f107" --features="stm32f107 smoltcp-phy log smoltcp/socket-tcp smoltcp/socket-icmp" --release
1618
```
1719

1820
## Usage
1921

2022
Add to the `[dependencies]` section in your `Cargo.toml`:
23+
2124
```rust
2225
stm32f4xx-hal = { version = "0.8.3", features = ["stm32f429"] }
2326
stm32-eth = { version = "0.2.0", features = ["stm32f429"] }
2427
```
28+
2529
or
30+
2631
```rust
2732
stm32f7xx-hal = { version = "0.2.0", features = ["stm32f767"] }
2833
stm32-eth = { version = "0.2.0", features = ["stm32f767"]}
2934
```
3035

3136
In `src/main.rs` add:
37+
3238
```rust
3339
use stm32_eth::{
3440
hal::gpio::GpioExt,

examples/ip-f107.rs

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use smoltcp::time::Instant;
2525
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};
2626
use stm32_eth::{Eth, EthPins, PhyAddress, RingEntry};
2727

28-
use stm32f1xx_hal::{prelude::*, flash::FlashExt};
2928
use rtt_target::{rprintln, rtt_init_print};
29+
use stm32f1xx_hal::{flash::FlashExt, prelude::*};
3030

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

@@ -37,21 +37,73 @@ static ETH_PENDING: Mutex<RefCell<bool>> = Mutex::new(RefCell::new(false));
3737
fn main() -> ! {
3838
rtt_init_print!();
3939

40-
let p = Peripherals::take().unwrap();
40+
let p = stm32f1xx_hal::stm32::Peripherals::take().unwrap();
4141
let mut cp = CorePeripherals::take().unwrap();
4242

4343
let mut flash = p.FLASH.constrain();
44-
let mut rcc = p.RCC.constrain();
4544

4645
// HCLK must be at least 25MHz to use the ethernet peripheral
4746
rprintln!("Setting up clocks");
47+
48+
// Code below handle situation when ethernet controller has its own clock
49+
50+
// let mut rcc = p.RCC.constrain();
51+
// let clocks = rcc
52+
// .cfgr
53+
// .use_hse(8.mhz())
54+
// .sysclk(72.mhz())
55+
// .hclk(72.mhz())
56+
// .pclk1(36.mhz())
57+
// .freeze(&mut flash.acr);
58+
///////////////////////////////////////////////////////////////////////////////
59+
60+
// This case handles case when ethernet controller clock is connected to MCO pin of STM32F107
61+
// MCU has connected 25 MHz oscillator to XTAL
62+
// Prescaller valuses (see clock diagram for STM32F107)
63+
// PREDIV2 = /5
64+
// PLL2MUL = x8
65+
// PREDIV1 = /5 (We have 8 Mhz for 'Clock from PREDIV1')
66+
// PLL3MUL = x10
67+
// PREDIV1SRC = PPL2
68+
let rcc = p.RCC;
69+
rcc.cfgr2.write(|w| {
70+
w.prediv2()
71+
.div5()
72+
.pll2mul()
73+
.mul8()
74+
.prediv1src()
75+
.pll2()
76+
.prediv1()
77+
.div5()
78+
.pll3mul()
79+
.mul10()
80+
});
81+
82+
// enable HSE and wait for it to be ready
83+
rcc.cr.modify(|_, w| w.hseon().set_bit());
84+
while rcc.cr.read().hserdy().bit_is_clear() {}
85+
86+
// enable PLL2 and wait until ready
87+
rcc.cr.modify(|_, w| w.pll2on().set_bit());
88+
while rcc.cr.read().pll2rdy().bit_is_clear() {}
89+
90+
// enable PLL3 and wait until ready
91+
rcc.cr.modify(|_, w| w.pll3on().set_bit());
92+
while rcc.cr.read().pll3rdy().bit_is_clear() {}
93+
94+
// Get PLL3 clock on PA8 pin (MCO)
95+
rcc.cfgr.modify(|_, w| w.mco().pll3ethernet());
96+
97+
let mut rcc = rcc.constrain();
98+
let acr = &mut flash.acr;
99+
48100
let clocks = rcc
49101
.cfgr
50-
.use_hse(8.mhz())
102+
.use_hse(8.mhz()) // HSE (Clock from PREDIV1), PLL configuration PREDIV2/PLL2MUL changes 25Mhz to 8Mhz
51103
.sysclk(72.mhz())
52-
.hclk(72.mhz())
53104
.pclk1(36.mhz())
54-
.freeze(&mut flash.acr);
105+
.freeze(acr);
106+
///////////////////////////////////////////////////////////////////////////////
55107

56108
rprintln!("Setting up systick");
57109
setup_systick(&mut cp.SYST);
@@ -61,6 +113,9 @@ fn main() -> ! {
61113
let mut gpiob = p.GPIOB.split(&mut rcc.apb2);
62114
let mut gpioc = p.GPIOC.split(&mut rcc.apb2);
63115

116+
// PLL3CLK goes to MCO (Main Clock Output) (PA8)
117+
let _mco = gpioa.pa8.into_alternate_push_pull(&mut gpioa.crh);
118+
64119
let ref_clk = gpioa.pa1.into_floating_input(&mut gpioa.crl);
65120
let md_io = gpioa.pa2.into_alternate_push_pull(&mut gpioa.crl);
66121
let crs = gpioa.pa7.into_floating_input(&mut gpioa.crl);

0 commit comments

Comments
 (0)