Skip to content

Commit

Permalink
stm32cube: stm32h5: ethernet: PTP clock doesn’t works
Browse files Browse the repository at this point in the history
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

Signed-off-by: blackhelicopters <[email protected]>
Signed-off-by: Marc Desvaux <[email protected]>
  • Loading branch information
Desvauxm-st authored and erwango committed Sep 27, 2023
1 parent d466dc8 commit 89ef0a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
9 changes: 9 additions & 0 deletions stm32cube/stm32h5xx/README
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ Patch List:
drivers/include/stm32h5xx_ll_spi.h
ST internal bug : 147754

*fix to the V2 HAL API to get PTP to work
impacted file : stm32h5xx_hal_eth.c
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
ST internal bug : 161504

See release_note.html from STM32Cube
27 changes: 18 additions & 9 deletions stm32cube/stm32h5xx/drivers/src/stm32h5xx_hal_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down

0 comments on commit 89ef0a3

Please sign in to comment.