1- // cargo build --example arp-smoltcp --features=stm32f407,smi, smoltcp-phy,smoltcp/socket-tcp,smoltcp/socket-icmp
1+ // cargo build --example arp-smoltcp --features=stm32f407,smoltcp-phy,smoltcp/socket-tcp,smoltcp/socket-icmp
22// This example uses the STM32F407 and the KSZ8051R as PHY. If necessary the pins,
33// the PHY register addresses and masks have to be adapted, as well as the IPs.
44// With Wireshark, you can see the ARP packets, which should look like this:
@@ -25,14 +25,11 @@ use smoltcp::wire::{
2525use stm32_eth:: {
2626 hal:: gpio:: { GpioExt , Speed } ,
2727 hal:: rcc:: RccExt ,
28- smi ,
28+ mac :: { phy :: BarePhy , Phy } ,
2929 stm32:: { interrupt, CorePeripherals , Peripherals , SYST } ,
3030} ;
3131use stm32_eth:: { EthPins , RingEntry , TxError } ;
3232
33- const PHY_REG_BSR : u8 = 0x01 ;
34- const PHY_REG_BSR_UP : u16 = 1 << 2 ;
35-
3633const PHY_ADDR : u8 = 0 ;
3734
3835static TIME : Mutex < RefCell < usize > > = Mutex :: new ( RefCell :: new ( 0 ) ) ;
@@ -75,7 +72,7 @@ fn main() -> ! {
7572
7673 let mut rx_ring: [ RingEntry < _ > ; 16 ] = Default :: default ( ) ;
7774 let mut tx_ring: [ RingEntry < _ > ; 8 ] = Default :: default ( ) ;
78- let ( mut eth_dma, mut eth_mac) = stm32_eth:: new (
75+ let ( mut eth_dma, eth_mac) = stm32_eth:: new (
7976 p. ETHERNET_MAC ,
8077 p. ETHERNET_MMC ,
8178 p. ETHERNET_DMA ,
@@ -89,8 +86,10 @@ fn main() -> ! {
8986
9087 let mut last_link_up = false ;
9188
89+ let mut bare_phy = BarePhy :: new ( eth_mac. with_mii ( mdio, mdc) , PHY_ADDR , Default :: default ( ) ) ;
90+
9291 loop {
93- let link_up = link_detected ( eth_mac . smi ( & mut mdio , & mut mdc ) ) ;
92+ let link_up = bare_phy . phy_link_up ( ) ;
9493
9594 if link_up != last_link_up {
9695 if link_up {
@@ -179,12 +178,3 @@ fn ETH() {
179178 let p = unsafe { Peripherals :: steal ( ) } ;
180179 stm32_eth:: eth_interrupt_handler ( & p. ETHERNET_DMA ) ;
181180}
182-
183- fn link_detected < Mdio , Mdc > ( smi : smi:: Smi < Mdio , Mdc > ) -> bool
184- where
185- Mdio : smi:: MdioPin ,
186- Mdc : smi:: MdcPin ,
187- {
188- let status = smi. read ( PHY_ADDR , PHY_REG_BSR ) ;
189- ( status & PHY_REG_BSR_UP ) == PHY_REG_BSR_UP
190- }
0 commit comments