cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H573: ETH SWRESET fails, ETH_DMAMR_SWR stays set, timeout

Lionheart1810
Visitor

I want to initialize the STM32H573 ETH module using the STM32CubeMX code generator (see ioc file attached). It should run in MII mode using an external transceiver.

I kept the configuration unchanged, however it always jumps to ErrorHandler, because HAL_ETH_Init returns HAL_ERROR on timeout of ETH_DMAMR_SWR at the following routine:

  SET_BIT(heth->Instance->DMAMR, ETH_DMAMR_SWR);

  /* Get tick */
  tickstart = HAL_GetTick();

  /* Wait for software reset */
  while (READ_BIT(heth->Instance->DMAMR, ETH_DMAMR_SWR) > 0U)
  {
    if (((HAL_GetTick() - tickstart) > ETH_SWRESET_TIMEOUT))
    {
      /* Set Error Code */
      heth->ErrorCode = HAL_ETH_ERROR_TIMEOUT;
      /* Set State as Error */
      heth->gState = HAL_ETH_STATE_ERROR;
      /* Return Error */
      return HAL_ERROR;
    }
  }

From what I've read on this forum, the ETH somehow needs an external clock input from the transceiver. However, ETH_REF_CLK is only defined in RMII mode, but I want MII mode with RX and TX clocks. Does it still need permanently running clock? ETH_RX_CLK is currently served from the transceiver with 2.5 MHz (in 10 Mbps mode), the ETH module itself is clocked 100 MHz from PLL1Q:

Screenshot_20250203_191600.png

I even tried rising the timeout threshold, but even 50 s is failing. Any ideas on how to get the initialization through?

2 REPLIES 2
alister
Lead

ETH_REF_CLK is for RMII. ETH_RX_CLK and ETH_TX_CLK are for MII.

I observed HAL_ETH_Init failing similarly for the STM32H7S78-DK last year and posted that and a fix at https://community.st.com/t5/stm32cubemx-mcus/bugs-caveats-misc-fixes-stm32h7s-cube/td-p/710992. For clarity, the peripheral clock's fix in HAL_ETH_MspInit was:

 

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ETH1REF;
 PeriphClkInit.Eth1RefClockSelection = RCC_ETH1REFCLKSOURCE_PHY;

 

 

Lionheart1810
Visitor

This section does not exist in the autogenerated HAL_ETH_MspInit:

Spoiler
void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(heth->Instance==ETH)
  {
  /* USER CODE BEGIN ETH_MspInit 0 */

  /* USER CODE END ETH_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_ETH_CLK_ENABLE();
    __HAL_RCC_ETHTX_CLK_ENABLE();
    __HAL_RCC_ETHRX_CLK_ENABLE();

    __HAL_RCC_GPIOB_CLK_ENABLE();
    __HAL_RCC_GPIOG_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOH_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**ETH GPIO Configuration
    PB8     ------> ETH_TXD3
    PG14     ------> ETH_TXD1
    PG13     ------> ETH_TXD0
    PG11     ------> ETH_TX_EN
    PC1     ------> ETH_MDC
    PC2     ------> ETH_TXD2
    PC3     ------> ETH_TX_CLK
    PH6     ------> ETH_RXD2
    PA1     ------> ETH_RX_CLK
    PA0     ------> ETH_CRS
    PC4     ------> ETH_RXD0
    PH7     ------> ETH_RXD3
    PA2     ------> ETH_MDIO
    PC5     ------> ETH_RXD1
    PA3     ------> ETH_COL
    PA7     ------> ETH_RX_DV
    */

    GPIO_InitStruct.Pin = GPIO_PIN_8;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_13|GPIO_PIN_11;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
                          |GPIO_PIN_5;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_0|GPIO_PIN_2|GPIO_PIN_3
                          |GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* USER CODE BEGIN ETH_MspInit 1 */

  /* USER CODE END ETH_MspInit 1 */

  }

}

Also, there is no RCC_PERIPHCLK_ETH... (as it is most likely directly clocked from PLL1Q).

Anything I am missing?