cancel
Showing results for 
Search instead for 
Did you mean: 

USB HS Device fails to bring up if ETH is activated

simo zz
Senior

Hi,

I am using an STM32H7RS MCU (NUCLEO-H7S3L8) and I need to use both USB HS Device and Ethernet MAC.

For Ethernet MAC I will only need to use MDIO interface, so I don't think I need a stack for it but please correct me if I am wrong.

The MX_ETH_Init code is generated with STM32CubeMX 6.14.0, the pin assignment is according to the schematics:

https://www.st.com/resource/en/schematic_pack/mb1737-h7s3l8-b02-schematic.pdf

 

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    eth.c
  * @brief   This file provides code for the configuration
  *          of the ETH instances.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "eth.h"
#include "string.h"

#if defined ( __ICCARM__ ) /*!< IAR Compiler */

#pragma location=0x24020000
ETH_DMADescTypeDef  DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
#pragma location=0x24020080
ETH_DMADescTypeDef  DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */

#elif defined ( __CC_ARM )  /* MDK ARM Compiler */

__attribute__((at(0x24020000))) ETH_DMADescTypeDef  DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
__attribute__((at(0x24020080))) ETH_DMADescTypeDef  DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */

#elif (defined ( __GNUC__ ) || defined ( __ARMCC_VERSION )) /* GNU Compiler */

ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; __attribute__((section(".RxDescripSection"))); /* Ethernet Rx DMA Descriptors */
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; __attribute__((section(".TxDescripSection")));   /* Ethernet Tx DMA Descriptors */

#endif
ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT * 2U];
ETH_TxPacketConfigTypeDef TxConfig;

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

ETH_HandleTypeDef heth;

/* ETH init function */
void MX_ETH_Init(void)
{

  /* USER CODE BEGIN ETH_Init 0 */

  /* USER CODE END ETH_Init 0 */

   static uint8_t MACAddr[6];

  /* USER CODE BEGIN ETH_Init 1 */

  /* USER CODE END ETH_Init 1 */
  heth.Instance = ETH;
  MACAddr[0] = 0x00;
  MACAddr[1] = 0x80;
  MACAddr[2] = 0xE1;
  MACAddr[3] = 0x00;
  MACAddr[4] = 0x00;
  MACAddr[5] = 0x00;
  heth.Init.MACAddr = &MACAddr[0];
  heth.Init.MediaInterface = HAL_ETH_RMII_MODE;
  heth.Init.TxDesc = DMATxDscrTab;
  heth.Init.RxDesc = DMARxDscrTab;
  heth.Init.RxBuffLen = 1524;

  /* USER CODE BEGIN MACADDRESS */

  /* USER CODE END MACADDRESS */

  if (HAL_ETH_Init(&heth) != HAL_OK)
  {
    Error_Handler();
  }

  memset(&TxConfig, 0 , sizeof(ETH_TxPacketConfigTypeDef));
  TxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD;
  TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC;
  TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;
  /* USER CODE BEGIN ETH_Init 2 */

  /* USER CODE END ETH_Init 2 */

}

void HAL_ETH_MspInit(ETH_HandleTypeDef* ethHandle)
{

  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  if(ethHandle->Instance==ETH)
  {
  /* USER CODE BEGIN ETH_MspInit 0 */

  /* USER CODE END ETH_MspInit 0 */

  /** Initializes the peripherals clock
  */
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ETH1REF;
    PeriphClkInit.Eth1RefClockSelection = RCC_ETH1REFCLKSOURCE_ETH;

  /* USER CODE BEGIN MACADDRESS */

  /* USER CODE END MACADDRESS */

    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }

    /* ETH clock enable */
    __HAL_RCC_ETH1MAC_CLK_ENABLE();
    __HAL_RCC_ETH1TX_CLK_ENABLE();
    __HAL_RCC_ETH1RX_CLK_ENABLE();

    __HAL_RCC_GPIOB_CLK_ENABLE();
    __HAL_RCC_GPIOG_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();
    /**ETH GPIO Configuration
    PB6     ------> ETH_RMII_REF_CLK
    PG12     ------> ETH_RMII_TXD1
    PG11     ------> ETH_RMII_TX_EN
    PG13     ------> ETH_RMII_TXD0
    PA2     ------> ETH_MDIO
    PA7     ------> ETH_RMII_CRS_DV
    PG6     ------> ETH_MDC
    PC5     ------> ETH_RMII_RXD1
    PG4     ------> ETH_RMII_RXD0
    */
    GPIO_InitStruct.Pin = GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11|GPIO_PIN_13|GPIO_PIN_6
                          |GPIO_PIN_4;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

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

    GPIO_InitStruct.Pin = GPIO_PIN_5;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /* USER CODE BEGIN ETH_MspInit 1 */

  /* USER CODE END ETH_MspInit 1 */
  }
}

void HAL_ETH_MspDeInit(ETH_HandleTypeDef* ethHandle)
{

  if(ethHandle->Instance==ETH)
  {
  /* USER CODE BEGIN ETH_MspDeInit 0 */

  /* USER CODE END ETH_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_ETH1MAC_CLK_DISABLE();
    __HAL_RCC_ETH1TX_CLK_DISABLE();
    __HAL_RCC_ETH1RX_CLK_DISABLE();

    /**ETH GPIO Configuration
    PB6     ------> ETH_RMII_REF_CLK
    PG12     ------> ETH_RMII_TXD1
    PG11     ------> ETH_RMII_TX_EN
    PG13     ------> ETH_RMII_TXD0
    PA2     ------> ETH_MDIO
    PA7     ------> ETH_RMII_CRS_DV
    PG6     ------> ETH_MDC
    PC5     ------> ETH_RMII_RXD1
    PG4     ------> ETH_RMII_RXD0
    */
    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);

    HAL_GPIO_DeInit(GPIOG, GPIO_PIN_12|GPIO_PIN_11|GPIO_PIN_13|GPIO_PIN_6
                          |GPIO_PIN_4);

    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_7);

    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_5);

  /* USER CODE BEGIN ETH_MspDeInit 1 */

  /* USER CODE END ETH_MspDeInit 1 */
  }
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

 

USB HS Device works both with or without DMA, but if MX_ETH_Init is executed, the USB HS Device fails to bring up.

Is there some particular configuration detail I am not taking into account?

Thanks,

s.

1 ACCEPTED SOLUTION

Accepted Solutions
simo zz
Senior

The problem seems to be given by the clock.

Setting the clock source as HSE, now the USB runs correctly.

s.

View solution in original post

3 REPLIES 3
FBL
ST Employee

Hi @simo zz 

Ensure that the clock configurations for both peripherals are correctly set and do not conflict. Also ensure that the memory regions used by the descriptors and buffers of both peripherals do not overlap. 

Did you check if internal regulator is used? 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


Hello @FBL,

 


@FBL wrote:

Ensure that the clock configurations for both peripherals are correctly set and do not conflict.

The clock configuration has been set as shown:

simozz_3-1741789377349.png

It shouldn't be any conflict. Right?

I also checked with oscilloscope the ETH CLK on PB6 (also available on CN12 of the board):

simozz_1-1741788928696.png

50 MHz, max 376 mV as show below:

simozz_2-1741789270441.png

This is with 10x probe:

simozz_0-1741792472668.png

Anyway, the execution of MX_ETH_Init() fails in HAL_ETH_Init checking for SWR reset bit in ETH_DMARR register. In other words the bit is not automatically cleared.

 


@FBL wrote:

Did you check if internal regulator is used? 


USB regulator is used. In general, USB is (or should be) fine, is it working fine, except if ETH Mac init function is executed.

s.

simo zz
Senior

The problem seems to be given by the clock.

Setting the clock source as HSE, now the USB runs correctly.

s.