Skip to content

PTP hardware clock using RTC#369

Open
ninjadrknss wants to merge 2 commits intomainfrom
feature/rtc-driver
Open

PTP hardware clock using RTC#369
ninjadrknss wants to merge 2 commits intomainfrom
feature/rtc-driver

Conversation

@ninjadrknss
Copy link
Contributor

@ninjadrknss ninjadrknss commented Feb 15, 2026

  • No merge conflicts
  • All checks passing
  • Request reviewers & ping on Slack

Closes #366

@ninjadrknss ninjadrknss self-assigned this Feb 15, 2026
@ninjadrknss
Copy link
Contributor Author

@jr1221 do you want me to also make a get time function using the PTP formate or just rely on the HAL getters?

@ninjadrknss ninjadrknss marked this pull request as ready for review February 15, 2026 23:06
@ninjadrknss
Copy link
Contributor Author

RTC config: LSE clock, FR BCD calendar mode, Clock and Calendar, ASync Pre-Scaler = 0, Sync Pre-Scaler = 32767 (to preserve 1 Hz ck_spre while maximizing sub second ticks)

Copy link
Contributor

@caiodasilva2005 caiodasilva2005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good work Alex. Just some nits and some questions. Thanks!

NetX/src/rtc.c Outdated
#include <stdint.h>
#include "stm32h5xx_hal_rtc.h"

#define ptp_utc_offset 0 // UTC 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nit: make this var all caps

NetX/src/rtc.c Outdated
ptp_date_time->nanosecond / 1000, second_fractions);

UINT offset_tick = 0; // ticks to go backwards
UINT offset_ahead_1s = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also very nit: they have macros for this I believe. Set this to RTC_SHIFTADD1S_RESET and then RTC_SHIFTADD1S_SET when you want to set it

NetX/src/rtc.c Outdated
if (rtc_sub_second_tick > rtp_sub_second_tick) { // local ahead
offset_tick = rtc_sub_second_tick - rtp_sub_second_tick;
} else { // local behind
offset_ahead_1s = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have to offset the seconds in this situation. Isn't it just comparing the sub-second ticks and you would just have to offset by that? Wouldn't we just have to add a second if the offset goes above the max sub-second value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2026-02-16 at 11 27 06 AM

offset ticks is the amount of ck_apre periods to go backwards, so if you want to go forwards you first add one second.

I should double check that everything is good though since it seems to be a bit complicated

{
switch (operation) {
case NX_PTP_CLIENT_CLOCK_INIT:
HAL_RTC_Init(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably do this in main.c? This is okay for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Develop HAL RTC interaction and callback layer for PTP

2 participants