diff --git a/Cargo.lock b/Cargo.lock index d7bcb99..a74e07f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,9 +2,9 @@ # It is not intended for manual editing. [[package]] name = "aligned" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1ce8b3382016136ab1d31a1b5ce807144f8b7eb2d5f16b2108f0f07edceb94" +checksum = "c19796bd8d477f1a9d4ac2465b464a8b1359474f06a96bb3cda650b4fca309bf" dependencies = [ "as-slice", ] @@ -22,9 +22,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bare-metal" @@ -37,9 +37,15 @@ dependencies = [ [[package]] name = "bit_field" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a165d606cf084741d4ac3a28fb6e9b1eb0bd31f6cd999098cfddb0b2ab381dc0" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" [[package]] name = "bitflags" @@ -70,20 +76,21 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cortex-m" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763" +checksum = "2be99930c99669a74d986f7fd2162085498b322e6daae8ef63a97cc9ac1dc73c" dependencies = [ "aligned", "bare-metal", + "bitfield", "volatile-register", ] [[package]] name = "cortex-m-log" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978caafe65d1023d38b00c76b83564788fc351d954a5005fb72cf992c0d61458" +checksum = "1d63959cb1e003dd97233fee6762351540253237eadf06fcdcb98cbfa3f9be4a" dependencies = [ "cortex-m", "cortex-m-semihosting", @@ -122,11 +129,11 @@ dependencies = [ [[package]] name = "embedded-hal" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b" +checksum = "fa998ce59ec9765d15216393af37a58961ddcefb14c753b4816ba2191d865fcb" dependencies = [ - "nb", + "nb 0.1.3", "void", ] @@ -162,18 +169,18 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "log" -version = "0.4.8" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ "cfg-if", ] [[package]] name = "managed" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" +checksum = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" [[package]] name = "memchr" @@ -183,15 +190,24 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "nb" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.0.0", +] + +[[package]] +name = "nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" [[package]] name = "nom" -version = "5.1.1" +version = "5.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" dependencies = [ "memchr", "version_check", @@ -199,9 +215,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" dependencies = [ "autocfg", "libm", @@ -225,18 +241,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.9" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.3" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ "proc-macro2", ] @@ -291,17 +307,16 @@ dependencies = [ [[package]] name = "stable_deref_trait" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stm32-eth" -version = "0.1.2" -source = "git+https://github.com/stm32-rs/stm32-eth.git#2c5dce379b85a31fb0b9c58a028b6454be1727aa" +version = "0.2.0" dependencies = [ "aligned", - "log", + "cortex-m", "smoltcp", "stm32f4xx-hal", "volatile-register", @@ -309,9 +324,9 @@ dependencies = [ [[package]] name = "stm32f4" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44a3d6c58b14e63926273694e7dd644894513c5e35ce6928c4657ddb62cae976" +checksum = "11460b4de3a84f072e2cf6e76306c64d27f405a0e83bace0a726f555ddf4bf33" dependencies = [ "bare-metal", "cortex-m", @@ -321,15 +336,16 @@ dependencies = [ [[package]] name = "stm32f4xx-hal" -version = "0.7.0" -source = "git+https://github.com/thalesfragoso/stm32f4xx-hal?branch=pwm-impl#cfd073e094daa9be9dd2b0a1f859a4e1c6be2b77" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a2f044469d1e3aff2cd02bee8b2724f3d5d91f3175e5d1ec99770320d16192" dependencies = [ "bare-metal", "cast", "cortex-m", "cortex-m-rt", "embedded-hal", - "nb", + "nb 0.1.3", "rand_core", "stm32f4", "void", @@ -337,9 +353,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.17" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" +checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9" dependencies = [ "proc-macro2", "quote", @@ -369,15 +385,15 @@ dependencies = [ [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "vcell" @@ -387,9 +403,9 @@ checksum = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c" [[package]] name = "version_check" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "void" diff --git a/Cargo.toml b/Cargo.toml index fbee09d..0915b2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,8 @@ bare-metal = "0.2" cortex-m = "0.6" cortex-m-rt = { version = "0.6", features = ["device"] } cortex-m-log = { version = "0.6", features = ["log-integration"] } -stm32f4xx-hal = { version = "0.7", features = ["rt", "stm32f427"] } -stm32-eth = { version = "0.1.2", features = ["smoltcp-phy"], git = "https://github.com/stm32-rs/stm32-eth.git" } +stm32f4xx-hal = { version = "0.8", features = ["rt", "stm32f427"] } +stm32-eth = { version = "0.2", features = ["stm32f427", "smoltcp-phy"], git = "https://github.com/stm32-rs/stm32-eth.git" } smoltcp = { version = "0.6.0", default-features = false, features = ["proto-ipv4", "socket-tcp", "log"] } hash2hwaddr = { version = "0.0", optional = true } bit_field = "0.10" @@ -30,9 +30,6 @@ byteorder = { version = "1", default-features = false } nom = { version = "5", default-features = false } num-traits = { version = "0.2", default-features = false, features = ["libm"] } -[patch.crates-io] -# TODO: pending https://github.com/stm32-rs/stm32f4xx-hal/pull/125 -stm32f4xx-hal = { git = "https://github.com/thalesfragoso/stm32f4xx-hal", branch = "pwm-impl" } [features] semihosting = ["panic-semihosting", "cortex-m-log/semihosting"] diff --git a/src/main.rs b/src/main.rs index e8425ec..6a6d623 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,8 +74,6 @@ fn main() -> ! { cp.SCB.enable_dcache(&mut cp.CPUID); let dp = Peripherals::take().unwrap(); - stm32_eth::setup(&dp.RCC, &dp.SYSCFG); - let clocks = dp.RCC.constrain() .cfgr .use_hse(HSE) @@ -91,7 +89,7 @@ fn main() -> ! { timer::setup(cp.SYST, clocks); - let pins = Pins::setup( + let (pins, eth_pins) = Pins::setup( clocks, dp.TIM1, dp.TIM3, dp.GPIOA, dp.GPIOB, dp.GPIOC, dp.GPIOE, dp.GPIOF, dp.GPIOG, dp.SPI2, dp.SPI4, dp.SPI5, @@ -110,7 +108,7 @@ fn main() -> ! { }; info!("Net hwaddr: {}", hwaddr); - net::run(dp.ETHERNET_MAC, dp.ETHERNET_DMA, hwaddr, |iface| { + net::run(clocks, dp.ETHERNET_MAC, dp.ETHERNET_DMA, eth_pins, hwaddr, |iface| { Server::::run(iface, |server| { loop { let instant = Instant::from_millis(i64::from(timer::now())); diff --git a/src/net.rs b/src/net.rs index b42349a..5914373 100644 --- a/src/net.rs +++ b/src/net.rs @@ -5,11 +5,13 @@ use core::cell::RefCell; use cortex_m::interrupt::Mutex; use bare_metal::CriticalSection; use stm32f4xx_hal::{ + rcc::Clocks, stm32::{interrupt, Peripherals, ETHERNET_MAC, ETHERNET_DMA}, }; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr}; use smoltcp::iface::{NeighborCache, EthernetInterfaceBuilder, EthernetInterface}; -use stm32_eth::{Eth, RingEntry, RxDescriptor, TxDescriptor}; +use stm32_eth::{Eth, RingEntry, PhyAddress, RxDescriptor, TxDescriptor}; +use crate::pins::EthernetPins; /// Not on the stack so that stack can be placed in CCMRAM (which the /// ethernet peripheral cannot access) @@ -24,7 +26,9 @@ static NET_PENDING: Mutex> = Mutex::new(RefCell::new(false)); /// Run callback `f` with ethernet driver and TCP/IP stack pub fn run( + clocks: Clocks, ethernet_mac: ETHERNET_MAC, ethernet_dma: ETHERNET_DMA, + eth_pins: EthernetPins, ethernet_addr: EthernetAddress, f: F ) where F: FnOnce(EthernetInterface<&mut stm32_eth::Eth<'static, 'static>>), @@ -38,8 +42,11 @@ pub fn run( // Ethernet driver let mut eth_dev = Eth::new( ethernet_mac, ethernet_dma, - &mut rx_ring[..], &mut tx_ring[..] - ); + &mut rx_ring[..], &mut tx_ring[..], + PhyAddress::_0, + clocks, + eth_pins, + ).unwrap(); eth_dev.enable_interrupt(); // IP stack diff --git a/src/pins.rs b/src/pins.rs index 0269d92..54c2ce9 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -2,7 +2,7 @@ use stm32f4xx_hal::{ adc::Adc, hal::{blocking::spi::Transfer, digital::v2::OutputPin}, gpio::{ - AF5, Alternate, Analog, + AF5, Alternate, Analog, Floating, Input, gpioa::*, gpiob::*, gpioc::*, @@ -19,9 +19,22 @@ use stm32f4xx_hal::{ stm32::{ADC1, GPIOA, GPIOB, GPIOC, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3}, time::U32Ext, }; +use stm32_eth::EthPins; use crate::channel::{Channel0, Channel1}; +pub type EthernetPins = EthPins< + PA1>, + PA2>, + PC1>, + PA7>, + PB11>, + PG13>, + PB13>, + PC4>, + PC5>, + >; + pub trait ChannelPins { type DacSpi: Transfer; type DacSync: OutputPin; @@ -86,7 +99,7 @@ impl Pins { gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG, spi2: SPI2, spi4: SPI4, spi5: SPI5, adc1: ADC1, - ) -> Self { + ) -> (Self, EthernetPins) { let gpioa = gpioa.split(); let gpiob = gpiob.split(); let gpioc = gpioc.split(); @@ -94,11 +107,6 @@ impl Pins { let gpiof = gpiof.split(); let gpiog = gpiog.split(); - Self::setup_ethernet( - gpioa.pa1, gpioa.pa2, gpioc.pc1, gpioa.pa7, - gpioc.pc4, gpioc.pc5, gpiob.pb11, gpiog.pg13, - gpiob.pb13 - ); let adc_spi = Self::setup_spi_adc(clocks, spi2, gpiob.pb10, gpiob.pb14, gpiob.pb15); let adc_nss = gpiob.pb12.into_push_pull_output(); @@ -151,13 +159,27 @@ impl Pins { tec_u_meas_pin: tec_u_meas1_pin, }; - Pins { + let pins = Pins { adc_spi, adc_nss, pins_adc, pwm, channel0, channel1, - } + }; + + let eth_pins = EthPins { + ref_clk: gpioa.pa1, + md_io: gpioa.pa2, + md_clk: gpioc.pc1, + crs: gpioa.pa7, + tx_en: gpiob.pb11, + tx_d0: gpiog.pg13, + tx_d1: gpiob.pb13, + rx_d0: gpioc.pc4, + rx_d1: gpioc.pc5, + }; + + (pins, eth_pins) } /// Configure the GPIO pins for SPI operation, and initialize SPI @@ -216,32 +238,6 @@ impl Pins { (spi, sync) } - - /// Configure the GPIO pins for Ethernet operation - fn setup_ethernet( - pa1: PA1, pa2: PA2, pc1: PC1, pa7: PA7, - pc4: PC4, pc5: PC5, pb11: PB11, pg13: PG13, - pb13: PB13 - ) { - // PA1 RMII Reference Clock - SB13 ON - pa1.into_alternate_af11().set_speed(VeryHigh); - // PA2 RMII MDIO - SB160 ON - pa2.into_alternate_af11().set_speed(VeryHigh); - // PC1 RMII MDC - SB164 ON - pc1.into_alternate_af11().set_speed(VeryHigh); - // PA7 RMII RX Data Valid D11 JP6 ON - pa7.into_alternate_af11().set_speed(VeryHigh); - // PC4 RMII RXD0 - SB178 ON - pc4.into_alternate_af11().set_speed(VeryHigh); - // PC5 RMII RXD1 - SB181 ON - pc5.into_alternate_af11().set_speed(VeryHigh); - // PB11 RMII TX Enable - SB183 ON - pb11.into_alternate_af11().set_speed(VeryHigh); - // PG13 RXII TXD0 - SB182 ON - pg13.into_alternate_af11().set_speed(VeryHigh); - // PB13 RMII TXD1 I2S_A_CK JP7 ON - pb13.into_alternate_af11().set_speed(VeryHigh); - } } pub struct PwmPins {