29.01.2015 Views

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Ethernet (ETH): media access control (MAC) with DMA controller<br />

RM0008<br />

The algorithm is as follows:<br />

●<br />

●<br />

At time MasterSyncTime (n) the master sends the slave clock a Sync message. The<br />

slave receives this message when its local clock is SlaveClockTime (n) <strong>and</strong> computes<br />

MasterClockTime (n) as:<br />

MasterClockTime (n) = MasterSyncTime (n) + MasterToSlaveDelay (n)<br />

The master clock count for current Sync cycle, MasterClockCount (n) is given by:<br />

MasterClockCount (n) = MasterClockTime (n) – MasterClockTime (n – 1) (assuming<br />

that MasterToSlaveDelay is the same for Sync cycles n <strong>and</strong> n – 1)<br />

● The slave clock count for current Sync cycle, SlaveClockCount (n) is given by:<br />

SlaveClockCount (n) = SlaveClockTime (n) – SlaveClockTime (n – 1)<br />

● The difference between master <strong>and</strong> slave clock counts for current Sync cycle,<br />

ClockDiffCount (n) is given by:<br />

ClockDiffCount (n) = MasterClockCount (n) – SlaveClockCount (n)<br />

● The frequency-scaling factor for slave clock, FreqScaleFactor (n) is given by:<br />

FreqScaleFactor (n) = (MasterClockCount (n) + ClockDiffCount (n)) /<br />

SlaveClockCount (n)<br />

● The frequency compensation value for Addend register, FreqCompensationValue (n) is<br />

given by:<br />

FreqCompensationValue (n) = FreqScaleFactor (n) × FreqCompensationValue (n – 1)<br />

In theory, this algorithm achieves lock in one Sync cycle; however, it may take several<br />

cycles, due to changing network propagation delays <strong>and</strong> operating conditions.<br />

This algorithm is self-correcting: if for any reason the slave clock is initially set to a value<br />

from the master that is incorrect, the algorithm corrects it at the cost of more Sync cycles.<br />

Programming steps for system time generation initialization<br />

Note:<br />

The time stamping feature can be enabled by setting bit 0 in the Time stamp control register<br />

(ETH__PTPTSCR). However, it is essential to initialize the time stamp counter after this bit<br />

is set to start time stamp operation. The proper sequence is the following:<br />

1. Mask the Time stamp trigger interrupt by setting bit 9 in the MACIMR register.<br />

2. Program Time stamp register bit 0 to enable time stamping.<br />

3. Program the Subsecond increment register based on the PTP clock frequency.<br />

4. If you are using the Fine correction method, program the Time stamp addend register<br />

<strong>and</strong> set Time stamp control register bit 5 (addend register update).<br />

5. Poll the Time stamp control register until bit 5 is cleared.<br />

6. To select the Fine correction method (if required), program Time stamp control register<br />

bit 1.<br />

7. Program the Time stamp high update <strong>and</strong> Time stamp low update registers with the<br />

appropriate time value.<br />

8. Set Time stamp control register bit 2 (Time stamp init).<br />

9. The Time stamp counter starts operation as soon as it is initialized with the value<br />

written in the Time stamp update register.<br />

10. Enable the MAC receiver <strong>and</strong> transmitter for proper time stamping.<br />

If time stamp operation is disabled by clearing bit 0 in the ETH_PTPTSCR register, the<br />

above steps must be repeated to restart the time stamp operation.<br />

876/995 Doc ID 13902 Rev 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!