Commit b916f9a0 authored by Marc Desvaux's avatar Marc Desvaux Committed by Erwan Gouriou
Browse files

drivers: STM32H7: ethernet: PTP clock doesn’t works

fix to the HAL_API_V2 to get PTP to work

In the HAL_ETH_ReadData function where it checks for the
last descriptor, I added a checked if the TSA bit was set
in DESC1
If the TSA bit is set then have a peak at the context
descriptor which should be the one after the last
descriptor
If the CTXT bit is set in the context descriptor then
extract the timestamps

update README to fix to the V2 HAL API to get PTP to work

Co-authored-by: default avatarChamira Perera <chamira.perera@audinate.com>
Signed-off-by: default avatarMarc Desvaux <marc.desvaux-ext@st.com>
parent 83cf59e4
Loading
Loading
Loading
Loading
+10 −0
Changes for stm32cube/stm32h7xx/README: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -47,6 +47,16 @@ Patch List:
    - Impacted file: stm32h7xx_hal_eth.c
    - Internal reference: Not available. Will be fixed as part of a new eth hal implementation

   *fix to the V2 HAL API to get PTP to work
     In the HAL_ETH_ReadData function where it checks for the last descriptor, 
     we added a checked if the TSA bit was set in DESC1
     If the TSA bit is set then have a peak at the context descriptor which should be the one 
     after the last descriptor
     If the CTXT bit is set in the context descriptor then extract the timestamps
     Impacted files:
     drivers/src/stm32h7xx_hal_eth.c
     ST Internal Reference: 142115
    
   *Enable legacy ethernet driver using HAL_ETH_LEGACY_MODULE_ENABLED
    This will have to be removed once Zephyr driver is magrated ot the new
    Cube HAL ethernet API.
+18 −9
Changes for stm32cube/stm32h7xx/drivers/src/stm32h7xx_hal_eth.c: 18 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -1036,8 +1036,8 @@ HAL_StatusTypeDef HAL_ETH_Transmit_IT(ETH_HandleTypeDef *heth, ETH_TxPacketConfi
  */
HAL_StatusTypeDef HAL_ETH_ReadData(ETH_HandleTypeDef *heth, void **pAppBuff)
{
  uint32_t descidx;
  ETH_DMADescTypeDef *dmarxdesc;
  uint32_t descidx, descidx_temp;
  ETH_DMADescTypeDef *dmarxdesc, *dmarxdesc_temp;
  uint32_t desccnt = 0U;
  uint32_t desccntmax;
  uint32_t bufflength;
@@ -1063,13 +1063,6 @@ HAL_StatusTypeDef HAL_ETH_ReadData(ETH_HandleTypeDef *heth, void **pAppBuff)
  while ((READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_OWN) == (uint32_t)RESET) && (desccnt < desccntmax)
         && (rxdataready == 0U))
  {
    if (READ_BIT(dmarxdesc->DESC3,  ETH_DMARXNDESCWBF_CTXT)  != (uint32_t)RESET)
    {
      /* Get timestamp high */
      heth->RxDescList.TimeStamp.TimeStampHigh = dmarxdesc->DESC1;
      /* Get timestamp low */
      heth->RxDescList.TimeStamp.TimeStampLow  = dmarxdesc->DESC0;
    }
    if ((READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_FD) != (uint32_t)RESET) || (heth->RxDescList.pRxStart != NULL))
    {
      /* Check if first descriptor */
@@ -1090,6 +1083,22 @@ HAL_StatusTypeDef HAL_ETH_ReadData(ETH_HandleTypeDef *heth, void **pAppBuff)

        /* Packet ready */
        rxdataready = 1;

        if (READ_BIT(dmarxdesc->DESC1, ETH_DMARXNDESCWBF_TSA) != (uint32_t)RESET)
        {
          descidx_temp = descidx;
          INCR_RX_DESC_INDEX(descidx_temp, 1U);

          dmarxdesc_temp = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[descidx_temp];

          if (READ_BIT(dmarxdesc_temp->DESC3, ETH_DMARXNDESCWBF_CTXT) != (uint32_t)RESET)
          {
            /* Get timestamp high */
            heth->RxDescList.TimeStamp.TimeStampHigh = dmarxdesc_temp->DESC1;
            /* Get timestamp low */
            heth->RxDescList.TimeStamp.TimeStampLow  = dmarxdesc_temp->DESC0;
          }
        }
      }

      /* Link data */