mirror of
https://github.com/apache/nuttx.git
synced 2026-10-02 11:48:02 +00:00
The MAC has a system time that is the base of the PTP hardware timestamps, but the driver never started it, and STM32_ETH_PTP only printed a warning. Add the registers of the timestamp unit and start the system time with the fine update method and the digital rollover, so that the nanoseconds count up to 10^9. The increment is 2 * 10^9 / HCLK ns, and the addend makes the update rate half of HCLK, which leaves room to trim the frequency in both directions. The time starts at zero right after the MAC reset, not with the MAC configuration, so it does not depend on the PHY having a link. The reset clears it, so it starts again each time the interface goes up. With STM32_ETH_PTP_GPIO, start the pulse-per-second output as a pulse train with a period of one second and a width of half of it, at the whole seconds of the system time. The fixed frequency mode of the MAC gives a pulse too short to be seen, so the flexible mode is used. The interrupt of the timestamp unit is not enabled in the MAC: it is set each time the target time of the PPS output is reached and is cleared by reading MACTSSR, which the interrupt handler does not do, so it would stay pending and keep the handler running until the network stops. Register /dev/ptp0 when CONFIG_PTP_CLOCK is set, so that a PTP daemon can read and set the system time and correct its frequency and its phase. The frequency is corrected by changing the addend, by up to 50% each way. A step of the time is added or subtracted with the update register; with the digital rollover a subtraction is programmed with the negated seconds and with 10^9 minus the nanoseconds. The pulse train counts by itself, so it does not follow a step of the system time and would be displaced by the same amount: after the time is set or stepped, it is started again at the next whole second. With HCLK at 200 MHz the system time advanced 10.0018 s while a host clock advanced 10.002 s, and the pulse train was seen on the pin. Reading, setting, steps of +0.5 s and -1.25 s and a change of 100 ppm were done through /dev/ptp0 on hardware, and the edges of the PPS output stayed at the whole seconds of the system time. Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com> Assisted-by: Claude:claude-sonnet-5 |
||
|---|---|---|
| .. | ||
| arm | ||
| arm64 | ||
| avr | ||
| ceva | ||
| dummy | ||
| hc | ||
| mips | ||
| misoc | ||
| or1k | ||
| renesas | ||
| risc-v | ||
| sim | ||
| sparc | ||
| tricore | ||
| x86 | ||
| x86_64 | ||
| xtensa | ||
| z16 | ||
| z80 | ||
| CMakeLists.txt | ||
| Kconfig | ||