2025-05-02 1:05 AM
Hello
I’m busy with the implementation of PTP support inside my project.
I choose the STM32H745, because there is PTP support in hardware, with a nice offload function. After reading and try to understand the manual I create this code:
uint32_t SubSecondValue = 43;
#define ADJ_FREQ_BASE_ADDEND 0x35455A81
// Mask the Timestamp Trigger interrupt by clearing bit 12 of Interrupt enable register (ETH_MACIER).
heth->Instance->MACIER &= ~(ETH_MACIER_TSIE);
// Set bit 0 of Timestamp control Register (ETH_MACTSCR) to enable timestamping.
//heth->Instance->MACTSCR |= 1; // Done at the END! :)
//Program Subsecond increment register (ETH_MACSSIR) based on the PTP clock frequency.
heth->Instance->MACSSIR = (SubSecondValue<<16);
// if you use the Fine Correction method, program Timestamp addend register (ETH_MACTSAR) and set bit 5 of Timestamp control Register (ETH_MACTSCR)
heth->Instance->MACTSAR = ADJ_FREQ_BASE_ADDEND;
heth->Instance->MACTSCR |= ETH_MACTSCR_TSADDREG;
/* Poll the Time stamp control register until bit 5 is cleared. */
while(ETH_GetPTPFlagStatus(heth, ETH_PTP_FLAG_TSARU) == SET);
/* Enable the PTP Fine Update method Fine*/
heth->Instance->MACTSCR |= ETH_MACTSCR_TSCFUPDT;
/* Program the Time stamp high update and Time stamp low update registers
* with the appropriate time value. */
/* Set the PTP Time Update High Register */
heth->Instance->MACSTSUR = 0;
/* Set the PTP Time Update Low Register with sign */
heth->Instance->MACSTNUR = ETH_PTP_PositiveTime | 0;
/* Set Time stamp control register bit 2 (Time stamp init). */
heth->Instance->MACTSCR |= ETH_MACTSCR_TSINIT;
/* Set PPS frequency to 128 Hz */
heth->Instance->MACPPSCR = 7;
// Source: RM0399 Page 3039
// 1. Program SNAPTYPSEL, TSMSTRENA and TSEVNTENA fields of Timestamp control Register (ETH_MACTSCR) to 0, 0, and 1 respectively.
heth->Instance->MACTSCR &= ~((0b00)<<16); // Clear SNAPTYPSEL
heth->Instance->MACTSCR &= ~((0b0)<<15); // Clear TSMSTRENA
heth->Instance->MACTSCR |= (1 << 14); // Set TSEVNTENA
// 2. Program the PTOEN bit and DN field of PTP Offload control register (ETH_MACPOCR) to enable PTP Offload feature and domain Number to match with ingress PTP Sync message and send in egress PTP Delay_Req message.
heth->Instance->MACPOCR &= ~((0b00000000)<<8); // Set Domain number to 0
heth->Instance->MACPOCR |= 4; // Set APDREQEN
// 3. Program the 80-bit Source Port Identity in PTP Source Port Identity 0 Register (ETH_MACSPI0R), PTP Source port identity 1 register (ETH_MACSPI1R) and PTP Source port identity 2 register (ETH_MACSPI2R) to match with ingress PTP Sync message and send in egress PTP Delay_Req message.
heth->Instance->MACSPI0R = 0x57ffec79;
heth->Instance->MACSPI1R = 0xfe81d0c8;
heth->Instance->MACSPI2R = 0x0001;
// 4. Program the DRSYNCR field in Log message interval register (ETH_MACLMIR) to indicate one PTP Delay_Req message is generated in response to how many received PTP Sync messages.
heth->Instance->MACLMIR |= (2<<24);
heth->Instance->MACPOCR |= 1; // Set PTOEN
This code is called just before “low_level_init” returns.
What I try to do: I want to implement PTP Slave device that reacts on PTP message and try to synchronize the time inside the hardware counter. Without any software interaction, hardware offload.
When I sniff with Wireshark nothing happens, there is no communication send from the STM to the PTP master. What do I wrong?
My PTP master, is a off the shelve box specially made for PTP. The SYNC and Follow up data packets are sending though the network.
My ClockIdentity: 0xd0c857fffe81ec79
SourcePortID: 0x0001
2025-06-04 12:02 AM
Hello, any news on this?
I also want to enable the PTP offload feature on a STM32H7. I have a very similar code as the one showed by @JDWBE on the first post. I am testing with a linux machine running ptpd as master, and also can't see any messages in the network sent by the MCU. I would appreciate a working example on this, or maybe some advice.
2025-06-24 4:01 AM
Hello @rmolinete no news yet, no answer from ST, only there is no example available... strange but this is the truth.
I have no idea how i can try to debug my code, everything inside the registers looks fine. But nothing happens, so maybe a silicon-bug inside?
2025-06-24 4:17 AM
Are you 100% sure that your external PTP master is using PTP over ethernet, not the UDP version?
2025-06-25 1:54 AM
See here a screen capture from WireShark. For me it looks like PTP over ethernet.
2025-06-25 2:53 AM
No.
Problem found, check the Wireshark message: it is UDP.
Check if you can change the master to pure PTP over ethernet (Ethernet Type of an Ethernet-encapsulated PTP message is 0x88F7).
2025-06-25 5:30 AM - edited 2025-06-25 5:30 AM
Yes, those packets look like PTP over UDP.
If you want to go through Ethernet, I guess you should add MAC receive filters for PTP multicast address as well (check out "Packet filtering control register (ETH_MACPFR)" on the reference manual).
I've also done this but still could not manage to get the PTP offload functionality working.
2025-06-25 6:18 AM
I'm not sure if either I am or you are absolutely wrong here:
the H7's PTP offload hardware works ONLY with PTP over ethernet, no IP address multicast filtering will help if the master uses PTP with UDP. The "pure ethernet" packets don't even have any IP addresses, using MAC addresses only. Although it is using a MAC-multicast address (0x011B 1900 0000).
Check RM0468, chapter 63.5.4, last part is about PTP offload.
Maybe you should grab another H7 board and use its offload function and make it PTP master.
Which makes sense, as the H7 PTP offload only supports one-step timestamp syncing (no FOLLOW-UP messages from master), so the master must make sure that its SYNC messages include its correct hardware timestamp.
Which is given when using H7 PTP offload as master - or so I hope...
2025-06-26 5:43 AM
@LCE wrote:... using MAC addresses only. Although it is using a MAC-multicast address (0x011B 1900 0000).
That's what I said. To receive packets destined for a multicast MAC address, you should either enable the multicast bit (which would allow you to receive all packets destined to a MAC multicast address) or specifically add the desired MAC multicast address filter in the hash map. What is wrong about this?
Thank you for noticing that the offload feature only works using one-step timestamping, I wasn't taking that into account. I will have to check if I can do that with the PC I was using as a master. I will try using another H7 as master as well, and I will let you know if I make any progress.
2025-06-26 10:05 PM
I recently started my own thread, and I started playing with the PTP offload - without any success.
PTP offload H7: one-step timestamp from HW? - STMicroelectronics Community