/**
******************************************************************************
* @file stm32hxx_hal_eth.h
* @author MCD Application Team
* @brief Header file of ETH HAL module.
******************************************************************************
* @attention
*
*
© Copyright (c) 2017 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32Hxx_HAL_ETH_H
#define STM32Hxx_HAL_ETH_H
#define STM32H7xx_HAL_ETH_H
/* Includes ------------------------------------------------------------------*/
#include "stm32h7xx_hal_def.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined( ETH )
/** @addtogroup STM32H7xx_HAL_Driver
* @{
*/
/** @addtogroup ETH
* @{
*/
/* Exported types ------------------------------------------------------------*/
#ifndef ETH_TX_DESC_CNT
#error Please define ETH_TX_DESC_CNT in your stm32h7xx_hal_conf.h
#endif
#ifndef ETH_RX_DESC_CNT
#error Please define ETH_RX_DESC_CNT in your stm32h7xx_hal_conf.h
#endif
/*********************** Descriptors struct def section ************************/
/** @defgroup ETH_Exported_Types ETH Exported Types
* @{
*/
struct xErrorFields
{
uint16_t
ERR_IHE : 1, /* IP Header Error */
ERR_DB : 1, /* Deferred Bit */
ERR_Umderflow : 1, /* Underflow Error */
ERR_ExcDefer : 1, /* Excessive Deferral */
ERR_CC : 4, /* Collision count. */
ERR_EC : 1, /* Excessive Collision */
ERR_LC : 1, /* Late collision. */
ERR_NC : 1, /* No carrier. */
ERR_LoC : 1, /* Loss of Carrier: carrier lost during transmission */
ERR_PCE : 1, /* Payload Checksum Error */
ERR_FF : 1, /* Packet Flushed: DMA/MTL flushed the packet due to SW flush */
ERR_JT : 1, /* Jabber Timeout */
ERR_SUMMARY : 1;
}
__attribute__( ( packed ) );
/**
* @brief ETH DMA Descriptor structure definition
*/
typedef struct
{
union
{
__IO uint32_t DESC0; /* The buffer */
uint32_t Buffer_1____;
};
union
{
__IO uint32_t DESC1;
uint32_t Buffer_2____;
};
union
{
__IO uint32_t DESC2; /* Buffer 1 length (0x00003FFFU) Buffer 2 Length (0x3FFF0000) */
struct
{
unsigned
Buff1_Length : 14, /* Buffer 1 Length */
VTIR________ : 2, /* VLAN Tag Insertion or Replacement mask */
Buff2_Length : 14, /* Buffer 2 Length */
TTSE________ : 1, /* Transmit Timestamp Enable */
IOC_________ : 1; /* Interrupt on Completion */
};
};
union
{
__IO uint32_t DESC3; /* bit 31 is the OWN (by DMA) bit */
struct
{
struct xErrorFields ERR_FIELDS;
struct
{
uint16_t
Reserved_1__ : 1,
TIMESTAMP___ : 1, /*!< Tx Timestamp Status */
Reserved_3__ : 10,
LAST_DESC___ : 1, /*!< Last Descriptor */
FIRST_DESC__ : 1, /*!< First Descriptor */
STATUS_CTX__ : 1, /*!< Context Type */
OWN_________ : 1;
} __attribute__( ( packed ) );
};
};
uint32_t BackupAddr0; /* used to store rx buffer 1 address */
uint32_t BackupAddr1; /* used to store rx buffer 2 address */
} ETH_DMADescTypeDef;
/*
* Channel status register ( see field DMACSR, or "ETH_DMACSR".
*/
typedef struct
{
union
{
uint32_t ulValue;
struct
{
uint32_t
TI_Transmit_Interrupt__________ : 1,
TPS_Transmit_Process_Stopped___ : 1,
TBU_Transmit_Buffer_Unavailable : 1,
R_0 : 3,
RI_Receive_Interrupt___________ : 1,
RBU_Receive_Buffer_Unavailable_ : 1,
RPS_Receive_Process_Stopped____ : 1,
RWT_Receive_Watchdog_Timeout___ : 1,
ETI_Early_Transmit_Interrupt___ : 1,
ERI_Early_Receive_Interrupt____ : 1,
FBE_Fatal_Bus_Error____________ : 1,
CDE_Context_Descriptor_Error___ : 1,
AIS_Abnormal_Interrupt_Summary_ : 1,
NIS_Normal_Interrupt_Summary___ : 1,
REB_0_Error_during_read_transfer_when_1__________ : 1,
REB_1_Error_during_descriptor_access_when_1______ : 1,
REB_2_Error_during_data_transfer_by_Rx_DMA_when_1 : 1,
TEB_0_Error_during_read_transfer_when_1__________ : 1,
TEB_1_Error_during_descriptor_access_when_1______ : 1,
TEB_2_Error_during_data_transfer_by_Tx_DMA_when_1 : 1,
R_1 : 10;
};
};
} IntStatus_t;
/**
*
*/
/**
* @brief ETH Buffers List structure definition
*/
typedef struct __ETH_BufferTypeDef
{
uint8_t * buffer; /*gState = HAL_ETH_STATE_RESET; \
( __HANDLE__ )->RxState = HAL_ETH_STATE_RESET; \
( __HANDLE__ )->MspInitCallback = NULL; \
( __HANDLE__ )->MspDeInitCallback = NULL; \
} while( 0 )
#else
#define __HAL_ETH_RESET_HANDLE_STATE( __HANDLE__ ) \
do { \
( __HANDLE__ )->gState = HAL_ETH_STATE_RESET; \
( __HANDLE__ )->RxState = HAL_ETH_STATE_RESET; \
} while( 0 )
#endif /*USE_HAL_ETH_REGISTER_CALLBACKS */
/**
* @brief Enables the specified ETHERNET DMA interrupts.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the ETHERNET DMA interrupt sources to be
* enabled @ref ETH_DMA_Interrupts
* @retval None
*/
#define __HAL_ETH_DMA_ENABLE_IT( __HANDLE__, __INTERRUPT__ ) ( ( __HANDLE__ )->Instance->DMACIER |= ( __INTERRUPT__ ) )
/**
* @brief Disables the specified ETHERNET DMA interrupts.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the ETHERNET DMA interrupt sources to be
* disabled. @ref ETH_DMA_Interrupts
* @retval None
*/
#define __HAL_ETH_DMA_DISABLE_IT( __HANDLE__, __INTERRUPT__ ) ( ( __HANDLE__ )->Instance->DMACIER &= ~( __INTERRUPT__ ) )
/**
* @brief Gets the ETHERNET DMA IT source enabled or disabled.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the interrupt source to get . @ref ETH_DMA_Interrupts
* @retval The ETH DMA IT Source enabled or disabled
*/
#define __HAL_ETH_DMA_GET_IT_SOURCE( __HANDLE__, __INTERRUPT__ ) ( ( ( __HANDLE__ )->Instance->DMACIER & ( __INTERRUPT__ ) ) == ( __INTERRUPT__ ) )
/**
* @brief Gets the ETHERNET DMA IT pending bit.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the interrupt source to get . @ref ETH_DMA_Interrupts
* @retval The state of ETH DMA IT (SET or RESET)
*/
#define __HAL_ETH_DMA_GET_IT( __HANDLE__, __INTERRUPT__ ) ( ( ( __HANDLE__ )->Instance->DMACSR & ( __INTERRUPT__ ) ) == ( __INTERRUPT__ ) )
/**
* @brief Clears the ETHERNET DMA IT pending bit.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the interrupt pending bit to clear. @ref ETH_DMA_Interrupts
* @retval None
*/
#define __HAL_ETH_DMA_CLEAR_IT( __HANDLE__, __INTERRUPT__ ) ( ( __HANDLE__ )->Instance->DMACSR = ( __INTERRUPT__ ) )
/**
* @brief Checks whether the specified ETHERNET DMA flag is set or not.
* @param __HANDLE__: ETH Handle
* @param __FLAG__: specifies the flag to check. @ref ETH_DMA_Status_Flags
* @retval The state of ETH DMA FLAG (SET or RESET).
*/
#define __HAL_ETH_DMA_GET_FLAG( __HANDLE__, __FLAG__ ) ( ( ( __HANDLE__ )->Instance->DMACSR & ( __FLAG__ ) ) == ( __FLAG__ ) )
/**
* @brief Clears the specified ETHERNET DMA flag.
* @param __HANDLE__: ETH Handle
* @param __FLAG__: specifies the flag to check. @ref ETH_DMA_Status_Flags
* @retval The state of ETH DMA FLAG (SET or RESET).
*/
#define __HAL_ETH_DMA_CLEAR_FLAG( __HANDLE__, __FLAG__ ) ( ( __HANDLE__ )->Instance->DMACSR = ( __FLAG__ ) )
/**
* @brief Enables the specified ETHERNET MAC interrupts.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the ETHERNET MAC interrupt sources to be
* enabled @ref ETH_MAC_Interrupts
* @retval None
*/
#define __HAL_ETH_MAC_ENABLE_IT( __HANDLE__, __INTERRUPT__ ) ( ( __HANDLE__ )->Instance->MACIER |= ( __INTERRUPT__ ) )
/**
* @brief Disables the specified ETHERNET MAC interrupts.
* @param __HANDLE__ : ETH Handle
* @param __INTERRUPT__: specifies the ETHERNET MAC interrupt sources to be
* enabled @ref ETH_MAC_Interrupts
* @retval None
*/
#define __HAL_ETH_MAC_DISABLE_IT( __HANDLE__, __INTERRUPT__ ) ( ( __HANDLE__ )->Instance->MACIER &= ~( __INTERRUPT__ ) )
/**
* @brief Checks whether the specified ETHERNET MAC flag is set or not.
* @param __HANDLE__: ETH Handle
* @param __INTERRUPT__: specifies the flag to check. @ref ETH_MAC_Interrupts
* @retval The state of ETH MAC IT (SET or RESET).
*/
#define __HAL_ETH_MAC_GET_IT( __HANDLE__, __INTERRUPT__ ) ( ( ( __HANDLE__ )->Instance->MACISR & ( __INTERRUPT__ ) ) == ( __INTERRUPT__ ) )
/*!< External interrupt line 86 Connected to the ETH wakeup EXTI Line */
#define ETH_WAKEUP_EXTI_LINE ( ( uint32_t ) 0x00400000U ) /* !< 86 - 64 = 22 */
/**
* @brief Enable the ETH WAKEUP Exti Line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be enabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None.
*/
#define __HAL_ETH_WAKEUP_EXTI_ENABLE_IT( __EXTI_LINE__ ) ( EXTI_D1->IMR3 |= ( __EXTI_LINE__ ) )
/**
* @brief checks whether the specified ETH WAKEUP Exti interrupt flag is set or not.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be cleared.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval EXTI ETH WAKEUP Line Status.
*/
#define __HAL_ETH_WAKEUP_EXTI_GET_FLAG( __EXTI_LINE__ ) ( EXTI_D1->PR3 & ( __EXTI_LINE__ ) )
/**
* @brief Clear the ETH WAKEUP Exti flag.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be cleared.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None.
*/
#define __HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG( __EXTI_LINE__ ) ( EXTI_D1->PR3 = ( __EXTI_LINE__ ) )
#if defined( DUAL_CORE )
/**
* @brief Enable the ETH WAKEUP Exti Line by Core2.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be enabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None.
*/
#define __HAL_ETH_WAKEUP_EXTID2_ENABLE_IT( __EXTI_LINE__ ) ( EXTI_D2->IMR3 |= ( __EXTI_LINE__ ) )
/**
* @brief checks whether the specified ETH WAKEUP Exti interrupt flag is set or not.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be cleared.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval EXTI ETH WAKEUP Line Status.
*/
#define __HAL_ETH_WAKEUP_EXTID2_GET_FLAG( __EXTI_LINE__ ) ( EXTI_D2->PR3 & ( __EXTI_LINE__ ) )
/**
* @brief Clear the ETH WAKEUP Exti flag.
* @param __EXTI_LINE__: specifies the ETH WAKEUP Exti sources to be cleared.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None.
*/
#define __HAL_ETH_WAKEUP_EXTID2_CLEAR_FLAG( __EXTI_LINE__ ) ( EXTI_D2->PR3 = ( __EXTI_LINE__ ) )
#endif
/**
* @brief enable rising edge interrupt on selected EXTI line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP EXTI sources to be disabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None
*/
#define __HAL_ETH_WAKEUP_EXTI_ENABLE_RISING_EDGE( __EXTI_LINE__ ) \
( EXTI->FTSR3 &= ~( __EXTI_LINE__ ) ); \
( EXTI->RTSR3 |= ( __EXTI_LINE__ ) )
/**
* @brief enable falling edge interrupt on selected EXTI line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP EXTI sources to be disabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None
*/
#define __HAL_ETH_WAKEUP_EXTI_ENABLE_FALLING_EDGE( __EXTI_LINE__ ) \
( EXTI->RTSR3 &= ~( __EXTI_LINE__ ) ); \
( EXTI->FTSR3 |= ( __EXTI_LINE__ ) )
/**
* @brief enable falling edge interrupt on selected EXTI line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP EXTI sources to be disabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None
*/
#define __HAL_ETH_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE( __EXTI_LINE__ ) \
( EXTI->RTSR3 |= ( __EXTI_LINE__ ) ); \
( EXTI->FTSR3 |= ( __EXTI_LINE__ ) )
/**
* @brief Generates a Software interrupt on selected EXTI line.
* @param __EXTI_LINE__: specifies the ETH WAKEUP EXTI sources to be disabled.
* @arg ETH_WAKEUP_EXTI_LINE
* @retval None
*/
#define __HAL_ETH_WAKEUP_EXTI_GENERATE_SWIT( __EXTI_LINE__ ) ( EXTI->SWIER3 |= ( __EXTI_LINE__ ) )
/**
* @}
*/
/* Include ETH HAL Extension module */
#include "stm32h7xx_hal_eth_ex.h"
/* Exported functions --------------------------------------------------------*/
/** @addtogroup ETH_Exported_Functions
* @{
*/
/** @addtogroup ETH_Exported_Functions_Group1
* @{
*/
/* Initialization and de initialization functions **********************************/
HAL_StatusTypeDef HAL_ETH_Init( ETH_HandleTypeDef * heth );
HAL_StatusTypeDef HAL_ETH_DeInit( ETH_HandleTypeDef * heth );
void HAL_ETH_MspInit( ETH_HandleTypeDef * heth );
void HAL_ETH_MspDeInit( ETH_HandleTypeDef * heth );
HAL_StatusTypeDef HAL_ETH_DescAssignMemory( ETH_HandleTypeDef * heth,
uint32_t Index,
uint8_t * pBuffer1,
uint8_t * pBuffer2 );
/* Callbacks Register/UnRegister functions ***********************************/
#if ( USE_HAL_ETH_REGISTER_CALLBACKS == 1 )
HAL_StatusTypeDef HAL_ETH_RegisterCallback( ETH_HandleTypeDef * heth,
HAL_ETH_CallbackIDTypeDef CallbackID,
pETH_CallbackTypeDef pCallback );
HAL_StatusTypeDef HAL_ETH_UnRegisterCallback( ETH_HandleTypeDef * heth,
HAL_ETH_CallbackIDTypeDef CallbackID );
#endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
/**
* @}
*/
/** @addtogroup ETH_Exported_Functions_Group2
* @{
*/
/* IO operation functions *******************************************************/
HAL_StatusTypeDef HAL_ETH_Start( ETH_HandleTypeDef * heth );
HAL_StatusTypeDef HAL_ETH_Start_IT( ETH_HandleTypeDef * heth );
HAL_StatusTypeDef HAL_ETH_Stop( ETH_HandleTypeDef * heth );
HAL_StatusTypeDef HAL_ETH_Stop_IT( ETH_HandleTypeDef * heth );
uint8_t HAL_ETH_IsRxDataAvailable( ETH_HandleTypeDef * heth );
/* The following 2 functions are replaced with a single function: HAL_ETH_GetRxData(). */
/* HAL_StatusTypeDef HAL_ETH_GetRxDataBuffer(ETH_HandleTypeDef *heth, ETH_BufferTypeDef *RxBuffer); */
/* HAL_StatusTypeDef HAL_ETH_GetRxDataLength(ETH_HandleTypeDef *heth, uint32_t *Length); */
size_t HAL_ETH_GetRxData( ETH_HandleTypeDef * heth,
ETH_BufferTypeDef * RxBuffer );
HAL_StatusTypeDef HAL_ETH_GetRxDataInfo( ETH_HandleTypeDef * heth,
ETH_RxPacketInfo * RxPacketInfo );
HAL_StatusTypeDef HAL_ETH_BuildRxDescriptors( ETH_HandleTypeDef * heth,
uint8_t * pucNewBuffer );
HAL_StatusTypeDef HAL_ETH_Transmit( ETH_HandleTypeDef * heth,
ETH_TxPacketConfig * pTxConfig,
uint32_t Timeout );
HAL_StatusTypeDef HAL_ETH_Transmit_IT( ETH_HandleTypeDef * heth,
ETH_TxPacketConfig * pTxConfig );
void ETH_Clear_Tx_Descriptors( ETH_HandleTypeDef * heth );
HAL_StatusTypeDef HAL_ETH_WritePHYRegister( ETH_HandleTypeDef * heth,
uint32_t PHYAddr,
uint32_t PHYReg,
uint32_t RegValue );
HAL_StatusTypeDef HAL_ETH_ReadPHYRegister( ETH_HandleTypeDef * heth,
uint32_t PHYAddr,
uint32_t PHYReg,
uint32_t * pRegValue );
void HAL_ETH_IRQHandler( ETH_HandleTypeDef * heth );
void HAL_ETH_TxCpltCallback( ETH_HandleTypeDef * heth );
void HAL_ETH_RxCpltCallback( ETH_HandleTypeDef * heth );
void HAL_ETH_DMAErrorCallback( ETH_HandleTypeDef * heth );
void HAL_ETH_MACErrorCallback( ETH_HandleTypeDef * heth );
void HAL_ETH_PMTCallback( ETH_HandleTypeDef * heth );
void HAL_ETH_EEECallback( ETH_HandleTypeDef * heth );
void HAL_ETH_WakeUpCallback( ETH_HandleTypeDef * heth );
/**
* @}
*/
/** @addtogroup ETH_Exported_Functions_Group3
* @{
*/
/* Peripheral Control functions **********************************************/
/* MAC & DMA Configuration APIs **********************************************/
HAL_StatusTypeDef HAL_ETH_GetMACConfig( ETH_HandleTypeDef * heth,
ETH_MACConfigTypeDef * macconf );
HAL_StatusTypeDef HAL_ETH_GetDMAConfig( ETH_HandleTypeDef * heth,
ETH_DMAConfigTypeDef * dmaconf );
HAL_StatusTypeDef HAL_ETH_SetMACConfig( ETH_HandleTypeDef * heth,
ETH_MACConfigTypeDef * macconf );
HAL_StatusTypeDef HAL_ETH_SetDMAConfig( ETH_HandleTypeDef * heth,
ETH_DMAConfigTypeDef * dmaconf );
/* MAC VLAN Processing APIs ************************************************/
void HAL_ETH_SetRxVLANIdentifier( ETH_HandleTypeDef * heth,
uint32_t ComparisonBits,
uint32_t VLANIdentifier );
/* MAC L2 Packet Filtering APIs **********************************************/
HAL_StatusTypeDef HAL_ETH_GetMACFilterConfig( ETH_HandleTypeDef * heth,
ETH_MACFilterConfigTypeDef * pFilterConfig );
HAL_StatusTypeDef HAL_ETH_SetMACFilterConfig( ETH_HandleTypeDef * heth,
ETH_MACFilterConfigTypeDef * pFilterConfig );
HAL_StatusTypeDef HAL_ETH_SetHashTable( ETH_HandleTypeDef * heth,
uint32_t * pHashTable );
HAL_StatusTypeDef HAL_ETH_SetSourceMACAddrMatch( ETH_HandleTypeDef * heth,
uint32_t AddrNbr,
uint8_t * pMACAddr );
/* MAC Power Down APIs *****************************************************/
void HAL_ETH_EnterPowerDownMode( ETH_HandleTypeDef * heth,
ETH_PowerDownConfigTypeDef * pPowerDownConfig );
void HAL_ETH_ExitPowerDownMode( ETH_HandleTypeDef * heth );
HAL_StatusTypeDef HAL_ETH_SetWakeUpFilter( ETH_HandleTypeDef * heth,
uint32_t * pFilter,
uint32_t Count );
/**
* @}
*/
/** @addtogroup ETH_Exported_Functions_Group4
* @{
*/
/* Peripheral State functions **************************************************/
HAL_ETH_StateTypeDef HAL_ETH_GetState( ETH_HandleTypeDef * heth );
uint32_t HAL_ETH_GetError( ETH_HandleTypeDef * heth );
uint32_t HAL_ETH_GetDMAError( ETH_HandleTypeDef * heth );
uint32_t HAL_ETH_GetMACError( ETH_HandleTypeDef * heth );
uint32_t HAL_ETH_GetMACWakeUpSource( ETH_HandleTypeDef * heth );
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* ETH */
#ifdef __cplusplus
}
#endif
#endif /* STM32Hxx_HAL_ETH_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/