Skip to content

Commit f87108b

Browse files
Merge pull request #72 from stm32-rs/ptp-example
Add PTP timesync example
2 parents d2d39ec + c130e0f commit f87108b

File tree

8 files changed

+702
-43
lines changed

8 files changed

+702
-43
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
run: |
9191
cargo build --release --target=${{ matrix.target }} --features ${{ matrix.features }}
9292
93-
build-ptp:
93+
build-no-ptp:
9494
name: build-no-ptp
9595
runs-on: ubuntu-20.04
9696
strategy:
@@ -117,7 +117,8 @@ jobs:
117117
run: |
118118
cargo build --release --target=${{ matrix.target }} --features ${{ matrix.features }} --no-default-features
119119
120-
# Examples
120+
# Test that all of the examples compile
121+
# for stm32f429
121122
examples:
122123
name: examples
123124
runs-on: ubuntu-20.04
@@ -134,21 +135,48 @@ jobs:
134135
features: smoltcp-phy
135136
- example: rtic-timestamp
136137
features: ""
138+
- example: timesync-server
139+
features: ptp
140+
- example: timesync-client
141+
features: ptp
142+
toolchain:
143+
- stable
144+
target:
145+
- thumbv7em-none-eabi
146+
steps:
147+
- name: Checkout
148+
uses: actions/checkout@v3
149+
150+
- name: Install Rust ${{ matrix.toolchain }} with target (${{ matrix.target }})
151+
run: |
152+
rustup set profile minimal
153+
rustup override set ${{ matrix.toolchain }}
154+
rustup target add ${{ matrix.target }}
155+
156+
- name: Build example ${{ matrix.example.example }} for stm32f429
157+
run: |
158+
cargo build --release --target=${{ matrix.target }} --example ${{ matrix.example.example }} --features stm32f429,${{ matrix.example.features }}
159+
160+
# Test that all the code shared with other MCU families also compiles
161+
examples-common:
162+
name: examples-common
163+
runs-on: ubuntu-20.04
164+
strategy:
165+
matrix:
166+
toolchain:
167+
- stable
168+
target:
169+
- thumbv7em-none-eabi
137170
mcu:
138171
- stm32f107
139172
- stm32f429
140173
- stm32f745
141-
toolchain:
142-
- stable
143-
target:
144-
- thumbv7m-none-eabi
145174
pins:
146175
- nucleo
147176
- default
148177
pps:
149178
- default
150179
- alternate
151-
152180
steps:
153181
- name: Checkout
154182
uses: actions/checkout@v3
@@ -159,9 +187,9 @@ jobs:
159187
rustup override set ${{ matrix.toolchain }}
160188
rustup target add ${{ matrix.target }}
161189
162-
- name: Build example ${{ matrix.example.example }} for ${{ matrix.mcu }}, eth pins ${{ matrix.pins }}, pps pin ${{ matrix.pps }}
190+
- name: Build examples common file for ${{ matrix.mcu }}, eth pins ${{ matrix.pins }}, pps pin ${{ matrix.pps }}
163191
run: |
164-
STM32_ETH_EXAMPLE_PPS=${{ matrix.pps }} STM32_ETH_EXAMPLE_PINS=${{ matrix.pins }} cargo build --release --target=${{ matrix.target }} --example ${{ matrix.example.example}} --features ${{ matrix.mcu }},${{ matrix.example.features }}
192+
STM32_ETH_EXAMPLE_PPS_PIN=${{ matrix.pps}} STM32_ETH_EXAMPLE_PINS=${{ matrix.pins }} cargo check --release --target=${{ matrix.target }} --example common --features ${{ matrix.mcu }},defmt,smoltcp-phy,ptp
165193
166194
# Refs: https://github.com/rust-lang/crater/blob/9ab6f9697c901c4a44025cf0a39b73ad5b37d198/.github/workflows/bors.yml#L125-L149
167195
#
@@ -175,6 +203,8 @@ jobs:
175203
- build
176204
- test
177205
- examples
206+
- examples-common
207+
- build-no-ptp
178208
runs-on: ubuntu-20.04
179209
steps:
180210
- name: Mark the job as a success

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
2-
* Update to `smoltcp` v0.9 [#71](https://github.com/stm32-rs/stm32-eth/pull/71).
2+
* Update to `smoltcp` v0.9 ([#71](https://github.com/stm32-rs/stm32-eth/pull/71))
3+
* Add `timesync-server` and `timesync-client` examples ([#72](https://github.com/stm32-rs/stm32-eth/pull/72))
34

45
## [0.4.1](https://github.com/stm32-rs/stm32-eth/tree/v0.4.1)
56
* Fix a bug when caching timestamps in the TX path ([#73](https://github.com/stm32-rs/stm32-eth/pull/73))

Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ panic-probe = { version = "0.3", features = [ "print-defmt" ] }
7474
systick-monotonic = "1.0"
7575
smoltcp = { version = "0.9", features = [ "medium-ethernet", "proto-ipv4", "socket-udp", "socket-tcp", "defmt" ], default-features = false }
7676

77+
# This isn't an actual example. It just exists so we can easily
78+
# test the common items :)
79+
[[example]]
80+
name = "common"
81+
required-features = ["defmt", "smoltcp-phy", "ptp"]
82+
7783
[[example]]
7884
name = "pktgen"
7985
required-features = [ "defmt" ]
@@ -94,6 +100,16 @@ required-features = [ "defmt" , "smoltcp-phy" ]
94100
name = "rtic-timestamp"
95101
required-features = [ "defmt", "ptp" ]
96102

103+
[[example]]
104+
name = "timesync-client"
105+
path = "./examples/timesync/client.rs"
106+
required-features = [ "defmt", "ptp" ]
107+
108+
[[example]]
109+
name = "timesync-server"
110+
path = "./examples/timesync/server.rs"
111+
required-features = [ "defmt", "ptp" ]
112+
97113
[profile.release]
98114
debug = 2
99115
lto = true

examples/common.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#![allow(unused_attributes)]
2+
#![no_std]
23

34
//! Common features used in examples.
45
//!
56
//! Note that this module isn't an example by itself.
67
8+
use defmt_rtt as _;
9+
use panic_probe as _;
10+
711
use stm32_eth::{
812
hal::{gpio::GpioExt, rcc::Clocks},
913
PartsIn,
@@ -14,6 +18,12 @@ pub use pins::{setup_pins, Gpio};
1418
use fugit::RateExtU32;
1519
use stm32_eth::hal::rcc::RccExt;
1620

21+
// This is here so that we can build the `common.rs` example individually for
22+
// each supported MCU family. That way we can be reasonably sure that all examples
23+
// compile, without having to compile all of them each time.
24+
#[allow(unused)]
25+
fn main() {}
26+
1727
/// Setup the clocks and return clocks and a GPIO struct that
1828
/// can be used to set up all of the pins.
1929
///

0 commit comments

Comments
 (0)