Skip to content

Commit e1b8a5d

Browse files
author
Johannes Draaijer
committed
Fix README.md example code, and add doctest for README that is also run by CI
1 parent fa39a12 commit e1b8a5d

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

README.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,34 @@ cargo build --example="ip-f107" --features="stm32f107 smoltcp-phy log smoltcp/so
2020

2121
## Usage
2222

23-
Add to the `[dependencies]` section in your `Cargo.toml`:
23+
Add one of the following to the `[dependencies]` section in your `Cargo.toml` (with the correct MCU specified):
2424

25-
```rust
26-
stm32f4xx-hal = { version = "0.10.1", features = ["stm32f429"] }
27-
stm32-eth = { version = "0.2.0", features = ["stm32f429"] }
25+
```toml
26+
stm32-eth = { version = "0.3.0", features = ["stm32f429"] } # For stm32f4xx-like MCUs
27+
stm32-eth = { version = "0.3.0", features = ["stm32f767"] } # For stm32f7xx-like MCUs
28+
stm32-eth = { version = "0.3.0", features = ["stm32f107"] } # For stm32f107
2829
```
2930

30-
or
31-
32-
```rust
33-
stm32f7xx-hal = { version = "0.6.0", features = ["stm32f767"] }
34-
stm32-eth = { version = "0.2.0", features = ["stm32f767"]}
35-
```
31+
`stm32_eth` re-exports the underlying HAL as `stm32_eth::hal`.
3632

3733
In `src/main.rs` add:
3834

39-
```rust
35+
```rust,no_run
4036
use stm32_eth::{
4137
hal::gpio::GpioExt,
4238
hal::rcc::RccExt,
4339
stm32::Peripherals,
40+
RingEntry,
41+
EthPins,
4442
};
45-
46-
47-
use stm32_eth::{RingEntry};
43+
use fugit::RateExtU32;
4844
4945
fn main() {
5046
let p = Peripherals::take().unwrap();
5147
5248
let rcc = p.RCC.constrain();
5349
// HCLK must be at least 25MHz to use the ethernet peripheral
54-
let clocks = rcc.cfgr.sysclk(32.mhz()).hclk(32.mhz()).freeze();
50+
let clocks = rcc.cfgr.sysclk(32.MHz()).hclk(32.MHz()).freeze();
5551
5652
let gpioa = p.GPIOA.split();
5753
let gpiob = p.GPIOB.split();
@@ -60,8 +56,6 @@ fn main() {
6056
6157
let eth_pins = EthPins {
6258
ref_clk: gpioa.pa1,
63-
md_io: gpioa.pa2,
64-
md_clk: gpioc.pc1,
6559
crs: gpioa.pa7,
6660
tx_en: gpiog.pg11,
6761
tx_d0: gpiog.pg13,
@@ -74,6 +68,7 @@ fn main() {
7468
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
7569
let (mut eth_dma, _eth_mac) = stm32_eth::new(
7670
p.ETHERNET_MAC,
71+
p.ETHERNET_MMC,
7772
p.ETHERNET_DMA,
7873
&mut rx_ring[..],
7974
&mut tx_ring[..],
@@ -83,10 +78,11 @@ fn main() {
8378
.unwrap();
8479
eth_dma.enable_interrupt();
8580
86-
if let Ok(pkt) = eth.recv_next() {
81+
if let Ok(pkt) = eth_dma.recv_next() {
8782
// handle received pkt
8883
}
8984
85+
let size = 42;
9086
eth_dma.send(size, |buf| {
9187
// write up to `size` bytes into buf before it is being sent
9288
}).expect("send");

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,17 @@ pub fn eth_interrupt_handler(eth_dma: &ETHERNET_DMA) {
369369
.dmasr
370370
.write(|w| w.nis().set_bit().rs().set_bit().ts().set_bit());
371371
}
372+
373+
/// This block ensures that README.md is checked when `cargo test` is run.
374+
///
375+
/// Taken from https://github.com/rp-rs/pio-rs/blob/b52d3ba9c031ffa72bdd6f16b5fa8c0c04f0e2e0/src/lib.rs#L963
376+
#[cfg(doctest)]
377+
mod test_readme {
378+
macro_rules! external_doc_test {
379+
($x:expr) => {
380+
#[doc = $x]
381+
extern "C" {}
382+
};
383+
}
384+
external_doc_test!(include_str!("../README.md"));
385+
}

0 commit comments

Comments
 (0)