Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32H7XX support #70

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3d577bf
Convert to ring mode (instead of chain mode)
datdenkikniet Feb 1, 2023
e20ea4d
Type-state-ify Rx and Tx ring, and stop transmissions on drop
datdenkikniet Feb 2, 2023
388577e
Properly feature gate ptp::Timestamp import
datdenkikniet Feb 2, 2023
7850052
Getting timestamp does not have to be mutable
datdenkikniet Feb 2, 2023
d311ce5
Fix timestamp attaching logic for RxDescriptor and update rtic-timestamp
datdenkikniet Feb 2, 2023
26388b6
Initial H7 support
datdenkikniet Feb 3, 2023
a2e3061
Update some things
datdenkikniet Feb 4, 2023
e9828f4
Make f series compile again
datdenkikniet Feb 4, 2023
8e53e0d
Remove unnecessary assert
datdenkikniet Feb 4, 2023
96aa844
This doesn't need to be pub
datdenkikniet Feb 4, 2023
489e80d
Move responsiblity for getting timestamps from a descriptor to the de…
datdenkikniet Feb 4, 2023
64a44b1
Tentative PTP support on H7 as well :D
datdenkikniet Feb 4, 2023
9b7dc07
Also timestamp target time interrupt
datdenkikniet Feb 4, 2023
2066f70
Properly initialize rings (SRAM is not 0'd out by default!) and add
datdenkikniet Feb 4, 2023
bbb905d
Okay, so we really do need this: zeroing out the descriptors is impor…
datdenkikniet Feb 4, 2023
14a2f31
Faster clocks!
datdenkikniet Feb 4, 2023
886c6ba
Small fixes
datdenkikniet Feb 4, 2023
accc603
Now with RX timestamps
datdenkikniet Feb 4, 2023
3b4d04e
Remove these unnecessary things here
datdenkikniet Feb 4, 2023
cdd57b4
Add set_pps_freq to h7 as well
datdenkikniet Feb 5, 2023
0438352
Update to smoltcp 0.9 and incorporate all changes that we added with …
datdenkikniet Feb 8, 2023
df931cc
Add MIIM support to H7
datdenkikniet Feb 8, 2023
690a9d1
Add PPS pin implementations for H7
datdenkikniet Feb 8, 2023
261a476
Update rtic-echo from branch master
datdenkikniet Feb 8, 2023
81f80e4
Fix CIC bits in TX descriptor & enable more interrupts
datdenkikniet Feb 8, 2023
b2fd801
Make hclk/sysclk divisible with 8
datdenkikniet Feb 8, 2023
f50db4a
Clean up TX descriptors a little
datdenkikniet Feb 9, 2023
486c2ad
This is a PTP-only function
datdenkikniet Feb 9, 2023
ad3e893
Merge branch 'master' into h7
datdenkikniet Feb 9, 2023
7f79c40
Update Cargo.toml
datdenkikniet Feb 9, 2023
900536c
Fix compilation of examples
datdenkikniet Feb 9, 2023
079941f
Kind of fix pktgen example
datdenkikniet Feb 9, 2023
c813db0
Update Cargo.toml with all H7 features and add github workflows
datdenkikniet Feb 9, 2023
7de9731
Add nucleo/default pin setups for H7
datdenkikniet Feb 9, 2023
9478597
Add some more TODOs
datdenkikniet Feb 10, 2023
f211956
Fix README example
datdenkikniet Feb 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ jobs:
- stm32f777
- stm32f778
- stm32f779
- stm32h735
- stm32h742
- stm32h742v
- stm32h743
- stm32h743v
- stm32h747cm7
- stm32h750
- stm32h750v
- stm32h753
- stm32h753v
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -103,6 +113,7 @@ jobs:
- stm32f107
- stm32f407
- stm32f745
- stm32h735
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -138,6 +149,7 @@ jobs:
- stm32f107
- stm32f429
- stm32f745
- stm32h735
toolchain:
- stable
target:
Expand Down
19 changes: 19 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ stm32f7xx-hal = { version = "0.7.0", optional = true }
stm32f4xx-hal = { version = "0.14", optional = true }
stm32f4 = { version = "0.15", optional = true }
stm32f1xx-hal = { version = "0.10", optional = true }
stm32h7xx-hal = { version = "0.13", optional = true }
ieee802_3_miim = "0.8"
cortex-m = "0.7"
log = { version = "0.4", optional = true }
Expand All @@ -40,6 +41,12 @@ default = [ "defmt", "ptp" ]
device-selected = []
fence = []
ptp = [ ]
f-series = [ ]

stm32f1xx-hal = [ "dep:stm32f1xx-hal", "f-series" ]
stm32f4xx-hal = [ "dep:stm32f4xx-hal", "f-series" ]
stm32f7xx-hal = [ "dep:stm32f7xx-hal", "f-series" ]
stm32h7xx-hal = [ "dep:stm32h7xx-hal" ]

stm32f107 = ["stm32f1xx-hal/stm32f107", "device-selected"]

Expand All @@ -62,6 +69,17 @@ stm32f777 = ["stm32f7xx-hal/stm32f777", "device-selected", "fence"]
stm32f778 = ["stm32f7xx-hal/stm32f778", "device-selected", "fence"]
stm32f779 = ["stm32f7xx-hal/stm32f779", "device-selected", "fence"]

stm32h735 = ["device-selected", "fence", "stm32h7xx-hal/stm32h735", ]
stm32h742 = ["device-selected", "fence", "stm32h7xx-hal/stm32h742",]
stm32h742v = ["device-selected", "fence", "stm32h7xx-hal/stm32h742v"]
stm32h743 = ["device-selected", "fence", "stm32h7xx-hal/stm32h743"]
stm32h743v = ["device-selected", "fence", "stm32h7xx-hal/stm32h743v"]
stm32h747cm7 = ["device-selected", "fence", "stm32h7xx-hal/stm32h747cm7"]
stm32h750 = ["device-selected", "fence", "stm32h7xx-hal/stm32h750"]
stm32h750v = ["device-selected", "fence", "stm32h7xx-hal/stm32h750v"]
stm32h753 = ["device-selected", "fence", "stm32h7xx-hal/stm32h753"]
stm32h753v = ["device-selected", "fence", "stm32h7xx-hal/stm32h753v"]

smoltcp-phy = ["smoltcp"]

[dev-dependencies]
Expand All @@ -73,6 +91,7 @@ defmt-rtt = "0.4"
panic-probe = { version = "0.3", features = [ "print-defmt" ] }
systick-monotonic = "1.0"
smoltcp = { version = "0.9", features = [ "medium-ethernet", "proto-ipv4", "socket-udp", "socket-tcp", "defmt" ], default-features = false }
siphasher = "0.3"

[[example]]
name = "pktgen"
Expand Down
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ stm32-eth = { version = "0.3.0", features = ["stm32f107"] } # For stm32f107
In `src/main.rs` add:

```rust,no_run
use fugit::RateExtU32;
use stm32_eth::{
dma::{RxDescriptor, RxDescriptorRing, TxDescriptor, TxDescriptorRing},
hal::gpio::GpioExt,
hal::rcc::RccExt,
stm32::Peripherals,
dma::{RxRingEntry, TxRingEntry},
EthPins,
EthPins, MTU,
};
use fugit::RateExtU32;

fn main() {
let p = Peripherals::take().unwrap();
Expand All @@ -56,8 +56,13 @@ fn main() {
rx_d1: gpioc.pc5,
};

let mut rx_ring: [RxRingEntry; 16] = Default::default();
let mut tx_ring: [TxRingEntry; 8] = Default::default();
let mut rx_ring: [RxDescriptor; 16] = Default::default();
let mut rx_buffers: [[u8; MTU + 2]; 16] = [[0u8; MTU + 2]; 16];
let rx_ring = RxDescriptorRing::new(&mut rx_ring[..], &mut rx_buffers[..]);

let mut tx_ring: [TxDescriptor; 8] = Default::default();
let mut tx_buffers: [[u8; MTU + 2]; 8] = [[0u8; MTU + 2]; 8];
let tx_ring = TxDescriptorRing::new(&mut tx_ring[..], &mut tx_buffers[..]);

let parts = stm32_eth::PartsIn {
mac: p.ETHERNET_MAC,
Expand All @@ -66,24 +71,23 @@ fn main() {
ptp: p.ETHERNET_PTP,
};

let stm32_eth::Parts { dma: mut eth_dma, mac: _, ptp: _ } = stm32_eth::new(
parts,
&mut rx_ring[..],
&mut tx_ring[..],
clocks,
eth_pins,
)
.unwrap();
let stm32_eth::Parts {
dma: mut eth_dma,
mac: _,
ptp: _,
} = stm32_eth::new(parts, rx_ring, tx_ring, clocks, eth_pins).unwrap();
eth_dma.enable_interrupt();

if let Ok(pkt) = eth_dma.recv_next(None) {
// handle received pkt
}

let size = 42;
eth_dma.send(size, None, |buf| {
// write up to `size` bytes into buf before it is being sent
}).expect("send");
eth_dma
.send(size, None, |buf| {
// write up to `size` bytes into buf before it is being sent
})
.expect("send");
}
```

Expand Down
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fn main() {
#[cfg(feature = "stm32f1xx-hal")]
println!("cargo:rustc-link-search=memory.x");

let hse = std::env::var("STM32_ETH_EXAMPLE_HSE");
Expand Down
38 changes: 24 additions & 14 deletions examples/arp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![no_main]

use defmt_rtt as _;
use ieee802_3_miim::{phy::BarePhy, Phy};
use panic_probe as _;

use core::cell::RefCell;
Expand All @@ -16,14 +17,13 @@ use cortex_m_rt::{entry, exception};

use cortex_m::interrupt::Mutex;
use stm32_eth::{
mac::{phy::BarePhy, Phy},
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
Parts,
};

pub mod common;

use stm32_eth::dma::{RxRingEntry, TxError, TxRingEntry};
use stm32_eth::dma::TxError;

const PHY_ADDR: u8 = 0;

Expand All @@ -43,22 +43,14 @@ fn main() -> ! {

let (eth_pins, mdio, mdc, _) = common::setup_pins(gpio);

let mut rx_ring: [RxRingEntry; 2] = Default::default();
let mut tx_ring: [TxRingEntry; 2] = Default::default();
let (tx_ring, rx_ring) = crate::common::setup_rings();

let Parts {
mut dma,
mac,
#[cfg(feature = "ptp")]
ptp: _,
} = stm32_eth::new(
ethernet,
&mut rx_ring[..],
&mut tx_ring[..],
clocks,
eth_pins,
)
.unwrap();
} = stm32_eth::new(ethernet, rx_ring, tx_ring, clocks, eth_pins).unwrap();
dma.enable_interrupt();

let mut last_link_up = false;
Expand Down Expand Up @@ -109,14 +101,32 @@ fn main() -> ! {
buf[38..42].copy_from_slice(&TARGET_IP);
});

loop {
use core::hash::{Hash, Hasher};

if let Ok(rx_packet) = dma.recv_next(None) {
let mut hasher = siphasher::sip::SipHasher::new();
rx_packet.hash(&mut hasher);

defmt::info!(
"Received {} bytes. Hash: {:016X}",
rx_packet.len(),
hasher.finish()
);
break;
}
}

match r {
Ok(()) => {
defmt::info!("ARP sent");
}
Err(TxError::WouldBlock) => defmt::info!("ARP failed"),
Err(TxError::WouldBlock) => {
defmt::info!("ARP failed. {}", dma.tx_state())
}
}
} else {
defmt::info!("Down");
// defmt::info!("Down");
}

cortex_m::interrupt::free(|cs| {
Expand Down
Loading