@@ -343,17 +343,34 @@ impl EthernetPTP {
343343/// Setting and configuring target time interrupts on the STM32F107 does not
344344/// make any sense: we can generate the interrupt, but it is impossible to
345345/// clear the flag as the register required to do so does not exist.
346- #[ cfg( all( not( feature = "stm32f1xx-hal" ) , not ( feature = "stm32h7xx-hal" ) ) ) ]
346+ #[ cfg( all( not( feature = "stm32f1xx-hal" ) ) ) ]
347347impl EthernetPTP {
348348 /// Configure the target time.
349349 fn set_target_time ( & mut self , timestamp : Timestamp ) {
350350 let ( high, low) = ( timestamp. seconds ( ) , timestamp. subseconds_signed ( ) ) ;
351- self . eth_ptp
352- . ptptthr
353- . write ( |w| unsafe { w. ttsh ( ) . bits ( high) } ) ;
354- self . eth_ptp
355- . ptpttlr
356- . write ( |w| unsafe { w. ttsl ( ) . bits ( low) } ) ;
351+
352+ #[ cfg( feature = "f-series" ) ]
353+ {
354+ self . eth_ptp
355+ . ptptthr
356+ . write ( |w| unsafe { w. ttsh ( ) . bits ( high) } ) ;
357+ self . eth_ptp
358+ . ptpttlr
359+ . write ( |w| unsafe { w. ttsl ( ) . bits ( low) } ) ;
360+ }
361+
362+ #[ cfg( feature = "stm32h7xx-hal" ) ]
363+ {
364+ // SAFETY: we only write to `ppsttsr` (PPS target time seconds register) and
365+ // `ppsttnr` (PPS target time subseconds register)
366+ let ( ppsttsr, ppsttnr) = unsafe {
367+ let mac = self . mac ( ) ;
368+ ( & mac. macppsttsr , & mac. macppsttnr )
369+ } ;
370+
371+ ppsttsr. write ( |w| unsafe { w. bits ( high) } ) ;
372+ ppsttnr. write ( |w| unsafe { w. bits ( low) } ) ;
373+ }
357374 }
358375
359376 /// Configure the target time interrupt.
@@ -362,22 +379,40 @@ impl EthernetPTP {
362379 /// interrupt to detect (and clear) the correct status bits.
363380 pub fn configure_target_time_interrupt ( & mut self , timestamp : Timestamp ) {
364381 self . set_target_time ( timestamp) ;
365- self . eth_ptp . ptptscr . modify ( |_, w| w. tsite ( ) . set_bit ( ) ) ;
366- EthernetMAC :: unmask_timestamp_trigger_interrupt ( ) ;
382+ #[ cfg( feature = "f-series" ) ]
383+ {
384+ self . eth_ptp . ptptscr . modify ( |_, w| w. tsite ( ) . set_bit ( ) ) ;
385+ EthernetMAC :: unmask_timestamp_trigger_interrupt ( ) ;
386+ }
367387 }
368388
369389 /// Returns a boolean indicating whether or not the interrupt
370390 /// was caused by a Timestamp trigger and clears the interrupt
371391 /// flag.
372392 pub fn interrupt_handler ( & mut self ) -> bool {
373- let is_tsint = self . eth_ptp . ptptssr . read ( ) . tsttr ( ) . bit_is_set ( ) ;
374- if is_tsint {
375- self . eth_ptp . ptptscr . modify ( |_, w| w. tsite ( ) . clear_bit ( ) ) ;
376- EthernetMAC :: mask_timestamp_trigger_interrupt ( ) ;
377- }
393+ #[ cfg( feature = "f-series" ) ]
394+ let is_tsint = {
395+ let is_tsint = self . eth_ptp . ptptssr . read ( ) . tsttr ( ) . bit_is_set ( ) ;
396+ if is_tsint {
397+ self . eth_ptp . ptptscr . modify ( |_, w| w. tsite ( ) . clear_bit ( ) ) ;
398+ EthernetMAC :: mask_timestamp_trigger_interrupt ( ) ;
399+ }
400+ is_tsint
401+ } ;
402+
403+ #[ cfg( feature = "stm32h7xx-hal" ) ]
404+ let is_tsint = {
405+ // SAFETY: we only write to `mactssr` (Timestamp Status register)
406+ let mactssr = unsafe { & self . mac ( ) . mactssr } ;
407+
408+ // Reading the bit clears it, and deasserts the interrupt.
409+ mactssr. read ( ) . tstargt0 ( ) . bit_is_set ( )
410+ } ;
411+
378412 is_tsint
379413 }
380414
415+ #[ cfg( feature = "f-series" ) ]
381416 /// Configure the PPS output frequency.
382417 ///
383418 /// The PPS output frequency becomes `2 ^ pps_freq`. `pps_freq` is
0 commit comments