Skip to content

Commit 8ebfe9c

Browse files
committed
More docs on the example
Add alternative pinout for nucleo board
1 parent 4be5253 commit 8ebfe9c

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ieee802_3_miim = { version = "0.7", optional = true }
2727
cortex-m = "0.7"
2828
log = { version = "0.4", optional = true }
2929

30-
# For rtic-telnet
30+
# For rtic-echo
3131
cortex-m-rtic = { version = "1.0", optional = true }
3232
defmt = { version = "0.3", optional = true }
3333
defmt-rtt = { version = "0.3", optional = true }
@@ -42,7 +42,7 @@ features = ["medium-ethernet", "proto-ipv4"]
4242
optional = true
4343

4444
[features]
45-
default = [ "ieee802_3_miim" ]
45+
default = [ "ieee802_3_miim", "defmt" ]
4646
device-selected = []
4747
fence = []
4848

@@ -69,6 +69,10 @@ stm32f779 = ["stm32f7xx-hal/stm32f779", "device-selected", "fence"]
6969

7070
smoltcp-phy = ["smoltcp"]
7171

72+
# Example features
73+
rtic-echo-example = [ "ieee802_3_miim", "cortex-m-rtic", "smoltcp-phy", "smoltcp/defmt", "smoltcp/medium-ethernet", "smoltcp/socket-tcp", "defmt", "defmt-rtt", "panic-probe", "systick-monotonic", "fugit" ]
74+
rtic-echo-example-altpin = [ ]
75+
7276
[dev-dependencies]
7377
cortex-m = "0.7"
7478
cortex-m-rt = "0.7"
@@ -104,7 +108,7 @@ required-features = ["stm32f407", "smoltcp-phy", "smoltcp/socket-icmp"]
104108

105109
[[example]]
106110
name = "rtic-echo"
107-
required-features = [ "ieee802_3_miim", "cortex-m-rtic", "smoltcp-phy", "smoltcp/defmt", "smoltcp/medium-ethernet", "smoltcp/socket-tcp", "defmt", "defmt-rtt", "panic-probe", "systick-monotonic", "fugit" ]
111+
required-features = [ "rtic-echo-example" ]
108112

109113
[profile.release]
110114
debug = 2

examples/rtic-echo.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#![no_std]
22
#![no_main]
33

4-
// A simple TCP echo server using RTIC
5-
//
6-
// To run, use the following command:
7-
// DEFMT_LOG=info PROBE_RUN_CHIP=<probe-run chip> cargo run --example rtic-echo --features <chip here> --target <correct target for chip> --release --features="cortex-m-rtic smoltcp-phy smoltcp/medium-ethernet smoltcp/socket-tcp defmt-rtt panic-probe systick-monotonic fugit defmt smoltcp/defmt"
4+
//! A simple TCP echo server using RTIC.
5+
//!
6+
//! Starts a TCP echo server on port `1337` at `ADDRESS`. `ADDRESS` is `10.0.0.1/24` by default.
7+
//!
8+
//! By default, the example assumes that the default RMII pins are used.
9+
//! To use it on an stm32-nucleo-f746zg dev board, the `rtic-echo-example-altpin` feature should be enabled. This may work on other
10+
//! boards, but that hasn't been tested so your mileage may vary.
11+
//!
12+
//! To run this, install `probe-run` (`cargo install probe-run --version '~0.3'`), and ensure that `probe-run` can
13+
//! attach to your test board.
14+
//! Then, use the following command:
15+
//! DEFMT_LOG=info PROBE_RUN_CHIP=<probe-run chip> cargo run --example rtic-echo --features <chip here>,rtic-echo-example --target <correct target for chip> --release
816
917
use defmt_rtt as _;
1018
use panic_probe as _;
@@ -160,14 +168,16 @@ mod app {
160168

161169
interface.poll(now_fn()).unwrap();
162170

163-
let mut phy = crate::EthernetPhy::from_miim(mac, 0).unwrap();
164-
165-
defmt::info!(
166-
"Resetting PHY as an extra step. Type: {}",
167-
phy.ident_string()
168-
);
171+
if let Ok(mut phy) = crate::EthernetPhy::from_miim(mac, 0) {
172+
defmt::info!(
173+
"Resetting PHY as an extra step. Type: {}",
174+
phy.ident_string()
175+
);
169176

170-
phy.phy_init();
177+
phy.phy_init();
178+
} else {
179+
defmt::info!("Not resetting unsupported PHY.");
180+
}
171181

172182
defmt::info!("Setup done.");
173183

@@ -262,18 +272,24 @@ mod pins {
262272
pub type RxD0 = PC4<Input>;
263273
pub type RxD1 = PC5<Input>;
264274

275+
#[cfg(not(feature = "rtic-echo-example-altpin"))]
265276
pub type TxEn = PB11<Input>;
277+
#[cfg(not(feature = "rtic-echo-example-altpin"))]
266278
pub type TxD0 = PB12<Input>;
267279

280+
#[cfg(all(feature = "rtic-echo-example-altpin"))]
281+
pub type TxEn = PG11<Input>;
282+
#[cfg(feature = "rtic-echo-example-altpin")]
283+
pub type TxD0 = PG13<Input>;
284+
268285
pub type Mdio = PA2<Alternate<11>>;
269286
pub type Mdc = PC1<Alternate<11>>;
270287

271-
#[allow(unused_variables)]
272288
pub fn get_pins(
273289
gpioa: gpioa::Parts,
274290
gpiob: gpiob::Parts,
275291
gpioc: gpioc::Parts,
276-
gpiog: gpiog::Parts,
292+
#[allow(unused_variables)] gpiog: gpiog::Parts,
277293
) -> (
278294
EthPins<RefClk, Crs, TxEn, TxD0, TxD1, RxD0, RxD1>,
279295
Mdio,
@@ -285,11 +301,18 @@ mod pins {
285301
let rx_d0 = gpioc.pc4.into_floating_input();
286302
let rx_d1 = gpioc.pc5.into_floating_input();
287303

304+
#[cfg(not(feature = "rtic-echo-example-altpin"))]
288305
let (tx_en, tx_d0) = (
289306
gpiob.pb11.into_floating_input(),
290307
gpiob.pb12.into_floating_input(),
291308
);
292309

310+
#[cfg(feature = "rtic-echo-example-altpin")]
311+
let (tx_en, tx_d0) = (
312+
gpiog.pg11.into_floating_input(),
313+
gpiog.pg13.into_floating_input(),
314+
);
315+
293316
#[cfg(feature = "stm32f4xx-hal")]
294317
let (mdio, mdc) = {
295318
let mut mdio = gpioa.pa2.into_alternate();
@@ -322,7 +345,6 @@ mod pins {
322345
}
323346

324347
#[cfg(any(feature = "stm32f1xx-hal"))]
325-
#[allow(missing_docs)]
326348
mod pins {
327349
use stm32_eth::{
328350
hal::gpio::{Alternate, Input, PushPull, *},

0 commit comments

Comments
 (0)