2021-02-10 03:47 PM
STM32Cube MX Version 6.1.1, STM32Cube MCU Package for STM32H7 Series V1.8.0
eth.c is generated with the following code. It sets the MAC address assuming it is an array of bytes.
/* ETH init function */
void MX_ETH_Init(void)
{
heth.Instance = ETH;
heth.Init.MACAddr[0] = 0x00;
heth.Init.MACAddr[1] = 0x80;
heth.Init.MACAddr[2] = 0xE1;
heth.Init.MACAddr[3] = 0x00;
heth.Init.MACAddr[4] = 0x00;
heth.Init.MACAddr[5] = 0x00;
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 */
However, ETH_InitTypeDef defines MACAddr as a pointer (to an array of six bytes)
/**
* @brief ETH Init Structure definition
*/
typedef struct
{
uint8_t *MACAddr; /*!< MAC Address of used Hardware: must be pointer on an array of 6 bytes */
ETH_MediaInterfaceTypeDef MediaInterface; /*!< Selects the MII interface or the RMII interface. */
ETH_DMADescTypeDef *TxDesc; /*!< Provides the address of the first DMA Tx descriptor in the list */
ETH_DMADescTypeDef *RxDesc; /*!< Provides the address of the first DMA Rx descriptor in the list */
uint32_t RxBuffLen; /*!< Provides the length of Rx buffers size */
}ETH_InitTypeDef;
So, when MAC address is set in MX_Eth_Init, the heth.Init.MACAddr pointer has a value of zero. So address 0, 1, 2, 3, 4, 5 are set to the MAC address. On most STM32s this would result in a hard fault, but the H7 has the ITCM RAM mapped at address zero so it just corrupts that!
The MAC address is set correctly as it is pointing valid RAM that is initialized to the correct MAC address.
The only workaround I can see is to reserve the six bytes at address 0...