@@ -48,7 +48,7 @@ mod app {
4848 } ,
4949 mac:: Speed ,
5050 ptp:: { EthernetPTP , Timestamp } ,
51- Parts ,
51+ Parts , MTU ,
5252 } ;
5353
5454 #[ local]
@@ -65,19 +65,27 @@ mod app {
6565 #[ monotonic( binds = SysTick , default = true ) ]
6666 type Monotonic = Systick < 1000 > ;
6767
68- #[ init( local = [
69- rx_desc: [ RxDescriptor ; 2 ] = [ RxDescriptor :: new( ) ; 2 ] ,
70- tx_desc: [ TxDescriptor ; 2 ] = [ TxDescriptor :: new( ) ; 2 ] ,
71- rx_buffers: [ [ u8 ; 1522 ] ; 2 ] = [ [ 0u8 ; stm32_eth:: MTU ] ; 2 ] ,
72- tx_buffers: [ [ u8 ; 1522 ] ; 2 ] = [ [ 0u8 ; stm32_eth:: MTU ] ; 2 ] ,
73- ] ) ]
68+ /// On H7s, the ethernet DMA does not have access to the normal ram
69+ /// so we must explicitly put them in SRAM.
70+ #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth" ) ]
71+ static mut TX_DESCRIPTORS : [ TxDescriptor ; 4 ] = [ TxDescriptor :: new ( ) ; 4 ] ;
72+ #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth" ) ]
73+ static mut TX_BUFFERS : [ [ u8 ; MTU + 2 ] ; 4 ] = [ [ 0u8 ; MTU + 2 ] ; 4 ] ;
74+ #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth2" ) ]
75+ static mut RX_DESCRIPTORS : [ RxDescriptor ; 4 ] = [ RxDescriptor :: new ( ) ; 4 ] ;
76+ #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth2" ) ]
77+ static mut RX_BUFFERS : [ [ u8 ; MTU + 2 ] ; 4 ] = [ [ 0u8 ; MTU + 2 ] ; 4 ] ;
78+
79+ #[ init]
7480 fn init ( cx : init:: Context ) -> ( Shared , Local , init:: Monotonics ) {
7581 defmt:: info!( "Pre-init" ) ;
7682 let core = cx. core ;
7783 let p = cx. device ;
7884
79- let rx_ring = RxDescriptorRing :: new ( cx. local . rx_desc , cx. local . rx_buffers ) ;
80- let tx_ring = TxDescriptorRing :: new ( cx. local . tx_desc , cx. local . tx_buffers ) ;
85+ let rx_ring =
86+ RxDescriptorRing :: new ( unsafe { & mut RX_DESCRIPTORS } , unsafe { & mut RX_BUFFERS } ) ;
87+ let tx_ring =
88+ TxDescriptorRing :: new ( unsafe { & mut TX_DESCRIPTORS } , unsafe { & mut TX_BUFFERS } ) ;
8189
8290 let ( clocks, gpio, ethernet) = crate :: common:: setup_peripherals ( p) ;
8391 let mono = Systick :: new ( core. SYST , clocks. hclk ( ) . raw ( ) ) ;
@@ -88,13 +96,15 @@ mod app {
8896 defmt:: info!( "Configuring ethernet" ) ;
8997
9098 let Parts { dma, mac, mut ptp } =
91- stm32_eth:: new_with_mii ( ethernet, rx_ring, tx_ring, clocks, pins, mdio , mdc ) . unwrap ( ) ;
99+ stm32_eth:: new ( ethernet, rx_ring, tx_ring, clocks, pins) . unwrap ( ) ;
92100
101+ #[ cfg( not( feature = "stm32h7xx-hal" ) ) ]
93102 ptp. enable_pps ( pps) ;
94103
95104 defmt:: info!( "Enabling interrupts" ) ;
96105 dma. enable_interrupt ( ) ;
97106
107+ #[ cfg( not( feature = "stm32h7xx-hal" ) ) ]
98108 match EthernetPhy :: from_miim ( mac, 0 ) {
99109 Ok ( mut phy) => {
100110 defmt:: info!(
@@ -151,14 +161,15 @@ mod app {
151161 // incorrect, but works well enough in low-activity systems (such as this example).
152162 let now = ( cx. shared . ptp , cx. shared . scheduled_time ) . lock ( |ptp, sched_time| {
153163 let now = ptp. get_time ( ) ;
154- #[ cfg( not( feature = "stm32f107" ) ) ]
164+ #[ cfg( not( any ( feature = "stm32f107" , feature = "stm32h7xx-hal" ) ) ) ]
155165 {
156166 let in_half_sec = now
157167 + Timestamp :: new (
158168 false ,
159169 0 ,
160170 stm32_eth:: ptp:: Subseconds :: new_from_nanos ( 500_000_000 ) . unwrap ( ) ,
161171 ) ;
172+
162173 ptp. configure_target_time_interrupt ( in_half_sec) ;
163174 }
164175 * sched_time = Some ( now) ;
@@ -201,7 +212,7 @@ mod app {
201212 . lock ( |dma, tx_id, ptp, _sched_time| {
202213 dma. interrupt_handler ( ) ;
203214
204- #[ cfg( not( feature = "stm32f107" ) ) ]
215+ #[ cfg( not( any ( feature = "stm32f107" , feature = "stm32h7xx-hal" ) ) ) ]
205216 {
206217 if ptp. interrupt_handler ( ) {
207218 if let Some ( sched_time) = _sched_time. take ( ) {
0 commit comments