Search code examples
ethernetstm32f7stm32cubemxptpdstm32h743

IEEE 1588 PTP Clock Source in STM32H743


I'm trying to get PTP timestamp on STM32H743 Nucleo board. There is no proble with LwIP and ethernet driver so far except for PTP. I followed the instruction( 58.9.7 Programming guidelines for IEEE 1588 timestamping) on reference manual (RM0433) as follow.

  CLEAR_BIT(heth->Instance->MACIER, ETH_MACIER_TSIE);
  SET_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_TSENA);
  WRITE_REG(heth->Instance->MACSSIR, 20);
  WRITE_REG(heth->Instance->MACTSAR, 894784853);    // 2^63 / 20 / 480M
  SET_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_TSADDREG);
  while(READ_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_TSADDREG));
  SET_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_TSCFUPDT);
  WRITE_REG(heth->Instance->MACSTSUR, 0x01);
  WRITE_REG(heth->Instance->MACSTNUR, 0x02);
  SET_BIT(heth->Instance->MACTSCR, ETH_MACTSCR_TSINIT); // If one-step timestamping is required follow reference manual
  // TODO: configure pps

However, System time seconds register (ETH_MACSTSR) does not count and just loaded initial value in System time seconds update register (ETH_MACSTSUR). In reference maual there is no clear information about clock source for PTP. In STM32F7, there is a clock path for PTP as in image below in CubeMX clock configuraton page.

enter image description here

However there no clock path for PTP in STM32H7 as in image below.

enter image description here

Am I missing something about to get system time from the registers ETH_MACSTSR and ETH_MACSTNR?


Solution

  • The problem comes from the Sub-second increment register (ETH_MACSSIR). The value to be incremented is stored in high word of the register as in the image below. so the value has to be shifted by 16.

    enter image description here

    Everything runs as expected when changed the value as follow.

    WRITE_REG(heth->Instance->MACSSIR, ((uint32_t)20)<<16);