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

Ptp #444

Open
wants to merge 78 commits into
base: master
Choose a base branch
from
Open

Ptp #444

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9ab5ffd
Added ptp changes from stm32-eth h7-take2 branch
ZachParallel Jul 28, 2023
313cefc
Removed default features
ZachParallel Jul 28, 2023
a2d53a6
Removed unused lifetime from Devive impl
ZachParallel Jul 28, 2023
f9ee699
Added the a lifetime back
ZachParallel Jul 28, 2023
5fe9187
Removed a
ZachParallel Jul 28, 2023
d7eae1f
Muttable reference DMA
ZachParallel Jul 28, 2023
051785f
Added a
ZachParallel Jul 31, 2023
3541cab
Explicit Device
ZachParallel Jul 31, 2023
5012a2d
Added ptp feature
ZachParallel Jul 31, 2023
b4bea4d
PTP error correction
ZachParallel Jul 31, 2023
29fbfc4
Added defmt info comments
ZachParallel Aug 1, 2023
3a200ec
Removed info
ZachParallel Aug 1, 2023
5aac15b
Add defmt feature
ZachParallel Aug 1, 2023
ee4cd73
Change
ZachParallel Aug 1, 2023
3149dd3
Change
ZachParallel Aug 1, 2023
7e52521
Change
ZachParallel Aug 1, 2023
30bf9dd
Fix defmt
ZachParallel Aug 1, 2023
d37828a
Change
ZachParallel Aug 1, 2023
73a631c
Change
ZachParallel Aug 1, 2023
417b719
Change
ZachParallel Aug 1, 2023
91bf810
Change
ZachParallel Aug 1, 2023
6656b19
Change
ZachParallel Aug 1, 2023
767916e
Change
ZachParallel Aug 1, 2023
6f6ff4c
Change
ZachParallel Aug 1, 2023
c94dc1a
Removed register setting that did not exist in stm32-eth
ZachParallel Aug 1, 2023
b7b0445
Change
ZachParallel Aug 1, 2023
e498306
Added PTP instance
ZachParallel Aug 1, 2023
fe78ddc
Added Parts
ZachParallel Aug 1, 2023
7c9b04c
Working timestamping hal
ZachParallel Aug 1, 2023
7e3d205
Removed uncessary defmt
ZachParallel Aug 2, 2023
9d17c47
Converted totoal nanos to i128
ZachParallel Aug 7, 2023
b1ca3a4
Converted totoal nanos to u64
ZachParallel Aug 7, 2023
a7d9adb
Error corrected total_nanos
ZachParallel Aug 7, 2023
82eda19
Added safe add functionality to timestamp
ZachParallel Aug 7, 2023
a51e083
Changed how time was set
ZachParallel Aug 7, 2023
25f9878
Test
ZachParallel Aug 18, 2023
8a7b44c
Removed poor comments and unused imports as well as added the async f…
ZachParallel Aug 21, 2023
2dffefc
adding device impl for ethernetdma value (not ref) as well
Aug 28, 2023
44f43ae
adding missing token impls
Aug 28, 2023
c02c47d
setting packet_id in transmit
Aug 28, 2023
dfac2f2
fixing dma impls
Aug 31, 2023
8bfee82
adding func to enable multicast
Sep 7, 2023
01d0a7e
fixing multicast bug
Sep 7, 2023
bff29fb
removing impl on dma ref
Sep 14, 2023
0eb4fce
capturing and saving ptp frames
Sep 18, 2023
a8e67cb
importing networkendian
Sep 18, 2023
e5f5e36
bug fixes
Sep 20, 2023
37b7f4e
more bug fixes
Sep 20, 2023
02a2fb9
more bug fixes
Sep 20, 2023
ec574c8
adding functions to access ptp frames
Sep 20, 2023
1b10cf9
adding lifetime removing networkendian usage
Sep 20, 2023
2d9a212
adding send ptp frame func
Sep 20, 2023
e0083f6
devie import error fix
Sep 20, 2023
f804473
Revert "removing impl on dma ref"
Sep 20, 2023
f8c8f2e
adding ptp frame buf for dma ref impl
Sep 20, 2023
98597be
ptp send uses frame length to copy
Sep 20, 2023
0f0c47c
adding credit to @datdenkikniet (Johannes Draaijer)
Sep 21, 2023
b64d97a
moving comment to prevent error
Sep 21, 2023
d324c1e
some clippy fixes
Oct 2, 2023
3422177
cargo fmt
Oct 2, 2023
0d74740
adding copy for ptpframewithid
Oct 2, 2023
c093c47
adding clone
Oct 2, 2023
e7b7925
adding clippy allows
Oct 2, 2023
ba4fd99
nucleo example fix
Oct 2, 2023
79fedc6
735 fix
Oct 2, 2023
c00cebc
cargo fmt
Oct 2, 2023
986170e
adding desc num
Oct 2, 2023
ad717ef
clippy passing
Oct 2, 2023
ad8f8b4
fmt
Oct 2, 2023
e687a30
removing bad defaults
Oct 2, 2023
6638912
fixing all ci micro checks/examples
Oct 2, 2023
ec81090
clippy check fix
Oct 2, 2023
8e4fb54
Merge branch 'stm32-rs:master' into ptp
HarishgunaS Oct 2, 2023
cca418f
fixing 735 example
Oct 2, 2023
bb7b50c
fmt
Oct 2, 2023
43e2854
export ptpframewithid
Oct 3, 2023
3fbfee4
making struct fields pub
Oct 3, 2023
d6d268f
fmt
Oct 3, 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
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
],
"rust-analyzer.check.allTargets": false,
"rust-analyzer.check.targets": "thumbv7em-none-eabihf",
}
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
"./Cargo.toml",
"./Cargo.toml",
"./Cargo.toml"
],
}
117 changes: 90 additions & 27 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[package]
name = "stm32h7xx-hal"
version = "0.14.0"
authors = ["Andrew Straw <[email protected]>",
"Richard Meadows <[email protected]>",
"Henrik Böving <[email protected]>",
"Jan Adä <[email protected]>",
"Robert Jördens <[email protected]>",
"Ryan Summers <[email protected]>",
"Matthew Meyer <[email protected]>",
"Florian Jung <[email protected]>",
"Matt Ickstadt <[email protected]>"]
authors = [
"Andrew Straw <[email protected]>",
"Richard Meadows <[email protected]>",
"Henrik Böving <[email protected]>",
"Jan Adä <[email protected]>",
"Robert Jördens <[email protected]>",
"Ryan Summers <[email protected]>",
"Matthew Meyer <[email protected]>",
"Florian Jung <[email protected]>",
"Matt Ickstadt <[email protected]>",
]
edition = "2021"
rust-version = "1.65"
categories = ["embedded", "hardware-support", "no-std"]
Expand All @@ -22,7 +24,24 @@ readme = "README.md"
exclude = [".gitignore"]

[package.metadata.docs.rs]
features = ["stm32h743v", "rt", "xspi", "sdmmc", "sdmmc-fatfs", "fmc", "usb_hs", "rtc", "ethernet", "ltdc", "crc", "rand", "can", "defmt", "log", "fugit/defmt"]
features = [
"stm32h743v",
"rt",
"xspi",
"sdmmc",
"sdmmc-fatfs",
"fmc",
"usb_hs",
"rtc",
"ethernet",
"ltdc",
"crc",
"rand",
"can",
"defmt",
"log",
"fugit/defmt",
]
targets = ["thumbv7em-none-eabihf"]
rustdoc-args = ["--cfg", "docsrs"]

Expand All @@ -41,11 +60,15 @@ bare-metal = "1.0.0"
sdio-host = { version = "0.9", optional = true }
embedded-sdmmc = { version = "0.5", optional = true }
stm32-fmc = { version = "0.3", optional = true }
synopsys-usb-otg = { version = "^0.3.0", features = ["cortex-m"], optional = true }
volatile-register = "0.2"
synopsys-usb-otg = { version = "^0.3.0", features = [
"cortex-m",
], optional = true }
embedded-display-controller = { version = "^0.1.0", optional = true }
log = { version = "0.4.14", optional = true} # see also the dev-dependencies section
log = { version = "0.4.14", optional = true } # see also the dev-dependencies section
fdcan = { version = "0.2", optional = true }
embedded-storage = "0.3"
futures = { version = "0.3", default-features = false, features = ["async-await"], optional = true }

[dependencies.smoltcp]
version = "0.10.0"
Expand All @@ -72,7 +95,11 @@ panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] }
cfg-if = "1.0.0"
rtt-target = "0.4.0"
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
cortex-m-log = { version = "0.8.0", features = ["itm", "semihosting", "log-integration"] }
cortex-m-log = { version = "0.8.0", features = [
"itm",
"semihosting",
"log-integration",
] }
cortex-m-semihosting = "0.5.0"
panic-itm = { version = "~0.4.1" }
panic-semihosting = "0.6"
Expand All @@ -88,18 +115,22 @@ default-features = false
features = ["medium-ethernet", "proto-ipv4", "proto-ipv6", "socket-raw"]

[features]
default = ["rt"]
default = ["rt",
"ethernet",
"device-selected", "async-await"]
device-selected = []
revision_v = []
rm0433 = ["gpio-h747"] # aka. "single core" devices
rm0433 = ["gpio-h747"] # aka. "single core" devices
rm0399 = ["gpio-h747"] # TODO: fix gpio # aka. "dual core" devices
rm0455 = ["gpio-h7a2"] # aka. "high memory integration" devices
rm0468 = ["gpio-h72"] # aka. "high speed" devices
rm0455 = ["gpio-h7a2"] # aka. "high memory integration" devices
rm0468 = ["gpio-h72"] # aka. "high speed" devices

gpio-h72 = []
gpio-h747 = []
gpio-h7a2 = []

async-await = ["dep:futures"]
ptp = ["smoltcp/packetmeta-id"]
dsi = []
cm4 = []
cm7 = []
Expand All @@ -124,11 +155,43 @@ stm32h742v = ["stm32h7/stm32h743v", "device-selected", "revision_v", "rm0433"]
stm32h743v = ["stm32h7/stm32h743v", "device-selected", "revision_v", "rm0433"]
stm32h753v = ["stm32h7/stm32h753v", "device-selected", "revision_v", "rm0433"]
stm32h750v = ["stm32h7/stm32h743v", "device-selected", "revision_v", "rm0433"]
stm32h747cm7 = ["stm32h7/stm32h747cm7", "device-selected", "revision_v", "rm0399", "cm7", "dsi", "smps"]
stm32h7b3 = ["stm32h7/stm32h7b3", "device-selected", "revision_v", "rm0455", "smps"]
stm32h7b0 = ["stm32h7/stm32h7b3", "device-selected", "revision_v", "rm0455", "smps"]
stm32h7a3 = ["stm32h7/stm32h7b3", "device-selected", "revision_v", "rm0455", "smps"]
stm32h735 = ["stm32h7/stm32h735", "device-selected", "revision_v", "rm0468", "smps"] # Also applies to 723,725,730,733
stm32h747cm7 = [
"stm32h7/stm32h747cm7",
"device-selected",
"revision_v",
"rm0399",
"cm7",
"dsi",
"smps",
]
stm32h7b3 = [
"stm32h7/stm32h7b3",
"device-selected",
"revision_v",
"rm0455",
"smps",
]
stm32h7b0 = [
"stm32h7/stm32h7b3",
"device-selected",
"revision_v",
"rm0455",
"smps",
]
stm32h7a3 = [
"stm32h7/stm32h7b3",
"device-selected",
"revision_v",
"rm0455",
"smps",
]
stm32h735 = [
"stm32h7/stm32h735",
"device-selected",
"revision_v",
"rm0468",
"smps",
] # Also applies to 723,725,730,733
# Flags for examples
log-itm = []
log-rtt = []
Expand All @@ -137,15 +200,15 @@ example-smps = []
example-ldo = []

[profile.dev]
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size in flash
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size in flash
incremental = false

[profile.release]
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size in flash
lto = true # better optimizations
opt-level = "s" # optimize for binary size
debug = true # symbols are nice and they don't increase the size in flash
lto = true # better optimizations
opt-level = "s" # optimize for binary size

# The following examples do not build for all feature flag combinations. The
# `required-features` field specifies the hal features and/or the hardware
Expand Down
110 changes: 85 additions & 25 deletions examples/ethernet-nucleo-h743zi2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ mod utilities;
use log::info;

use stm32h7xx_hal::rcc::CoreClocks;
use stm32h7xx_hal::{ethernet, ethernet::PHY};
use stm32h7xx_hal::{
ethernet,
ethernet::{
RxDescriptor, RxDescriptorRing, TxDescriptor, TxDescriptorRing, MTU,
PHY,
},
};
use stm32h7xx_hal::{prelude::*, stm32, stm32::interrupt};

/// Configure SYSTICK for 1ms timebase
Expand All @@ -49,9 +55,24 @@ static TIME: AtomicU32 = AtomicU32::new(0);
/// Locally administered MAC address
const MAC_ADDRESS: [u8; 6] = [0x02, 0x00, 0x11, 0x22, 0x33, 0x44];

/// Ethernet descriptor rings are a global singleton
/// DesRing TD
const NUM_DESCRIPTORS: usize = 8;
#[link_section = ".sram3.eth"]
static mut DES_RING: ethernet::DesRing<4, 4> = ethernet::DesRing::new();
/// Doc
static mut TX_DESCRIPTORS: [TxDescriptor; NUM_DESCRIPTORS] =
[TxDescriptor::new(); NUM_DESCRIPTORS];
#[link_section = ".sram3.eth"]
/// Doc
static mut TX_BUFFERS: [[u8; MTU + 2]; NUM_DESCRIPTORS] =
[[0u8; MTU + 2]; NUM_DESCRIPTORS];
#[link_section = ".sram3.eth"]
/// Doc
static mut RX_DESCRIPTORS: [RxDescriptor; NUM_DESCRIPTORS] =
[RxDescriptor::new(); NUM_DESCRIPTORS];
#[link_section = ".sram3.eth"]
/// Doc
static mut RX_BUFFERS: [[u8; MTU + 2]; NUM_DESCRIPTORS] =
[[0u8; MTU + 2]; NUM_DESCRIPTORS];

// the program entry point
#[entry]
Expand Down Expand Up @@ -104,43 +125,82 @@ fn main() -> ! {
let rmii_txd0 = gpiog.pg13.into_alternate();
let rmii_txd1 = gpiob.pb13.into_alternate();

let rmii_pins = (
rmii_ref_clk,
rmii_mdio,
rmii_mdc,
rmii_crs_dv,
rmii_rxd0,
rmii_rxd1,
rmii_tx_en,
rmii_txd0,
rmii_txd1,
);
// Initialise ethernet...
assert_eq!(ccdr.clocks.hclk().raw(), 200_000_000); // HCLK 200MHz
assert_eq!(ccdr.clocks.pclk1().raw(), 100_000_000); // PCLK 100MHz
assert_eq!(ccdr.clocks.pclk2().raw(), 100_000_000); // PCLK 100MHz
assert_eq!(ccdr.clocks.pclk4().raw(), 100_000_000); // PCLK 100MHz

let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS);
let (_eth_dma, eth_mac) = unsafe {
ethernet::new(
dp.ETHERNET_MAC,
dp.ETHERNET_MTL,
dp.ETHERNET_DMA,
(
rmii_ref_clk,
rmii_mdio,
rmii_mdc,
rmii_crs_dv,
rmii_rxd0,
rmii_rxd1,
rmii_tx_en,
rmii_txd0,
rmii_txd1,
),
&mut DES_RING,
mac_addr,
ccdr.peripheral.ETH1MAC,
&ccdr.clocks,
let (rx_ring, tx_ring) = {
// let tx_desc = unsafe { TX_DESCRIPTORS.write([TxDescriptor::new(); NUM_DESCRIPTORS]) };
// let tx_buf = unsafe { TX_BUFFERS.write([[0u8; MTU + 2]; NUM_DESCRIPTORS]) };

// let rx_desc = unsafe { RX_DESCRIPTORS.write([RxDescriptor::new(); NUM_DESCRIPTORS]) };
// let rx_buf = unsafe { RX_BUFFERS.write([[0u8; MTU + 2]; NUM_DESCRIPTORS]) };

(
RxDescriptorRing::new(unsafe { &mut RX_DESCRIPTORS }, unsafe {
&mut RX_BUFFERS
}),
TxDescriptorRing::new(unsafe { &mut TX_DESCRIPTORS }, unsafe {
&mut TX_BUFFERS
}),
)
};

#[cfg(feature = "ptp")]
let ethernet::Parts {
dma: eth_dma,
mac: eth_mac,
ptp: _ptp,
} = ethernet::new(
dp.ETHERNET_MAC,
dp.ETHERNET_MTL,
dp.ETHERNET_DMA,
rmii_pins,
rx_ring,
tx_ring,
mac_addr,
ccdr.peripheral.ETH1MAC,
&ccdr.clocks,
);

#[cfg(not(feature = "ptp"))]
let ethernet::Parts {
dma: eth_dma,
mac: eth_mac,
} = ethernet::new(
dp.ETHERNET_MAC,
dp.ETHERNET_MTL,
dp.ETHERNET_DMA,
rmii_pins,
rx_ring,
tx_ring,
mac_addr,
ccdr.peripheral.ETH1MAC,
&ccdr.clocks,
);
// let start_addend = ptp.addend();
eth_dma.enable_interrupt();

// Initialise ethernet PHY...
let mut lan8742a = ethernet::phy::LAN8742A::new(eth_mac.set_phy_addr(0));
lan8742a.phy_reset();
lan8742a.phy_init();

unsafe {
ethernet::enable_interrupt();
cp.NVIC.set_priority(stm32::Interrupt::ETH, 196); // Mid prio
cortex_m::peripheral::NVIC::unmask(stm32::Interrupt::ETH);
}
Expand Down Expand Up @@ -180,7 +240,7 @@ fn main() -> ! {

#[interrupt]
fn ETH() {
unsafe { ethernet::interrupt_handler() }
ethernet::eth_interrupt_handler();
}

#[exception]
Expand Down
Loading