STM32H735xx HAL User Manual
stm32h7xx_hal_eth.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_hal_eth.c
00004   * @author  MCD Application Team
00005   * @brief   ETH HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the Ethernet (ETH) peripheral:
00008   *           + Initialization and deinitialization functions
00009   *           + IO operation functions
00010   *           + Peripheral Control functions
00011   *           + Peripheral State and Errors functions
00012   ******************************************************************************
00013   * @attention
00014   *
00015   * Copyright (c) 2017 STMicroelectronics.
00016   * All rights reserved.
00017   *
00018   * This software is licensed under terms that can be found in the LICENSE file
00019   * in the root directory of this software component.
00020   * If no LICENSE file comes with this software, it is provided AS-IS.
00021   *
00022   ******************************************************************************
00023   @verbatim
00024   ==============================================================================
00025                     ##### How to use this driver #####
00026   ==============================================================================
00027      [..]
00028      The ETH HAL driver can be used as follows:
00029 
00030       (#)Declare a ETH_HandleTypeDef handle structure, for example:
00031          ETH_HandleTypeDef  heth;
00032 
00033       (#)Fill parameters of Init structure in heth handle
00034 
00035       (#)Call HAL_ETH_Init() API to initialize the Ethernet peripheral (MAC, DMA, ...)
00036 
00037       (#)Initialize the ETH low level resources through the HAL_ETH_MspInit() API:
00038           (##) Enable the Ethernet interface clock using
00039                 (+++)  __HAL_RCC_ETH1MAC_CLK_ENABLE()
00040                 (+++)  __HAL_RCC_ETH1TX_CLK_ENABLE()
00041                 (+++)  __HAL_RCC_ETH1RX_CLK_ENABLE()
00042 
00043           (##) Initialize the related GPIO clocks
00044           (##) Configure Ethernet pinout
00045           (##) Configure Ethernet NVIC interrupt (in Interrupt mode)
00046 
00047       (#) Ethernet data reception is asynchronous, so call the following API
00048           to start the listening mode:
00049           (##) HAL_ETH_Start():
00050                This API starts the MAC and DMA transmission and reception process,
00051                without enabling end of transfer interrupts, in this mode user
00052                has to poll for data availability by calling HAL_ETH_IsRxDataAvailable()
00053           (##) HAL_ETH_Start_IT():
00054                This API starts the MAC and DMA transmission and reception process,
00055                end of transfer interrupts are enabled in this mode,
00056                HAL_ETH_RxCpltCallback() will be executed when an Ethernet packet is received
00057 
00058       (#) When data is received (HAL_ETH_IsRxDataAvailable() returns 1 or Rx interrupt
00059           occurred), user can call the following APIs to get received data:
00060           (##) HAL_ETH_GetRxDataBuffer(): Get buffer address of received frame
00061           (##) HAL_ETH_GetRxDataLength(): Get received frame length
00062           (##) HAL_ETH_GetRxDataInfo(): Get received frame additional info,
00063                please refer to ETH_RxPacketInfo typedef structure
00064 
00065       (#) For transmission path, two APIs are available:
00066          (##) HAL_ETH_Transmit(): Transmit an ETH frame in blocking mode
00067          (##) HAL_ETH_Transmit_IT(): Transmit an ETH frame in interrupt mode,
00068               HAL_ETH_TxCpltCallback() will be executed when end of transfer occur
00069 
00070       (#) Communication with an external PHY device:
00071          (##) HAL_ETH_ReadPHYRegister(): Read a register from an external PHY
00072          (##) HAL_ETH_WritePHYRegister(): Write data to an external RHY register
00073 
00074       (#) Configure the Ethernet MAC after ETH peripheral initialization
00075           (##) HAL_ETH_GetMACConfig(): Get MAC actual configuration into ETH_MACConfigTypeDef
00076           (##) HAL_ETH_SetMACConfig(): Set MAC configuration based on ETH_MACConfigTypeDef
00077 
00078       (#) Configure the Ethernet DMA after ETH peripheral initialization
00079           (##) HAL_ETH_GetDMAConfig(): Get DMA actual configuration into ETH_DMAConfigTypeDef
00080           (##) HAL_ETH_SetDMAConfig(): Set DMA configuration based on ETH_DMAConfigTypeDef
00081 
00082       -@- The PTP protocol offload APIs are not supported in this driver.
00083 
00084   *** Callback registration ***
00085   =============================================
00086 
00087   The compilation define  USE_HAL_ETH_REGISTER_CALLBACKS when set to 1
00088   allows the user to configure dynamically the driver callbacks.
00089   Use Function @ref HAL_ETH_RegisterCallback() to register an interrupt callback.
00090 
00091   Function @ref HAL_ETH_RegisterCallback() allows to register following callbacks:
00092     (+) TxCpltCallback   : Tx Complete Callback.
00093     (+) RxCpltCallback   : Rx Complete Callback.
00094     (+) DMAErrorCallback : DMA Error Callback.
00095     (+) MACErrorCallback : MAC Error Callback.
00096     (+) PMTCallback      : Power Management Callback
00097     (+) EEECallback      : EEE Callback.
00098     (+) WakeUpCallback   : Wake UP Callback
00099     (+) MspInitCallback  : MspInit Callback.
00100     (+) MspDeInitCallback: MspDeInit Callback.
00101 
00102   This function takes as parameters the HAL peripheral handle, the Callback ID
00103   and a pointer to the user callback function.
00104 
00105   Use function @ref HAL_ETH_UnRegisterCallback() to reset a callback to the default
00106   weak function.
00107   @ref HAL_ETH_UnRegisterCallback takes as parameters the HAL peripheral handle,
00108   and the Callback ID.
00109   This function allows to reset following callbacks:
00110     (+) TxCpltCallback   : Tx Complete Callback.
00111     (+) RxCpltCallback   : Rx Complete Callback.
00112     (+) DMAErrorCallback : DMA Error Callback.
00113     (+) MACErrorCallback : MAC Error Callback.
00114     (+) PMTCallback      : Power Management Callback
00115     (+) EEECallback      : EEE Callback.
00116     (+) WakeUpCallback   : Wake UP Callback
00117     (+) MspInitCallback  : MspInit Callback.
00118     (+) MspDeInitCallback: MspDeInit Callback.
00119 
00120   By default, after the HAL_ETH_Init and when the state is HAL_ETH_STATE_RESET
00121   all callbacks are set to the corresponding weak functions:
00122   examples @ref HAL_ETH_TxCpltCallback(), @ref HAL_ETH_RxCpltCallback().
00123   Exception done for MspInit and MspDeInit functions that are
00124   reset to the legacy weak function in the HAL_ETH_Init/ @ref HAL_ETH_DeInit only when
00125   these callbacks are null (not registered beforehand).
00126   if not, MspInit or MspDeInit are not null, the HAL_ETH_Init/ @ref HAL_ETH_DeInit
00127   keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
00128 
00129   Callbacks can be registered/unregistered in HAL_ETH_STATE_READY state only.
00130   Exception done MspInit/MspDeInit that can be registered/unregistered
00131   in HAL_ETH_STATE_READY or HAL_ETH_STATE_RESET state,
00132   thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
00133   In that case first register the MspInit/MspDeInit user callbacks
00134   using @ref HAL_ETH_RegisterCallback() before calling @ref HAL_ETH_DeInit
00135   or HAL_ETH_Init function.
00136 
00137   When The compilation define USE_HAL_ETH_REGISTER_CALLBACKS is set to 0 or
00138   not defined, the callback registration feature is not available and all callbacks
00139   are set to the corresponding weak functions.
00140 
00141   @endverbatim
00142   ******************************************************************************
00143   */
00144 
00145 /* Includes ------------------------------------------------------------------*/
00146 #include "stm32h7xx_hal.h"
00147 
00148 /** @addtogroup STM32H7xx_HAL_Driver
00149   * @{
00150   */
00151 #ifdef HAL_ETH_MODULE_ENABLED
00152 
00153 #if defined(ETH)
00154 
00155 /** @defgroup ETH ETH
00156   * @brief ETH HAL module driver
00157   * @{
00158   */
00159 
00160 /* Private typedef -----------------------------------------------------------*/
00161 /* Private define ------------------------------------------------------------*/
00162 /** @addtogroup ETH_Private_Constants ETH Private Constants
00163   * @{
00164   */
00165 #define ETH_MACCR_MASK       ((uint32_t)0xFFFB7F7CU)
00166 #define ETH_MACECR_MASK      ((uint32_t)0x3F077FFFU)
00167 #define ETH_MACPFR_MASK      ((uint32_t)0x800007FFU)
00168 #define ETH_MACWTR_MASK      ((uint32_t)0x0000010FU)
00169 #define ETH_MACTFCR_MASK     ((uint32_t)0xFFFF00F2U)
00170 #define ETH_MACRFCR_MASK     ((uint32_t)0x00000003U)
00171 #define ETH_MTLTQOMR_MASK    ((uint32_t)0x00000072U)
00172 #define ETH_MTLRQOMR_MASK    ((uint32_t)0x0000007BU)
00173 
00174 #define ETH_DMAMR_MASK       ((uint32_t)0x00007802U)
00175 #define ETH_DMASBMR_MASK     ((uint32_t)0x0000D001U)
00176 #define ETH_DMACCR_MASK      ((uint32_t)0x00013FFFU)
00177 #define ETH_DMACTCR_MASK     ((uint32_t)0x003F1010U)
00178 #define ETH_DMACRCR_MASK     ((uint32_t)0x803F0000U)
00179 #define ETH_MACPCSR_MASK     (ETH_MACPCSR_PWRDWN | ETH_MACPCSR_RWKPKTEN | \
00180                               ETH_MACPCSR_MGKPKTEN | ETH_MACPCSR_GLBLUCAST | \
00181                               ETH_MACPCSR_RWKPFE)
00182 
00183 /* Timeout values */
00184 #define ETH_SWRESET_TIMEOUT                 ((uint32_t)500U)
00185 #define ETH_MDIO_BUS_TIMEOUT                ((uint32_t)1000U)
00186 
00187 #define ETH_DMARXNDESCWBF_ERRORS_MASK ((uint32_t)(ETH_DMARXNDESCWBF_DE | ETH_DMARXNDESCWBF_RE | \
00188                                                   ETH_DMARXNDESCWBF_OE | ETH_DMARXNDESCWBF_RWT |\
00189                                                   ETH_DMARXNDESCWBF_GP | ETH_DMARXNDESCWBF_CE))
00190 
00191 #define ETH_MAC_US_TICK               ((uint32_t)1000000U)
00192 /**
00193   * @}
00194   */
00195 
00196 /* Private macros ------------------------------------------------------------*/
00197 /** @defgroup ETH_Private_Macros ETH Private Macros
00198   * @{
00199   */
00200 /* Helper macros for TX descriptor handling */
00201 #define INCR_TX_DESC_INDEX(inx, offset) do {\
00202         (inx) += (offset);\
00203           if ((inx) >= (uint32_t)ETH_TX_DESC_CNT){\
00204             (inx) = ((inx) - (uint32_t)ETH_TX_DESC_CNT);}\
00205 } while (0)
00206 
00207 /* Helper macros for RX descriptor handling */
00208 #define INCR_RX_DESC_INDEX(inx, offset) do {\
00209         (inx) += (offset);\
00210           if ((inx) >= (uint32_t)ETH_RX_DESC_CNT){\
00211             (inx) = ((inx) - (uint32_t)ETH_RX_DESC_CNT);}\
00212 } while (0)
00213 /**
00214   * @}
00215   */
00216 /* Private function prototypes -----------------------------------------------*/
00217 /** @defgroup ETH_Private_Functions   ETH Private Functions
00218   * @{
00219   */
00220 static void ETH_MAC_MDIO_ClkConfig(ETH_HandleTypeDef *heth);
00221 static void ETH_SetMACConfig(ETH_HandleTypeDef *heth,  ETH_MACConfigTypeDef *macconf);
00222 static void ETH_SetDMAConfig(ETH_HandleTypeDef *heth,  ETH_DMAConfigTypeDef *dmaconf);
00223 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth);
00224 static void ETH_DMATxDescListInit(ETH_HandleTypeDef *heth);
00225 static void ETH_DMARxDescListInit(ETH_HandleTypeDef *heth);
00226 static uint32_t ETH_Prepare_Tx_Descriptors(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig, uint32_t ItMode);
00227 
00228 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
00229 static void ETH_InitCallbacksToDefault(ETH_HandleTypeDef *heth);
00230 #endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
00231 /**
00232   * @}
00233   */
00234 
00235 /* Exported functions ---------------------------------------------------------*/
00236 /** @defgroup ETH_Exported_Functions ETH Exported Functions
00237   * @{
00238   */
00239 
00240 /** @defgroup ETH_Exported_Functions_Group1 Initialization and deinitialization functions
00241   *  @brief    Initialization and Configuration functions
00242   *
00243 @verbatim
00244 ===============================================================================
00245             ##### Initialization and Configuration functions #####
00246  ===============================================================================
00247     [..]  This subsection provides a set of functions allowing to initialize and
00248           deinitialize the ETH peripheral:
00249 
00250       (+) User must Implement HAL_ETH_MspInit() function in which he configures
00251           all related peripherals resources (CLOCK, GPIO and NVIC ).
00252 
00253       (+) Call the function HAL_ETH_Init() to configure the selected device with
00254           the selected configuration:
00255         (++) MAC address
00256         (++) Media interface (MII or RMII)
00257         (++) Rx DMA Descriptors Tab
00258         (++) Tx DMA Descriptors Tab
00259         (++) Length of Rx Buffers
00260 
00261       (+) Call the function HAL_ETH_DescAssignMemory() to assign data buffers
00262           for each Rx DMA Descriptor
00263 
00264       (+) Call the function HAL_ETH_DeInit() to restore the default configuration
00265           of the selected ETH peripheral.
00266 
00267 @endverbatim
00268   * @{
00269   */
00270 
00271 /**
00272   * @brief  Initialize the Ethernet peripheral registers.
00273   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00274   *         the configuration information for ETHERNET module
00275   * @retval HAL status
00276   */
00277 HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth)
00278 {
00279   uint32_t tickstart;
00280 
00281   if(heth == NULL)
00282   {
00283     return HAL_ERROR;
00284   }
00285 
00286 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
00287 
00288   if(heth->gState == HAL_ETH_STATE_RESET)
00289   {
00290     /* Allocate lock resource and initialize it */
00291     heth->Lock = HAL_UNLOCKED;
00292 
00293     ETH_InitCallbacksToDefault(heth);
00294 
00295     if(heth->MspInitCallback == NULL)
00296     {
00297       heth->MspInitCallback = HAL_ETH_MspInit;
00298     }
00299 
00300     /* Init the low level hardware */
00301     heth->MspInitCallback(heth);
00302   }
00303 
00304 #else
00305 
00306   /* Check the ETH peripheral state */
00307   if(heth->gState == HAL_ETH_STATE_RESET)
00308   {
00309     /* Init the low level hardware : GPIO, CLOCK, NVIC. */
00310     HAL_ETH_MspInit(heth);
00311   }
00312 #endif /* (USE_HAL_ETH_REGISTER_CALLBACKS) */
00313 
00314   heth->gState = HAL_ETH_STATE_BUSY;
00315 
00316   __HAL_RCC_SYSCFG_CLK_ENABLE();
00317 
00318   if(heth->Init.MediaInterface == HAL_ETH_MII_MODE)
00319   {
00320     HAL_SYSCFG_ETHInterfaceSelect(SYSCFG_ETH_MII);
00321   }
00322   else
00323   {
00324     HAL_SYSCFG_ETHInterfaceSelect(SYSCFG_ETH_RMII);
00325   }
00326 
00327   /* Ethernet Software reset */
00328   /* Set the SWR bit: resets all MAC subsystem internal registers and logic */
00329   /* After reset all the registers holds their respective reset values */
00330   SET_BIT(heth->Instance->DMAMR, ETH_DMAMR_SWR);
00331 
00332   /* Get tick */
00333   tickstart = HAL_GetTick();
00334 
00335   /* Wait for software reset */
00336   while (READ_BIT(heth->Instance->DMAMR, ETH_DMAMR_SWR) > 0U)
00337   {
00338     if(((HAL_GetTick() - tickstart ) > ETH_SWRESET_TIMEOUT))
00339     {
00340       /* Set Error Code */
00341       heth->ErrorCode = HAL_ETH_ERROR_TIMEOUT;
00342       /* Set State as Error */
00343       heth->gState = HAL_ETH_STATE_ERROR;
00344       /* Return Error */
00345       return HAL_ERROR;
00346     }
00347   }
00348 
00349   /*------------------ MDIO CSR Clock Range Configuration --------------------*/
00350   ETH_MAC_MDIO_ClkConfig(heth);
00351 
00352   /*------------------ MAC LPI 1US Tic Counter Configuration --------------------*/
00353   WRITE_REG(heth->Instance->MAC1USTCR, (((uint32_t)HAL_RCC_GetHCLKFreq() / ETH_MAC_US_TICK) - 1U));
00354 
00355   /*------------------ MAC, MTL and DMA default Configuration ----------------*/
00356   ETH_MACDMAConfig(heth);
00357 
00358   /* SET DSL to 64 bit */
00359   MODIFY_REG(heth->Instance->DMACCR, ETH_DMACCR_DSL, ETH_DMACCR_DSL_64BIT);
00360 
00361   /* Set Receive Buffers Length (must be a multiple of 4) */
00362   if ((heth->Init.RxBuffLen % 0x4U) != 0x0U)
00363   {
00364     /* Set Error Code */
00365     heth->ErrorCode = HAL_ETH_ERROR_PARAM;
00366     /* Set State as Error */
00367     heth->gState = HAL_ETH_STATE_ERROR;
00368     /* Return Error */
00369     return HAL_ERROR;
00370   }
00371   else
00372   {
00373     MODIFY_REG(heth->Instance->DMACRCR, ETH_DMACRCR_RBSZ, ((heth->Init.RxBuffLen) << 1));
00374   }
00375 
00376   /*------------------ DMA Tx Descriptors Configuration ----------------------*/
00377   ETH_DMATxDescListInit(heth);
00378 
00379   /*------------------ DMA Rx Descriptors Configuration ----------------------*/
00380   ETH_DMARxDescListInit(heth);
00381 
00382   /*--------------------- ETHERNET MAC Address Configuration ------------------*/
00383   /* Set MAC addr bits 32 to 47 */
00384   heth->Instance->MACA0HR = (((uint32_t)(heth->Init.MACAddr[5]) << 8) | (uint32_t)heth->Init.MACAddr[4]);
00385   /* Set MAC addr bits 0 to 31 */
00386   heth->Instance->MACA0LR = (((uint32_t)(heth->Init.MACAddr[3]) << 24) | ((uint32_t)(heth->Init.MACAddr[2]) << 16) |
00387                              ((uint32_t)(heth->Init.MACAddr[1]) << 8) | (uint32_t)heth->Init.MACAddr[0]);
00388 
00389   heth->ErrorCode = HAL_ETH_ERROR_NONE;
00390   heth->gState = HAL_ETH_STATE_READY;
00391   heth->RxState = HAL_ETH_STATE_READY;
00392 
00393   return HAL_OK;
00394 }
00395 
00396 /**
00397   * @brief  DeInitializes the ETH peripheral.
00398   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00399   *         the configuration information for ETHERNET module
00400   * @retval HAL status
00401   */
00402 HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth)
00403 {
00404   /* Set the ETH peripheral state to BUSY */
00405   heth->gState = HAL_ETH_STATE_BUSY;
00406 
00407 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
00408 
00409   if(heth->MspDeInitCallback == NULL)
00410   {
00411     heth->MspDeInitCallback = HAL_ETH_MspDeInit;
00412   }
00413   /* DeInit the low level hardware */
00414   heth->MspDeInitCallback(heth);
00415 #else
00416 
00417   /* De-Init the low level hardware : GPIO, CLOCK, NVIC. */
00418   HAL_ETH_MspDeInit(heth);
00419 
00420 #endif /* (USE_HAL_ETH_REGISTER_CALLBACKS) */
00421 
00422   /* Set ETH HAL state to Disabled */
00423   heth->gState= HAL_ETH_STATE_RESET;
00424 
00425   /* Return function status */
00426   return HAL_OK;
00427 }
00428 
00429 /**
00430   * @brief  Initializes the ETH MSP.
00431   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00432   *         the configuration information for ETHERNET module
00433   * @retval None
00434   */
00435 __weak void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
00436 {
00437   /* Prevent unused argument(s) compilation warning */
00438   UNUSED(heth);
00439   /* NOTE : This function Should not be modified, when the callback is needed,
00440   the HAL_ETH_MspInit could be implemented in the user file
00441   */
00442 }
00443 
00444 /**
00445   * @brief  DeInitializes ETH MSP.
00446   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00447   *         the configuration information for ETHERNET module
00448   * @retval None
00449   */
00450 __weak void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
00451 {
00452   /* Prevent unused argument(s) compilation warning */
00453   UNUSED(heth);
00454   /* NOTE : This function Should not be modified, when the callback is needed,
00455   the HAL_ETH_MspDeInit could be implemented in the user file
00456   */
00457 }
00458 
00459 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
00460 /**
00461   * @brief  Register a User ETH Callback
00462   *         To be used instead of the weak predefined callback
00463   * @param heth eth handle
00464   * @param CallbackID ID of the callback to be registered
00465   *        This parameter can be one of the following values:
00466   *          @arg @ref HAL_ETH_TX_COMPLETE_CB_ID Tx Complete Callback ID
00467   *          @arg @ref HAL_ETH_RX_COMPLETE_CB_ID Rx Complete Callback ID
00468   *          @arg @ref HAL_ETH_DMA_ERROR_CB_ID   DMA Error Callback ID
00469   *          @arg @ref HAL_ETH_MAC_ERROR_CB_ID   MAC Error Callback ID
00470   *          @arg @ref HAL_ETH_PMT_CB_ID         Power Management Callback ID
00471   *          @arg @ref HAL_ETH_EEE_CB_ID         EEE Callback ID
00472   *          @arg @ref HAL_ETH_WAKEUP_CB_ID      Wake UP Callback ID
00473   *          @arg @ref HAL_ETH_MSPINIT_CB_ID     MspInit callback ID
00474   *          @arg @ref HAL_ETH_MSPDEINIT_CB_ID   MspDeInit callback ID
00475   * @param pCallback pointer to the Callback function
00476   * @retval status
00477   */
00478 HAL_StatusTypeDef HAL_ETH_RegisterCallback(ETH_HandleTypeDef *heth, HAL_ETH_CallbackIDTypeDef CallbackID, pETH_CallbackTypeDef pCallback)
00479 {
00480   HAL_StatusTypeDef status = HAL_OK;
00481 
00482   if(pCallback == NULL)
00483   {
00484     /* Update the error code */
00485     heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
00486 
00487     return HAL_ERROR;
00488   }
00489   /* Process locked */
00490   __HAL_LOCK(heth);
00491 
00492   if(heth->gState == HAL_ETH_STATE_READY)
00493   {
00494     switch (CallbackID)
00495     {
00496     case HAL_ETH_TX_COMPLETE_CB_ID :
00497       heth->TxCpltCallback = pCallback;
00498       break;
00499 
00500     case HAL_ETH_RX_COMPLETE_CB_ID :
00501       heth->RxCpltCallback = pCallback;
00502       break;
00503 
00504     case HAL_ETH_DMA_ERROR_CB_ID :
00505       heth->DMAErrorCallback = pCallback;
00506       break;
00507 
00508     case HAL_ETH_MAC_ERROR_CB_ID :
00509       heth->MACErrorCallback = pCallback;
00510       break;
00511 
00512     case HAL_ETH_PMT_CB_ID :
00513       heth->PMTCallback = pCallback;
00514       break;
00515 
00516     case HAL_ETH_EEE_CB_ID :
00517       heth->EEECallback = pCallback;
00518       break;
00519 
00520     case HAL_ETH_WAKEUP_CB_ID :
00521       heth->WakeUpCallback = pCallback;
00522       break;
00523 
00524     case HAL_ETH_MSPINIT_CB_ID :
00525       heth->MspInitCallback = pCallback;
00526       break;
00527 
00528    case HAL_ETH_MSPDEINIT_CB_ID :
00529       heth->MspDeInitCallback = pCallback;
00530       break;
00531 
00532     default :
00533       /* Update the error code */
00534       heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
00535       /* Return error status */
00536       status =  HAL_ERROR;
00537       break;
00538     }
00539   }
00540   else if(heth->gState == HAL_ETH_STATE_RESET)
00541   {
00542     switch (CallbackID)
00543     {
00544     case HAL_ETH_MSPINIT_CB_ID :
00545       heth->MspInitCallback = pCallback;
00546       break;
00547 
00548    case HAL_ETH_MSPDEINIT_CB_ID :
00549       heth->MspDeInitCallback = pCallback;
00550       break;
00551 
00552     default :
00553       /* Update the error code */
00554       heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
00555      /* Return error status */
00556       status =  HAL_ERROR;
00557       break;
00558     }
00559   }
00560   else
00561   {
00562     /* Update the error code */
00563     heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
00564     /* Return error status */
00565     status =  HAL_ERROR;
00566   }
00567 
00568   /* Release Lock */
00569   __HAL_UNLOCK(heth);
00570 
00571   return status;
00572 }
00573 
00574 /**
00575   * @brief  Unregister an ETH Callback
00576   *         ETH callabck is redirected to the weak predefined callback
00577   * @param heth eth handle
00578   * @param CallbackID ID of the callback to be unregistered
00579   *        This parameter can be one of the following values:
00580   *          @arg @ref HAL_ETH_TX_COMPLETE_CB_ID Tx Complete Callback ID
00581   *          @arg @ref HAL_ETH_RX_COMPLETE_CB_ID Rx Complete Callback ID
00582   *          @arg @ref HAL_ETH_DMA_ERROR_CB_ID   DMA Error Callback ID
00583   *          @arg @ref HAL_ETH_MAC_ERROR_CB_ID   MAC Error Callback ID
00584   *          @arg @ref HAL_ETH_PMT_CB_ID         Power Management Callback ID
00585   *          @arg @ref HAL_ETH_EEE_CB_ID         EEE Callback ID
00586   *          @arg @ref HAL_ETH_WAKEUP_CB_ID      Wake UP Callback ID
00587   *          @arg @ref HAL_ETH_MSPINIT_CB_ID     MspInit callback ID
00588   *          @arg @ref HAL_ETH_MSPDEINIT_CB_ID   MspDeInit callback ID
00589   * @retval status
00590   */
00591 HAL_StatusTypeDef HAL_ETH_UnRegisterCallback(ETH_HandleTypeDef *heth, HAL_ETH_CallbackIDTypeDef CallbackID)
00592 {
00593   HAL_StatusTypeDef status = HAL_OK;
00594 
00595   /* Process locked */
00596   __HAL_LOCK(heth);
00597 
00598   if(heth->gState == HAL_ETH_STATE_READY)
00599   {
00600     switch (CallbackID)
00601     {
00602     case HAL_ETH_TX_COMPLETE_CB_ID :
00603       heth->TxCpltCallback = HAL_ETH_TxCpltCallback;
00604       break;
00605 
00606     case HAL_ETH_RX_COMPLETE_CB_ID :
00607       heth->RxCpltCallback = HAL_ETH_RxCpltCallback;
00608       break;
00609 
00610     case HAL_ETH_DMA_ERROR_CB_ID :
00611       heth->DMAErrorCallback = HAL_ETH_DMAErrorCallback;
00612       break;
00613 
00614     case HAL_ETH_MAC_ERROR_CB_ID :
00615       heth->MACErrorCallback = HAL_ETH_MACErrorCallback;
00616       break;
00617 
00618     case HAL_ETH_PMT_CB_ID :
00619       heth->PMTCallback = HAL_ETH_PMTCallback;
00620       break;
00621 
00622     case HAL_ETH_EEE_CB_ID :
00623       heth->EEECallback = HAL_ETH_EEECallback;
00624       break;
00625 
00626     case HAL_ETH_WAKEUP_CB_ID :
00627       heth->WakeUpCallback = HAL_ETH_WakeUpCallback;
00628       break;
00629 
00630     case HAL_ETH_MSPINIT_CB_ID :
00631       heth->MspInitCallback = HAL_ETH_MspInit;
00632       break;
00633 
00634    case HAL_ETH_MSPDEINIT_CB_ID :
00635       heth->MspDeInitCallback = HAL_ETH_MspDeInit;
00636       break;
00637 
00638     default :
00639       /* Update the error code */
00640       heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
00641      /* Return error status */
00642       status =  HAL_ERROR;
00643       break;
00644     }
00645   }
00646   else if(heth->gState == HAL_ETH_STATE_RESET)
00647   {
00648     switch (CallbackID)
00649     {
00650     case HAL_ETH_MSPINIT_CB_ID :
00651       heth->MspInitCallback = HAL_ETH_MspInit;
00652       break;
00653 
00654    case HAL_ETH_MSPDEINIT_CB_ID :
00655       heth->MspDeInitCallback = HAL_ETH_MspDeInit;
00656       break;
00657 
00658     default :
00659       /* Update the error code */
00660       heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
00661      /* Return error status */
00662       status =  HAL_ERROR;
00663       break;
00664     }
00665   }
00666   else
00667   {
00668     /* Update the error code */
00669     heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
00670     /* Return error status */
00671     status =  HAL_ERROR;
00672   }
00673 
00674   /* Release Lock */
00675   __HAL_UNLOCK(heth);
00676 
00677   return status;
00678 }
00679 #endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
00680 
00681 /**
00682   * @brief  Assign memory buffers to a DMA Rx descriptor
00683   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00684   *         the configuration information for ETHERNET module
00685   * @param  Index : index of the DMA Rx descriptor
00686   *                  this parameter can be a value from 0x0 to (ETH_RX_DESC_CNT -1)
00687   * @param  pBuffer1: address of buffer 1
00688   * @param  pBuffer2: address of buffer 2 if available
00689   * @retval HAL status
00690   */
00691 HAL_StatusTypeDef HAL_ETH_DescAssignMemory(ETH_HandleTypeDef *heth, uint32_t Index, uint8_t *pBuffer1, uint8_t *pBuffer2)
00692 {
00693   ETH_DMADescTypeDef *dmarxdesc = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[Index];
00694 
00695   if((pBuffer1 == NULL) || (Index >= (uint32_t)ETH_RX_DESC_CNT))
00696   {
00697     /* Set Error Code */
00698     heth->ErrorCode = HAL_ETH_ERROR_PARAM;
00699     /* Return Error */
00700     return HAL_ERROR;
00701   }
00702 
00703   /* write buffer address to RDES0 */
00704   WRITE_REG(dmarxdesc->DESC0, (uint32_t)pBuffer1);
00705   /* store buffer address */
00706   WRITE_REG(dmarxdesc->BackupAddr0, (uint32_t)pBuffer1);
00707   /* set buffer address valid bit to RDES3 */
00708   SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_BUF1V);
00709 
00710   if(pBuffer2 != NULL)
00711   {
00712     /* write buffer 2 address to RDES1 */
00713     WRITE_REG(dmarxdesc->DESC2, (uint32_t)pBuffer2);
00714      /* store buffer 2 address */
00715     WRITE_REG(dmarxdesc->BackupAddr1, (uint32_t)pBuffer2);
00716     /* set buffer 2 address valid bit to RDES3 */
00717     SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_BUF2V);
00718   }
00719   /* set OWN bit to RDES3 */
00720   SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_OWN);
00721 
00722   return HAL_OK;
00723 }
00724 
00725 /**
00726   * @}
00727   */
00728 
00729 /** @defgroup ETH_Exported_Functions_Group2 IO operation functions
00730   *  @brief ETH Transmit and Receive functions
00731   *
00732 @verbatim
00733   ==============================================================================
00734                       ##### IO operation functions #####
00735   ==============================================================================
00736   [..]
00737     This subsection provides a set of functions allowing to manage the ETH
00738     data transfer.
00739 
00740 @endverbatim
00741   * @{
00742   */
00743 
00744 /**
00745   * @brief  Enables Ethernet MAC and DMA reception and transmission
00746   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00747   *         the configuration information for ETHERNET module
00748   * @retval HAL status
00749   */
00750 HAL_StatusTypeDef HAL_ETH_Start(ETH_HandleTypeDef *heth)
00751 {
00752   if(heth->gState == HAL_ETH_STATE_READY)
00753   {
00754     heth->gState = HAL_ETH_STATE_BUSY;
00755 
00756     /* Enable the MAC transmission */
00757     SET_BIT(heth->Instance->MACCR, ETH_MACCR_TE);
00758 
00759     /* Enable the MAC reception */
00760     SET_BIT(heth->Instance->MACCR, ETH_MACCR_RE);
00761 
00762     /* Set the Flush Transmit FIFO bit */
00763     SET_BIT(heth->Instance->MTLTQOMR, ETH_MTLTQOMR_FTQ);
00764 
00765     /* Enable the DMA transmission */
00766     SET_BIT(heth->Instance->DMACTCR, ETH_DMACTCR_ST);
00767 
00768     /* Enable the DMA reception */
00769     SET_BIT(heth->Instance->DMACRCR, ETH_DMACRCR_SR);
00770 
00771     /* Clear Tx and Rx process stopped flags */
00772     heth->Instance->DMACSR |= (ETH_DMACSR_TPS | ETH_DMACSR_RPS);
00773 
00774     heth->gState = HAL_ETH_STATE_READY;
00775     heth->RxState = HAL_ETH_STATE_BUSY_RX;
00776 
00777     return HAL_OK;
00778   }
00779   else
00780   {
00781     return HAL_ERROR;
00782   }
00783 }
00784 
00785 /**
00786   * @brief  Enables Ethernet MAC and DMA reception/transmission in Interrupt mode
00787   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00788   *         the configuration information for ETHERNET module
00789   * @retval HAL status
00790   */
00791 HAL_StatusTypeDef HAL_ETH_Start_IT(ETH_HandleTypeDef *heth)
00792 {
00793   uint32_t descindex;
00794 
00795   ETH_DMADescTypeDef *dmarxdesc;
00796 
00797   if(heth->gState == HAL_ETH_STATE_READY)
00798   {
00799     heth->gState = HAL_ETH_STATE_BUSY;
00800 
00801     /* Set IOC bit to all Rx descriptors */
00802     for(descindex = 0; descindex < (uint32_t)ETH_RX_DESC_CNT; descindex++)
00803     {
00804       dmarxdesc = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[descindex];
00805       SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_IOC);
00806     }
00807 
00808     /* save IT mode to ETH Handle */
00809     heth->RxDescList.ItMode = 1U;
00810 
00811     /* Enable the MAC transmission */
00812     SET_BIT(heth->Instance->MACCR, ETH_MACCR_TE);
00813 
00814     /* Enable the MAC reception */
00815     SET_BIT(heth->Instance->MACCR, ETH_MACCR_RE);
00816 
00817     /* Set the Flush Transmit FIFO bit */
00818     SET_BIT(heth->Instance->MTLTQOMR, ETH_MTLTQOMR_FTQ);
00819 
00820     /* Enable the DMA transmission */
00821     SET_BIT(heth->Instance->DMACTCR, ETH_DMACTCR_ST);
00822 
00823     /* Enable the DMA reception */
00824     SET_BIT(heth->Instance->DMACRCR, ETH_DMACRCR_SR);
00825 
00826     /* Clear Tx and Rx process stopped flags */
00827     heth->Instance->DMACSR |= (ETH_DMACSR_TPS | ETH_DMACSR_RPS);
00828 
00829     /* Enable ETH DMA interrupts:
00830     - Tx complete interrupt
00831     - Rx complete interrupt
00832     - Fatal bus interrupt
00833     */
00834     __HAL_ETH_DMA_ENABLE_IT(heth, (ETH_DMACIER_NIE | ETH_DMACIER_RIE | ETH_DMACIER_TIE  |
00835                                    ETH_DMACIER_FBEE | ETH_DMACIER_AIE));
00836 
00837     heth->gState = HAL_ETH_STATE_READY;
00838     heth->RxState = HAL_ETH_STATE_BUSY_RX;
00839 
00840     return HAL_OK;
00841   }
00842   else
00843   {
00844     return HAL_ERROR;
00845   }
00846 }
00847 
00848 /**
00849   * @brief  Stop Ethernet MAC and DMA reception/transmission
00850   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00851   *         the configuration information for ETHERNET module
00852   * @retval HAL status
00853   */
00854 HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth)
00855 {
00856   if(heth->gState != HAL_ETH_STATE_RESET)
00857   {
00858      /* Set the ETH peripheral state to BUSY */
00859     heth->gState = HAL_ETH_STATE_BUSY;
00860 
00861     /* Disable the DMA transmission */
00862     CLEAR_BIT(heth->Instance->DMACTCR, ETH_DMACTCR_ST);
00863 
00864     /* Disable the DMA reception */
00865     CLEAR_BIT(heth->Instance->DMACRCR, ETH_DMACRCR_SR);
00866 
00867     /* Disable the MAC reception */
00868     CLEAR_BIT( heth->Instance->MACCR, ETH_MACCR_RE);
00869 
00870     /* Set the Flush Transmit FIFO bit */
00871     SET_BIT(heth->Instance->MTLTQOMR, ETH_MTLTQOMR_FTQ);
00872 
00873     /* Disable the MAC transmission */
00874     CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_TE);
00875 
00876     heth->gState = HAL_ETH_STATE_READY;
00877     heth->RxState = HAL_ETH_STATE_READY;
00878 
00879     /* Return function status */
00880     return HAL_OK;
00881   }
00882   else
00883   {
00884     return HAL_ERROR;
00885   }
00886 }
00887 
00888 /**
00889   * @brief  Stop Ethernet MAC and DMA reception/transmission in Interrupt mode
00890   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00891   *         the configuration information for ETHERNET module
00892   * @retval HAL status
00893   */
00894 HAL_StatusTypeDef HAL_ETH_Stop_IT(ETH_HandleTypeDef *heth)
00895 {
00896   ETH_DMADescTypeDef *dmarxdesc;
00897   uint32_t descindex;
00898 
00899   if(heth->gState != HAL_ETH_STATE_RESET)
00900   {
00901     /* Set the ETH peripheral state to BUSY */
00902     heth->gState = HAL_ETH_STATE_BUSY;
00903 
00904     /* Disable interrupts:
00905     - Tx complete interrupt
00906     - Rx complete interrupt
00907     - Fatal bus interrupt
00908     */
00909     __HAL_ETH_DMA_DISABLE_IT(heth, (ETH_DMACIER_NIE | ETH_DMACIER_RIE | ETH_DMACIER_TIE  |
00910                                    ETH_DMACIER_FBEE | ETH_DMACIER_AIE));
00911 
00912     /* Disable the DMA transmission */
00913     CLEAR_BIT(heth->Instance->DMACTCR, ETH_DMACTCR_ST);
00914 
00915     /* Disable the DMA reception */
00916     CLEAR_BIT(heth->Instance->DMACRCR, ETH_DMACRCR_SR);
00917 
00918     /* Disable the MAC reception */
00919     CLEAR_BIT( heth->Instance->MACCR, ETH_MACCR_RE);
00920 
00921     /* Set the Flush Transmit FIFO bit */
00922     SET_BIT(heth->Instance->MTLTQOMR, ETH_MTLTQOMR_FTQ);
00923 
00924     /* Disable the MAC transmission */
00925     CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_TE);
00926 
00927     /* Clear IOC bit to all Rx descriptors */
00928     for(descindex = 0; descindex < (uint32_t)ETH_RX_DESC_CNT; descindex++)
00929     {
00930       dmarxdesc = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[descindex];
00931       CLEAR_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_IOC);
00932     }
00933 
00934     heth->RxDescList.ItMode = 0U;
00935 
00936     heth->gState = HAL_ETH_STATE_READY;
00937     heth->RxState = HAL_ETH_STATE_READY;
00938 
00939     /* Return function status */
00940     return HAL_OK;
00941   }
00942   else
00943   {
00944     return HAL_ERROR;
00945   }
00946 }
00947 
00948 /**
00949   * @brief  Sends an Ethernet Packet in polling mode.
00950   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
00951   *         the configuration information for ETHERNET module
00952   * @param  pTxConfig: Hold the configuration of packet to be transmitted
00953   * @param  Timeout: timeout value
00954   * @retval HAL status
00955   */
00956 HAL_StatusTypeDef HAL_ETH_Transmit(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig, uint32_t Timeout)
00957 {
00958   uint32_t tickstart;
00959   const ETH_DMADescTypeDef *dmatxdesc;
00960 
00961   if(pTxConfig == NULL)
00962   {
00963     heth->ErrorCode |= HAL_ETH_ERROR_PARAM;
00964     return HAL_ERROR;
00965   }
00966 
00967   if(heth->gState == HAL_ETH_STATE_READY)
00968   {
00969     /* Config DMA Tx descriptor by Tx Packet info */
00970     if (ETH_Prepare_Tx_Descriptors(heth, pTxConfig, 0) != HAL_ETH_ERROR_NONE)
00971     {
00972       /* Set the ETH error code */
00973       heth->ErrorCode |= HAL_ETH_ERROR_BUSY;
00974       return HAL_ERROR;
00975     }
00976 
00977     dmatxdesc = (ETH_DMADescTypeDef *)(&heth->TxDescList)->TxDesc[heth->TxDescList.CurTxDesc];
00978 
00979     /* Incr current tx desc index */
00980     INCR_TX_DESC_INDEX(heth->TxDescList.CurTxDesc, 1U);
00981 
00982     /* Start transmission */
00983     /* issue a poll command to Tx DMA by writing address of next immediate free descriptor */
00984     WRITE_REG(heth->Instance->DMACTDTPR, (uint32_t)(heth->TxDescList.TxDesc[heth->TxDescList.CurTxDesc]));
00985 
00986     tickstart = HAL_GetTick();
00987 
00988     /* Wait for data to be transmitted or timeout occurred */
00989     while((dmatxdesc->DESC3 & ETH_DMATXNDESCWBF_OWN) != (uint32_t)RESET)
00990     {
00991       if((heth->Instance->DMACSR & ETH_DMACSR_FBE) != (uint32_t)RESET)
00992       {
00993         heth->ErrorCode |= HAL_ETH_ERROR_DMA;
00994         heth->DMAErrorCode = heth->Instance->DMACSR;
00995         /* Set ETH HAL State to Ready */
00996         heth->gState = HAL_ETH_STATE_ERROR;
00997         /* Return function status */
00998         return HAL_ERROR;
00999       }
01000 
01001       /* Check for the Timeout */
01002       if(Timeout != HAL_MAX_DELAY)
01003       {
01004         if(((HAL_GetTick() - tickstart ) > Timeout) || (Timeout == 0U))
01005         {
01006           heth->ErrorCode |= HAL_ETH_ERROR_TIMEOUT;
01007           heth->gState = HAL_ETH_STATE_ERROR;
01008           return HAL_ERROR;
01009         }
01010       }
01011     }
01012 
01013     /* Return function status */
01014     return HAL_OK;
01015   }
01016   else
01017   {
01018     return HAL_ERROR;
01019   }
01020 }
01021 
01022 /**
01023   * @brief  Sends an Ethernet Packet in interrupt mode.
01024   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01025   *         the configuration information for ETHERNET module
01026   * @param  pTxConfig: Hold the configuration of packet to be transmitted
01027   * @retval HAL status
01028   */
01029 HAL_StatusTypeDef HAL_ETH_Transmit_IT(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig)
01030 {
01031   if(pTxConfig == NULL)
01032   {
01033     heth->ErrorCode |= HAL_ETH_ERROR_PARAM;
01034     return HAL_ERROR;
01035   }
01036 
01037   if(heth->gState == HAL_ETH_STATE_READY)
01038   {
01039     /* Config DMA Tx descriptor by Tx Packet info */
01040     if (ETH_Prepare_Tx_Descriptors(heth, pTxConfig, 1) != HAL_ETH_ERROR_NONE)
01041     {
01042       heth->ErrorCode |= HAL_ETH_ERROR_BUSY;
01043       return HAL_ERROR;
01044     }
01045 
01046     /* Incr current tx desc index */
01047     INCR_TX_DESC_INDEX(heth->TxDescList.CurTxDesc, 1U);
01048 
01049     /* Start transmission */
01050     /* issue a poll command to Tx DMA by writing address of next immediate free descriptor */
01051     WRITE_REG(heth->Instance->DMACTDTPR, (uint32_t)(heth->TxDescList.TxDesc[heth->TxDescList.CurTxDesc]));
01052 
01053     return HAL_OK;
01054 
01055   }
01056   else
01057   {
01058     return HAL_ERROR;
01059   }
01060 }
01061 
01062 /**
01063   * @brief  Checks for received Packets.
01064   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01065   *         the configuration information for ETHERNET module
01066   * @retval  1: A Packet is received
01067   *          0: no Packet received
01068   */
01069 uint8_t HAL_ETH_IsRxDataAvailable(ETH_HandleTypeDef *heth)
01070 {
01071   ETH_RxDescListTypeDef *dmarxdesclist = &heth->RxDescList;
01072   uint32_t descidx = dmarxdesclist->CurRxDesc;
01073   ETH_DMADescTypeDef *dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01074   uint32_t descscancnt = 0;
01075   uint32_t appdesccnt = 0, firstappdescidx = 0;
01076 
01077   if(dmarxdesclist->AppDescNbr != 0U)
01078   {
01079     /* data already received by not yet processed*/
01080     return 0;
01081   }
01082 
01083   /* Check if descriptor is not owned by DMA */
01084   while((READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_OWN) == (uint32_t)RESET) && (descscancnt < (uint32_t)ETH_RX_DESC_CNT))
01085   {
01086     descscancnt++;
01087 
01088     /* Check if last descriptor */
01089     if(READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_LD) != (uint32_t)RESET)
01090     {
01091       /* Increment the number of descriptors to be passed to the application */
01092       appdesccnt += 1U;
01093 
01094       if(appdesccnt == 1U)
01095       {
01096         WRITE_REG(firstappdescidx, descidx);
01097       }
01098 
01099       /* Increment current rx descriptor index */
01100       INCR_RX_DESC_INDEX(descidx, 1U);
01101 
01102       /* Check for Context descriptor */
01103       /* Get current descriptor address */
01104       dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01105 
01106       if(READ_BIT(dmarxdesc->DESC3,  ETH_DMARXNDESCWBF_OWN)  == (uint32_t)RESET)
01107       {
01108         if(READ_BIT(dmarxdesc->DESC3,  ETH_DMARXNDESCWBF_CTXT)  != (uint32_t)RESET)
01109         {
01110           /* Increment the number of descriptors to be passed to the application */
01111           dmarxdesclist->AppContextDesc = 1;
01112           /* Increment current rx descriptor index */
01113           INCR_RX_DESC_INDEX(descidx, 1U);
01114         }
01115       }
01116       /* Fill information to Rx descriptors list */
01117       dmarxdesclist->CurRxDesc = descidx;
01118       dmarxdesclist->FirstAppDesc = firstappdescidx;
01119       dmarxdesclist->AppDescNbr = appdesccnt;
01120 
01121       /* Return function status */
01122       return 1;
01123     }
01124     /* Check if first descriptor */
01125     else if(READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_FD) != (uint32_t)RESET)
01126     {
01127       WRITE_REG(firstappdescidx, descidx);
01128       /* Increment the number of descriptors to be passed to the application */
01129       appdesccnt = 1U;
01130 
01131       /* Increment current rx descriptor index */
01132       INCR_RX_DESC_INDEX(descidx, 1U);
01133       /* Get current descriptor address */
01134       dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01135     }
01136     /* It should be an intermediate descriptor */
01137     else
01138     {
01139       /* Increment the number of descriptors to be passed to the application */
01140       appdesccnt += 1U;
01141 
01142       /* Increment current rx descriptor index */
01143       INCR_RX_DESC_INDEX(descidx, 1U);
01144       /* Get current descriptor address */
01145       dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01146     }
01147   }
01148 
01149   /* Build Descriptors if an incomplete Packet is received */
01150   if(appdesccnt > 0U)
01151   {
01152     dmarxdesclist->CurRxDesc = descidx;
01153     dmarxdesclist->FirstAppDesc = firstappdescidx;
01154     descidx = firstappdescidx;
01155     dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01156 
01157     for(descscancnt = 0; descscancnt < appdesccnt; descscancnt++)
01158     {
01159       WRITE_REG(dmarxdesc->DESC0, dmarxdesc->BackupAddr0);
01160       WRITE_REG(dmarxdesc->DESC3, ETH_DMARXNDESCRF_BUF1V);
01161 
01162       if (READ_REG(dmarxdesc->BackupAddr1) != ((uint32_t)RESET))
01163       {
01164         WRITE_REG(dmarxdesc->DESC2, dmarxdesc->BackupAddr1);
01165         SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_BUF2V);
01166       }
01167 
01168       SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_OWN);
01169 
01170       if(dmarxdesclist->ItMode != ((uint32_t)RESET))
01171       {
01172         SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_IOC);
01173       }
01174       if(descscancnt < (appdesccnt - 1U))
01175       {
01176         /* Increment rx descriptor index */
01177         INCR_RX_DESC_INDEX(descidx, 1U);
01178         /* Get descriptor address */
01179         dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01180       }
01181     }
01182 
01183     /* Set the Tail pointer address to the last rx descriptor hold by the app */
01184     WRITE_REG(heth->Instance->DMACRDTPR, (uint32_t)dmarxdesc);
01185   }
01186 
01187   /* Fill information to Rx descriptors list: No received Packet */
01188   dmarxdesclist->AppDescNbr = 0U;
01189 
01190   return 0;
01191 }
01192 
01193 /**
01194   * @brief  This function gets the buffer address of last received Packet.
01195   * @note   Please insure to allocate the RxBuffer structure before calling this function
01196   *         how to use example:
01197   *           HAL_ETH_GetRxDataLength(heth, &Length);
01198   *           BuffersNbr = (Length / heth->Init.RxBuffLen) + 1;
01199   *           RxBuffer = (ETH_BufferTypeDef *)malloc(BuffersNbr * sizeof(ETH_BufferTypeDef));
01200   *           HAL_ETH_GetRxDataBuffer(heth, RxBuffer);
01201   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01202   *         the configuration information for ETHERNET module
01203   * @param  RxBuffer: Pointer to a ETH_BufferTypeDef structure
01204   * @retval HAL status
01205   */
01206 HAL_StatusTypeDef HAL_ETH_GetRxDataBuffer(ETH_HandleTypeDef *heth, ETH_BufferTypeDef *RxBuffer)
01207 {
01208   ETH_RxDescListTypeDef *dmarxdesclist = &heth->RxDescList;
01209   uint32_t descidx = dmarxdesclist->FirstAppDesc;
01210   uint32_t index, accumulatedlen = 0, lastdesclen;
01211   __IO const ETH_DMADescTypeDef *dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01212   ETH_BufferTypeDef *rxbuff = RxBuffer;
01213 
01214   if(rxbuff == NULL)
01215   {
01216     heth->ErrorCode = HAL_ETH_ERROR_PARAM;
01217     return HAL_ERROR;
01218   }
01219 
01220   if(dmarxdesclist->AppDescNbr == 0U)
01221   {
01222     if(HAL_ETH_IsRxDataAvailable(heth) == 0U)
01223     {
01224       /* No data to be transferred to the application */
01225       return HAL_ERROR;
01226     }
01227     else
01228     {
01229       descidx = dmarxdesclist->FirstAppDesc;
01230       dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01231     }
01232   }
01233 
01234   /* Get intermediate descriptors buffers: in case of the Packet is split into multi descriptors */
01235   for(index = 0; index < (dmarxdesclist->AppDescNbr - 1U); index++)
01236   {
01237     /* Get Address and length of the first buffer address */
01238     rxbuff->buffer = (uint8_t *) dmarxdesc->BackupAddr0;
01239     rxbuff->len =  heth->Init.RxBuffLen;
01240 
01241     /* Check if the second buffer address of this descriptor is valid */
01242     if(dmarxdesc->BackupAddr1 != 0U)
01243     {
01244       /* Point to next buffer */
01245       rxbuff = rxbuff->next;
01246       /* Get Address and length of the second buffer address */
01247       rxbuff->buffer = (uint8_t *) dmarxdesc->BackupAddr1;
01248       rxbuff->len =  heth->Init.RxBuffLen;
01249     }
01250     else
01251     {
01252       /* Nothing to do here */
01253     }
01254 
01255     /* get total length until this descriptor */
01256     accumulatedlen = READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_PL);
01257 
01258     /* Increment to next descriptor */
01259     INCR_RX_DESC_INDEX(descidx, 1U);
01260     dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01261 
01262     /* Point to next buffer */
01263     rxbuff = rxbuff->next;
01264   }
01265 
01266   /* last descriptor data length */
01267   lastdesclen = READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_PL) - accumulatedlen;
01268 
01269   /* Get Address of the first buffer address */
01270   rxbuff->buffer = (uint8_t *) dmarxdesc->BackupAddr0;
01271 
01272   /* data is in only one buffer */
01273   if(lastdesclen <= heth->Init.RxBuffLen)
01274   {
01275     rxbuff->len = lastdesclen;
01276   }
01277   /* data is in two buffers */
01278   else if(dmarxdesc->BackupAddr1 != 0U)
01279   {
01280     /* Get the Length of the first buffer address */
01281     rxbuff->len = heth->Init.RxBuffLen;
01282     /* Point to next buffer */
01283     rxbuff = rxbuff->next;
01284     /* Get the Address the Length of the second buffer address */
01285     rxbuff->buffer = (uint8_t *) dmarxdesc->BackupAddr1;
01286     rxbuff->len =  lastdesclen - (heth->Init.RxBuffLen);
01287   }
01288   else /* Buffer 2 not valid*/
01289   {
01290     return HAL_ERROR;
01291   }
01292 
01293   return HAL_OK;
01294 }
01295 
01296 /**
01297   * @brief  This function gets the length of last received Packet.
01298   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01299   *         the configuration information for ETHERNET module
01300   * @param  Length: parameter to hold Rx packet length
01301   * @retval HAL Status
01302   */
01303 HAL_StatusTypeDef HAL_ETH_GetRxDataLength(ETH_HandleTypeDef *heth, uint32_t *Length)
01304 {
01305   ETH_RxDescListTypeDef *dmarxdesclist = &heth->RxDescList;
01306   uint32_t descidx = dmarxdesclist->FirstAppDesc;
01307   __IO const ETH_DMADescTypeDef *dmarxdesc;
01308 
01309   if(dmarxdesclist->AppDescNbr == 0U)
01310   {
01311     if(HAL_ETH_IsRxDataAvailable(heth) == 0U)
01312     {
01313       /* No data to be transferred to the application */
01314       return HAL_ERROR;
01315     }
01316   }
01317 
01318   /* Get index of last descriptor */
01319   INCR_RX_DESC_INDEX(descidx, (dmarxdesclist->AppDescNbr - 1U));
01320   /* Point to last descriptor */
01321   dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01322 
01323   *Length = READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_PL);
01324 
01325   return HAL_OK;
01326 }
01327 
01328 /**
01329   * @brief  Get the Rx data info (Packet type, VLAN tag, Filters status, ...)
01330   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01331   *         the configuration information for ETHERNET module
01332   * @param  RxPacketInfo: parameter to hold info of received buffer
01333   * @retval HAL status
01334   */
01335 HAL_StatusTypeDef HAL_ETH_GetRxDataInfo(ETH_HandleTypeDef *heth, ETH_RxPacketInfo *RxPacketInfo)
01336 {
01337   ETH_RxDescListTypeDef *dmarxdesclist = &heth->RxDescList;
01338   uint32_t descidx = dmarxdesclist->FirstAppDesc;
01339   __IO const ETH_DMADescTypeDef *dmarxdesc;
01340 
01341   if(dmarxdesclist->AppDescNbr == 0U)
01342   {
01343     if(HAL_ETH_IsRxDataAvailable(heth) == 0U)
01344     {
01345       /* No data to be transferred to the application */
01346       return HAL_ERROR;
01347     }
01348   }
01349 
01350   /* Get index of last descriptor */
01351   INCR_RX_DESC_INDEX(descidx, ((dmarxdesclist->AppDescNbr) - 1U));
01352   /* Point to last descriptor */
01353   dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descidx];
01354 
01355   if((dmarxdesc->DESC3 & ETH_DMARXNDESCWBF_ES) != (uint32_t)RESET)
01356   {
01357     RxPacketInfo->ErrorCode = READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_ERRORS_MASK);
01358   }
01359   else
01360   {
01361     if(READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_RS0V) != 0U)
01362     {
01363 
01364       if(READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_LT) == ETH_DMARXNDESCWBF_LT_DVLAN)
01365       {
01366         RxPacketInfo->VlanTag = READ_BIT(dmarxdesc->DESC0, ETH_DMARXNDESCWBF_OVT);
01367         RxPacketInfo->InnerVlanTag = READ_BIT(dmarxdesc->DESC0, ETH_DMARXNDESCWBF_IVT) >> 16;
01368       }
01369       else
01370       {
01371         RxPacketInfo->VlanTag = READ_BIT(dmarxdesc->DESC0, ETH_DMARXNDESCWBF_OVT);
01372       }
01373     }
01374 
01375     if(READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_RS1V) != 0U)
01376     {
01377       /* Get Payload type */
01378       RxPacketInfo->PayloadType =READ_BIT( dmarxdesc->DESC1, ETH_DMARXNDESCWBF_PT);
01379       /* Get Header type */
01380       RxPacketInfo->HeaderType = READ_BIT(dmarxdesc->DESC1, (ETH_DMARXNDESCWBF_IPV4 | ETH_DMARXNDESCWBF_IPV6));
01381       /* Get Checksum status */
01382       RxPacketInfo->Checksum = READ_BIT(dmarxdesc->DESC1, (ETH_DMARXNDESCWBF_IPCE | ETH_DMARXNDESCWBF_IPCB | ETH_DMARXNDESCWBF_IPHE));
01383     }
01384 
01385     if(READ_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCWBF_RS2V) != 0U)
01386     {
01387       RxPacketInfo->MacFilterStatus = READ_BIT(dmarxdesc->DESC2, (ETH_DMARXNDESCWBF_HF | ETH_DMARXNDESCWBF_DAF | ETH_DMARXNDESCWBF_SAF | ETH_DMARXNDESCWBF_VF));
01388       RxPacketInfo->L3FilterStatus = READ_BIT(dmarxdesc->DESC2,  (ETH_DMARXNDESCWBF_L3FM | ETH_DMARXNDESCWBF_L3L4FM));
01389       RxPacketInfo->L4FilterStatus = READ_BIT(dmarxdesc->DESC2, (ETH_DMARXNDESCWBF_L4FM | ETH_DMARXNDESCWBF_L3L4FM));
01390     }
01391   }
01392 
01393   /* Get the segment count */
01394   WRITE_REG(RxPacketInfo->SegmentCnt, dmarxdesclist->AppDescNbr);
01395 
01396   return HAL_OK;
01397 }
01398 
01399 /**
01400 * @brief  This function gives back Rx Desc of the last received Packet
01401 *         to the DMA, so ETH DMA will be able to use these descriptors
01402 *         to receive next Packets.
01403 *         It should be called after processing the received Packet.
01404 * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01405 *         the configuration information for ETHERNET module
01406 * @retval HAL status.
01407 */
01408 HAL_StatusTypeDef HAL_ETH_BuildRxDescriptors(ETH_HandleTypeDef *heth)
01409 {
01410   ETH_RxDescListTypeDef *dmarxdesclist = &heth->RxDescList;
01411   uint32_t descindex = dmarxdesclist->FirstAppDesc;
01412   __IO ETH_DMADescTypeDef *dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descindex];
01413   uint32_t totalappdescnbr = dmarxdesclist->AppDescNbr;
01414   uint32_t descscan;
01415 
01416   if(dmarxdesclist->AppDescNbr == 0U)
01417   {
01418     /* No Rx descriptors to build */
01419     return HAL_ERROR;
01420   }
01421 
01422   if(dmarxdesclist->AppContextDesc != 0U)
01423   {
01424     /* A context descriptor is available */
01425     totalappdescnbr += 1U;
01426   }
01427 
01428   for(descscan =0; descscan < totalappdescnbr; descscan++)
01429   {
01430     WRITE_REG(dmarxdesc->DESC0, dmarxdesc->BackupAddr0);
01431     WRITE_REG(dmarxdesc->DESC3, ETH_DMARXNDESCRF_BUF1V);
01432 
01433     if (READ_REG(dmarxdesc->BackupAddr1) != 0U)
01434     {
01435       WRITE_REG(dmarxdesc->DESC2, dmarxdesc->BackupAddr1);
01436       SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_BUF2V);
01437     }
01438 
01439     SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_OWN);
01440 
01441     if(dmarxdesclist->ItMode != 0U)
01442     {
01443       SET_BIT(dmarxdesc->DESC3, ETH_DMARXNDESCRF_IOC);
01444     }
01445 
01446     if(descscan < (totalappdescnbr - 1U))
01447     {
01448       /* Increment rx descriptor index */
01449       INCR_RX_DESC_INDEX(descindex, 1U);
01450       /* Get descriptor address */
01451       dmarxdesc = (ETH_DMADescTypeDef *)dmarxdesclist->RxDesc[descindex];
01452     }
01453   }
01454 
01455   /* Set the Tail pointer address to the last rx descriptor hold by the app */
01456   WRITE_REG(heth->Instance->DMACRDTPR, (uint32_t)dmarxdesc);
01457 
01458   /* reset the Application desc number */
01459   WRITE_REG(dmarxdesclist->AppDescNbr, 0);
01460 
01461   /*  reset the application context descriptor */
01462   WRITE_REG(heth->RxDescList.AppContextDesc, 0);
01463 
01464   return HAL_OK;
01465 }
01466 
01467 
01468 /**
01469   * @brief  This function handles ETH interrupt request.
01470   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01471   *         the configuration information for ETHERNET module
01472   * @retval HAL status
01473   */
01474 void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth)
01475 {
01476   /* Packet received */
01477   if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMACSR_RI))
01478   {
01479     if(__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMACIER_RIE))
01480     {
01481 
01482 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01483       /*Call registered Receive complete callback*/
01484       heth->RxCpltCallback(heth);
01485 #else
01486       /* Receive complete callback */
01487       HAL_ETH_RxCpltCallback(heth);
01488 #endif  /* USE_HAL_ETH_REGISTER_CALLBACKS */
01489 
01490       /* Clear the Eth DMA Rx IT pending bits */
01491       __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMACSR_RI | ETH_DMACSR_NIS);
01492     }
01493   }
01494 
01495   /* Packet transmitted */
01496   if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMACSR_TI))
01497   {
01498     if(__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMACIER_TIE))
01499     {
01500 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01501         /*Call registered Transmit complete callback*/
01502         heth->TxCpltCallback(heth);
01503 #else
01504       /* Transfer complete callback */
01505       HAL_ETH_TxCpltCallback(heth);
01506 #endif  /* USE_HAL_ETH_REGISTER_CALLBACKS */
01507 
01508       /* Clear the Eth DMA Tx IT pending bits */
01509       __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMACSR_TI | ETH_DMACSR_NIS);
01510     }
01511   }
01512 
01513 
01514   /* ETH DMA Error */
01515   if(__HAL_ETH_DMA_GET_IT(heth, ETH_DMACSR_AIS))
01516   {
01517     if(__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMACIER_AIE))
01518     {
01519       heth->ErrorCode |= HAL_ETH_ERROR_DMA;
01520 
01521       /* if fatal bus error occurred */
01522       if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMACSR_FBE))
01523       {
01524         /* Get DMA error code  */
01525         heth->DMAErrorCode = READ_BIT(heth->Instance->DMACSR, (ETH_DMACSR_FBE | ETH_DMACSR_TPS | ETH_DMACSR_RPS));
01526 
01527         /* Disable all interrupts */
01528         __HAL_ETH_DMA_DISABLE_IT(heth, ETH_DMACIER_NIE | ETH_DMACIER_AIE);
01529 
01530         /* Set HAL state to ERROR */
01531         heth->gState = HAL_ETH_STATE_ERROR;
01532       }
01533       else
01534       {
01535         /* Get DMA error status  */
01536        heth->DMAErrorCode = READ_BIT(heth->Instance->DMACSR, (ETH_DMACSR_CDE | ETH_DMACSR_ETI | ETH_DMACSR_RWT |
01537                                                        ETH_DMACSR_RBU | ETH_DMACSR_AIS));
01538 
01539         /* Clear the interrupt summary flag */
01540         __HAL_ETH_DMA_CLEAR_IT(heth, (ETH_DMACSR_CDE | ETH_DMACSR_ETI | ETH_DMACSR_RWT |
01541                                     ETH_DMACSR_RBU | ETH_DMACSR_AIS));
01542       }
01543 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01544       /* Call registered DMA Error callback*/
01545       heth->DMAErrorCallback(heth);
01546 #else
01547       /* Ethernet DMA Error callback */
01548       HAL_ETH_DMAErrorCallback(heth);
01549 #endif  /* USE_HAL_ETH_REGISTER_CALLBACKS */
01550 
01551     }
01552   }
01553 
01554   /* ETH MAC Error IT */
01555   if(__HAL_ETH_MAC_GET_IT(heth, (ETH_MACIER_RXSTSIE | ETH_MACIER_TXSTSIE)))
01556   {
01557     /* Get MAC Rx Tx status and clear Status register pending bit */
01558     heth->MACErrorCode = READ_REG(heth->Instance->MACRXTXSR);
01559 
01560     heth->gState = HAL_ETH_STATE_ERROR;
01561 
01562 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01563     /* Call registered MAC Error callback*/
01564     heth->MACErrorCallback(heth);
01565 #else
01566     /* Ethernet MAC Error callback */
01567     HAL_ETH_MACErrorCallback(heth);
01568 #endif  /* USE_HAL_ETH_REGISTER_CALLBACKS */
01569 
01570     heth->MACErrorCode = (uint32_t)(0x0U);
01571   }
01572 
01573   /* ETH PMT IT */
01574   if(__HAL_ETH_MAC_GET_IT(heth, ETH_MAC_PMT_IT))
01575   {
01576     /* Get MAC Wake-up source and clear the status register pending bit */
01577     heth->MACWakeUpEvent = READ_BIT(heth->Instance->MACPCSR, (ETH_MACPCSR_RWKPRCVD | ETH_MACPCSR_MGKPRCVD));
01578 
01579 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01580     /* Call registered PMT callback*/
01581     heth->PMTCallback(heth);
01582 #else
01583     /* Ethernet PMT callback */
01584     HAL_ETH_PMTCallback(heth);
01585 #endif  /* USE_HAL_ETH_REGISTER_CALLBACKS */
01586 
01587     heth->MACWakeUpEvent = (uint32_t)(0x0U);
01588   }
01589 
01590   /* ETH EEE IT */
01591   if(__HAL_ETH_MAC_GET_IT(heth, ETH_MAC_LPI_IT))
01592   {
01593     /* Get MAC LPI interrupt source and clear the status register pending bit */
01594     heth->MACLPIEvent = READ_BIT(heth->Instance->MACPCSR, 0x0000000FU);
01595 
01596 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01597     /* Call registered EEE callback*/
01598     heth->EEECallback(heth);
01599 #else
01600     /* Ethernet EEE callback */
01601     HAL_ETH_EEECallback(heth);
01602 #endif  /* USE_HAL_ETH_REGISTER_CALLBACKS */
01603 
01604     heth->MACLPIEvent = (uint32_t)(0x0U);
01605   }
01606 
01607 #if defined(DUAL_CORE)
01608   if (HAL_GetCurrentCPUID() == CM7_CPUID)
01609   {
01610     /* check ETH WAKEUP exti flag */
01611     if(__HAL_ETH_WAKEUP_EXTI_GET_FLAG(ETH_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
01612     {
01613       /* Clear ETH WAKEUP Exti pending bit */
01614       __HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG(ETH_WAKEUP_EXTI_LINE);
01615 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01616       /* Call registered WakeUp callback*/
01617       heth->WakeUpCallback(heth);
01618 #else
01619       /* ETH WAKEUP callback */
01620       HAL_ETH_WakeUpCallback(heth);
01621 #endif
01622     }
01623   }
01624   else
01625   {
01626     /* check ETH WAKEUP exti flag */
01627     if(__HAL_ETH_WAKEUP_EXTID2_GET_FLAG(ETH_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
01628     {
01629       /* Clear ETH WAKEUP Exti pending bit */
01630       __HAL_ETH_WAKEUP_EXTID2_CLEAR_FLAG(ETH_WAKEUP_EXTI_LINE);
01631 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01632       /* Call registered WakeUp callback*/
01633       heth->WakeUpCallback(heth);
01634 #else
01635       /* ETH WAKEUP callback */
01636       HAL_ETH_WakeUpCallback(heth);
01637 #endif
01638     }
01639   }
01640 #else
01641   /* check ETH WAKEUP exti flag */
01642   if(__HAL_ETH_WAKEUP_EXTI_GET_FLAG(ETH_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
01643   {
01644     /* Clear ETH WAKEUP Exti pending bit */
01645     __HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG(ETH_WAKEUP_EXTI_LINE);
01646 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
01647       /* Call registered WakeUp callback*/
01648       heth->WakeUpCallback(heth);
01649 #else
01650       /* ETH WAKEUP callback */
01651       HAL_ETH_WakeUpCallback(heth);
01652 #endif
01653   }
01654 #endif
01655 }
01656 
01657 /**
01658   * @brief  Tx Transfer completed callbacks.
01659   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01660   *         the configuration information for ETHERNET module
01661   * @retval None
01662   */
01663 __weak void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)
01664 {
01665   /* Prevent unused argument(s) compilation warning */
01666   UNUSED(heth);
01667   /* NOTE : This function Should not be modified, when the callback is needed,
01668   the HAL_ETH_TxCpltCallback could be implemented in the user file
01669   */
01670 }
01671 
01672 /**
01673   * @brief  Rx Transfer completed callbacks.
01674   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01675   *         the configuration information for ETHERNET module
01676   * @retval None
01677   */
01678 __weak void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
01679 {
01680   /* Prevent unused argument(s) compilation warning */
01681   UNUSED(heth);
01682   /* NOTE : This function Should not be modified, when the callback is needed,
01683   the HAL_ETH_RxCpltCallback could be implemented in the user file
01684   */
01685 }
01686 
01687 /**
01688   * @brief  Ethernet DMA transfer error callbacks
01689   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01690   *         the configuration information for ETHERNET module
01691   * @retval None
01692   */
01693 __weak void HAL_ETH_DMAErrorCallback(ETH_HandleTypeDef *heth)
01694 {
01695   /* Prevent unused argument(s) compilation warning */
01696   UNUSED(heth);
01697   /* NOTE : This function Should not be modified, when the callback is needed,
01698   the HAL_ETH_DMAErrorCallback could be implemented in the user file
01699   */
01700 }
01701 
01702 /**
01703 * @brief  Ethernet MAC transfer error callbacks
01704   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01705   *         the configuration information for ETHERNET module
01706   * @retval None
01707   */
01708 __weak void HAL_ETH_MACErrorCallback(ETH_HandleTypeDef *heth)
01709 {
01710   /* Prevent unused argument(s) compilation warning */
01711   UNUSED(heth);
01712   /* NOTE : This function Should not be modified, when the callback is needed,
01713   the HAL_ETH_MACErrorCallback could be implemented in the user file
01714   */
01715 }
01716 
01717 /**
01718   * @brief  Ethernet Power Management module IT callback
01719   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01720   *         the configuration information for ETHERNET module
01721   * @retval None
01722   */
01723 __weak void HAL_ETH_PMTCallback(ETH_HandleTypeDef *heth)
01724 {
01725   /* Prevent unused argument(s) compilation warning */
01726   UNUSED(heth);
01727   /* NOTE : This function Should not be modified, when the callback is needed,
01728   the HAL_ETH_PMTCallback could be implemented in the user file
01729   */
01730 }
01731 
01732 /**
01733   * @brief  Energy Efficient Etherent IT callback
01734   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01735   *         the configuration information for ETHERNET module
01736   * @retval None
01737   */
01738 __weak void HAL_ETH_EEECallback(ETH_HandleTypeDef *heth)
01739 {
01740   /* Prevent unused argument(s) compilation warning */
01741   UNUSED(heth);
01742   /* NOTE : This function Should not be modified, when the callback is needed,
01743   the HAL_ETH_EEECallback could be implemented in the user file
01744   */
01745 }
01746 
01747 /**
01748   * @brief  ETH WAKEUP interrupt callback
01749   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01750   *         the configuration information for ETHERNET module
01751   * @retval None
01752   */
01753 __weak void HAL_ETH_WakeUpCallback(ETH_HandleTypeDef *heth)
01754 {
01755   /* Prevent unused argument(s) compilation warning */
01756   UNUSED(heth);
01757   /* NOTE : This function Should not be modified, when the callback is needed,
01758             the HAL_ETH_WakeUpCallback could be implemented in the user file
01759    */
01760 }
01761 
01762 /**
01763   * @brief  Read a PHY register
01764   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01765   *         the configuration information for ETHERNET module
01766   * @param  PHYAddr: PHY port address, must be a value from 0 to 31
01767   * @param  PHYReg: PHY register address, must be a value from 0 to 31
01768   * @param pRegValue: parameter to hold read value
01769   * @retval HAL status
01770   */
01771 HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint32_t PHYAddr, uint32_t PHYReg, uint32_t *pRegValue)
01772 {
01773   uint32_t tmpreg, tickstart;
01774 
01775   /* Check for the Busy flag */
01776   if(READ_BIT(heth->Instance->MACMDIOAR, ETH_MACMDIOAR_MB) != 0U)
01777   {
01778     return HAL_ERROR;
01779   }
01780 
01781   /* Get the  MACMDIOAR value */
01782   WRITE_REG(tmpreg, heth->Instance->MACMDIOAR);
01783 
01784   /* Prepare the MDIO Address Register value
01785      - Set the PHY device address
01786      - Set the PHY register address
01787      - Set the read mode
01788      - Set the MII Busy bit */
01789 
01790   MODIFY_REG(tmpreg, ETH_MACMDIOAR_PA, (PHYAddr <<21));
01791   MODIFY_REG(tmpreg, ETH_MACMDIOAR_RDA, (PHYReg << 16));
01792   MODIFY_REG(tmpreg, ETH_MACMDIOAR_MOC, ETH_MACMDIOAR_MOC_RD);
01793   SET_BIT(tmpreg, ETH_MACMDIOAR_MB);
01794 
01795   /* Write the result value into the MDII Address register */
01796   WRITE_REG(heth->Instance->MACMDIOAR, tmpreg);
01797 
01798   tickstart = HAL_GetTick();
01799 
01800   /* Wait for the Busy flag */
01801   while(READ_BIT(heth->Instance->MACMDIOAR, ETH_MACMDIOAR_MB) > 0U)
01802   {
01803     if(((HAL_GetTick() - tickstart ) > ETH_MDIO_BUS_TIMEOUT))
01804     {
01805       return HAL_ERROR;
01806     }
01807   }
01808 
01809   /* Get MACMIIDR value */
01810   WRITE_REG(*pRegValue, (uint16_t)heth->Instance->MACMDIODR);
01811 
01812   return HAL_OK;
01813 }
01814 
01815 
01816 /**
01817   * @brief  Writes to a PHY register.
01818   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01819   *         the configuration information for ETHERNET module
01820   * @param  PHYAddr: PHY port address, must be a value from 0 to 31
01821   * @param  PHYReg: PHY register address, must be a value from 0 to 31
01822   * @param  RegValue: the value to write
01823   * @retval HAL status
01824   */
01825 HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint32_t PHYAddr, uint32_t PHYReg, uint32_t RegValue)
01826 {
01827   uint32_t tmpreg, tickstart;
01828 
01829   /* Check for the Busy flag */
01830   if(READ_BIT(heth->Instance->MACMDIOAR, ETH_MACMDIOAR_MB) != 0U)
01831   {
01832     return HAL_ERROR;
01833   }
01834 
01835   /* Get the  MACMDIOAR value */
01836   WRITE_REG(tmpreg, heth->Instance->MACMDIOAR);
01837 
01838   /* Prepare the MDIO Address Register value
01839      - Set the PHY device address
01840      - Set the PHY register address
01841      - Set the write mode
01842      - Set the MII Busy bit */
01843 
01844   MODIFY_REG(tmpreg, ETH_MACMDIOAR_PA, (PHYAddr <<21));
01845   MODIFY_REG(tmpreg, ETH_MACMDIOAR_RDA, (PHYReg << 16));
01846   MODIFY_REG(tmpreg, ETH_MACMDIOAR_MOC, ETH_MACMDIOAR_MOC_WR);
01847   SET_BIT(tmpreg, ETH_MACMDIOAR_MB);
01848 
01849 
01850   /* Give the value to the MII data register */
01851   WRITE_REG(ETH->MACMDIODR, (uint16_t)RegValue);
01852 
01853   /* Write the result value into the MII Address register */
01854   WRITE_REG(ETH->MACMDIOAR, tmpreg);
01855 
01856   tickstart = HAL_GetTick();
01857 
01858   /* Wait for the Busy flag */
01859   while(READ_BIT(heth->Instance->MACMDIOAR, ETH_MACMDIOAR_MB) > 0U)
01860   {
01861     if(((HAL_GetTick() - tickstart ) > ETH_MDIO_BUS_TIMEOUT))
01862     {
01863       return HAL_ERROR;
01864     }
01865   }
01866 
01867   return HAL_OK;
01868 }
01869 
01870 /**
01871   * @}
01872   */
01873 
01874 /** @defgroup ETH_Exported_Functions_Group3 Peripheral Control functions
01875   *  @brief   ETH control functions
01876   *
01877 @verbatim
01878   ==============================================================================
01879                       ##### Peripheral Control functions #####
01880   ==============================================================================
01881   [..]
01882     This subsection provides a set of functions allowing to control the ETH
01883     peripheral.
01884 
01885 @endverbatim
01886   * @{
01887   */
01888 /**
01889   * @brief  Get the configuration of the MAC and MTL subsystems.
01890   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01891   *         the configuration information for ETHERNET module
01892   * @param  macconf: pointer to a ETH_MACConfigTypeDef structure that will hold
01893   *         the configuration of the MAC.
01894   * @retval HAL Status
01895   */
01896 HAL_StatusTypeDef HAL_ETH_GetMACConfig(ETH_HandleTypeDef *heth, ETH_MACConfigTypeDef *macconf)
01897 {
01898   if (macconf == NULL)
01899   {
01900     return HAL_ERROR;
01901   }
01902 
01903   /* Get MAC parameters */
01904   macconf->PreambleLength = READ_BIT(heth->Instance->MACCR, ETH_MACCR_PRELEN);
01905   macconf->DeferralCheck = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_DC)>> 4) > 0U) ? ENABLE : DISABLE;
01906   macconf->BackOffLimit = READ_BIT(heth->Instance->MACCR, ETH_MACCR_BL);
01907   macconf->RetryTransmission = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_DR) >> 8) == 0U) ? ENABLE : DISABLE;
01908   macconf->CarrierSenseDuringTransmit = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_DCRS) >> 9) > 0U) ? ENABLE : DISABLE;
01909   macconf->ReceiveOwn = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_DO) >> 10) == 0U) ? ENABLE : DISABLE;
01910   macconf->CarrierSenseBeforeTransmit = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_ECRSFD) >> 11) > 0U) ? ENABLE : DISABLE;
01911   macconf->LoopbackMode = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_LM) >> 12) > 0U) ? ENABLE : DISABLE;
01912   macconf->DuplexMode = READ_BIT(heth->Instance->MACCR, ETH_MACCR_DM);
01913   macconf->Speed = READ_BIT(heth->Instance->MACCR, ETH_MACCR_FES);
01914   macconf->JumboPacket = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_JE) >> 16) > 0U) ? ENABLE : DISABLE;
01915   macconf->Jabber = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_JD) >>17) == 0U) ? ENABLE : DISABLE;
01916   macconf->Watchdog = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_WD) >>19) == 0U) ? ENABLE : DISABLE;
01917   macconf->AutomaticPadCRCStrip = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_ACS) >> 20) > 0U) ? ENABLE : DISABLE;
01918   macconf->CRCStripTypePacket = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_CST) >> 21) > 0U) ? ENABLE : DISABLE;
01919   macconf->Support2KPacket = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_S2KP) >> 22) > 0U) ? ENABLE : DISABLE;
01920   macconf->GiantPacketSizeLimitControl = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_GPSLCE) >> 23) > 0U) ? ENABLE : DISABLE;
01921   macconf->InterPacketGapVal = READ_BIT(heth->Instance->MACCR, ETH_MACCR_IPG);
01922   macconf->ChecksumOffload = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_IPC) >> 27) > 0U) ? ENABLE : DISABLE;
01923   macconf->SourceAddrControl = READ_BIT(heth->Instance->MACCR, ETH_MACCR_SARC);
01924 
01925   macconf->GiantPacketSizeLimit = READ_BIT(heth->Instance->MACECR, ETH_MACECR_GPSL);
01926   macconf->CRCCheckingRxPackets = ((READ_BIT(heth->Instance->MACECR, ETH_MACECR_DCRCC) >> 16) == 0U) ? ENABLE : DISABLE;
01927   macconf->SlowProtocolDetect = ((READ_BIT(heth->Instance->MACECR, ETH_MACECR_SPEN) >> 17) > 0U) ? ENABLE : DISABLE;
01928   macconf->UnicastSlowProtocolPacketDetect = ((READ_BIT(heth->Instance->MACECR, ETH_MACECR_USP) >> 18) > 0U) ? ENABLE : DISABLE;
01929   macconf->ExtendedInterPacketGap = ((READ_BIT(heth->Instance->MACECR, ETH_MACECR_EIPGEN) >> 24) > 0U) ? ENABLE : DISABLE;
01930   macconf->ExtendedInterPacketGapVal = READ_BIT(heth->Instance->MACECR, ETH_MACECR_EIPG) >> 25;
01931 
01932 
01933   macconf->ProgrammableWatchdog = ((READ_BIT(heth->Instance->MACWTR, ETH_MACWTR_PWE) >> 8) > 0U) ? ENABLE : DISABLE;
01934   macconf->WatchdogTimeout = READ_BIT(heth->Instance->MACWTR, ETH_MACWTR_WTO);
01935 
01936   macconf->TransmitFlowControl = ((READ_BIT(heth->Instance->MACTFCR, ETH_MACTFCR_TFE) >> 1) > 0U) ? ENABLE : DISABLE;
01937   macconf->ZeroQuantaPause = ((READ_BIT(heth->Instance->MACTFCR, ETH_MACTFCR_DZPQ) >> 7) == 0U) ? ENABLE : DISABLE;
01938   macconf->PauseLowThreshold = READ_BIT(heth->Instance->MACTFCR, ETH_MACTFCR_PLT);
01939   macconf->PauseTime = (READ_BIT(heth->Instance->MACTFCR, ETH_MACTFCR_PT) >> 16);
01940 
01941 
01942   macconf->ReceiveFlowControl = (READ_BIT(heth->Instance->MACRFCR, ETH_MACRFCR_RFE) > 0U) ? ENABLE : DISABLE;
01943   macconf->UnicastPausePacketDetect = ((READ_BIT(heth->Instance->MACRFCR, ETH_MACRFCR_UP) >> 1) > 0U) ? ENABLE : DISABLE;
01944 
01945   macconf->TransmitQueueMode = READ_BIT(heth->Instance->MTLTQOMR, (ETH_MTLTQOMR_TTC | ETH_MTLTQOMR_TSF));
01946 
01947   macconf->ReceiveQueueMode = READ_BIT(heth->Instance->MTLRQOMR, (ETH_MTLRQOMR_RTC | ETH_MTLRQOMR_RSF));
01948   macconf->ForwardRxUndersizedGoodPacket = ((READ_BIT(heth->Instance->MTLRQOMR, ETH_MTLRQOMR_FUP) >> 3) > 0U) ? ENABLE : DISABLE;
01949   macconf->ForwardRxErrorPacket = ((READ_BIT(heth->Instance->MTLRQOMR, ETH_MTLRQOMR_FEP) >> 4) > 0U) ? ENABLE : DISABLE;
01950   macconf->DropTCPIPChecksumErrorPacket = ((READ_BIT(heth->Instance->MTLRQOMR, ETH_MTLRQOMR_DISTCPEF) >> 6) == 0U) ? ENABLE : DISABLE;
01951 
01952   return HAL_OK;
01953 }
01954 
01955 /**
01956   * @brief  Get the configuration of the DMA.
01957   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01958   *         the configuration information for ETHERNET module
01959   * @param  dmaconf: pointer to a ETH_DMAConfigTypeDef structure that will hold
01960   *         the configuration of the ETH DMA.
01961   * @retval HAL Status
01962   */
01963 HAL_StatusTypeDef HAL_ETH_GetDMAConfig(ETH_HandleTypeDef *heth, ETH_DMAConfigTypeDef *dmaconf)
01964 {
01965   if (dmaconf == NULL)
01966   {
01967     return HAL_ERROR;
01968   }
01969 
01970   dmaconf->AddressAlignedBeats = ((READ_BIT(heth->Instance->DMASBMR, ETH_DMASBMR_AAL) >> 12) > 0U) ? ENABLE : DISABLE;
01971   dmaconf->BurstMode = READ_BIT(heth->Instance->DMASBMR, ETH_DMASBMR_FB | ETH_DMASBMR_MB);
01972   dmaconf->RebuildINCRxBurst = ((READ_BIT(heth->Instance->DMASBMR, ETH_DMASBMR_RB)>> 15) > 0U) ? ENABLE : DISABLE;
01973 
01974   dmaconf->DMAArbitration = READ_BIT(heth->Instance->DMAMR, (ETH_DMAMR_TXPR |ETH_DMAMR_PR | ETH_DMAMR_DA));
01975 
01976   dmaconf->PBLx8Mode =  ((READ_BIT(heth->Instance->DMACCR, ETH_DMACCR_8PBL)>> 16) > 0U) ? ENABLE : DISABLE;
01977   dmaconf->MaximumSegmentSize = READ_BIT(heth->Instance->DMACCR, ETH_DMACCR_MSS);
01978 
01979   dmaconf->FlushRxPacket = ((READ_BIT(heth->Instance->DMACRCR,  ETH_DMACRCR_RPF) >> 31) > 0U) ? ENABLE : DISABLE;
01980   dmaconf->RxDMABurstLength = READ_BIT(heth->Instance->DMACRCR, ETH_DMACRCR_RPBL);
01981 
01982   dmaconf->SecondPacketOperate = ((READ_BIT(heth->Instance->DMACTCR, ETH_DMACTCR_OSP) >> 4) > 0U) ? ENABLE : DISABLE;
01983   dmaconf->TCPSegmentation = ((READ_BIT(heth->Instance->DMACTCR, ETH_DMACTCR_TSE) >> 12) > 0U) ? ENABLE : DISABLE;
01984   dmaconf->TxDMABurstLength = READ_BIT(heth->Instance->DMACTCR, ETH_DMACTCR_TPBL);
01985 
01986   return HAL_OK;
01987 }
01988 
01989 /**
01990   * @brief  Set the MAC configuration.
01991   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
01992   *         the configuration information for ETHERNET module
01993   * @param  macconf: pointer to a ETH_MACConfigTypeDef structure that contains
01994   *         the configuration of the MAC.
01995   * @retval HAL status
01996   */
01997 HAL_StatusTypeDef HAL_ETH_SetMACConfig(ETH_HandleTypeDef *heth,  ETH_MACConfigTypeDef *macconf)
01998 {
01999   if(macconf == NULL)
02000   {
02001     return HAL_ERROR;
02002   }
02003 
02004   if(heth->RxState == HAL_ETH_STATE_READY)
02005   {
02006     ETH_SetMACConfig(heth, macconf);
02007 
02008     return HAL_OK;
02009   }
02010   else
02011   {
02012     return HAL_ERROR;
02013   }
02014 }
02015 
02016 /**
02017   * @brief  Set the ETH DMA configuration.
02018   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02019   *         the configuration information for ETHERNET module
02020   * @param  dmaconf: pointer to a ETH_DMAConfigTypeDef structure that will hold
02021   *         the configuration of the ETH DMA.
02022   * @retval HAL status
02023   */
02024 HAL_StatusTypeDef HAL_ETH_SetDMAConfig(ETH_HandleTypeDef *heth,  ETH_DMAConfigTypeDef *dmaconf)
02025 {
02026   if(dmaconf == NULL)
02027   {
02028     return HAL_ERROR;
02029   }
02030 
02031   if(heth->RxState == HAL_ETH_STATE_READY)
02032   {
02033     ETH_SetDMAConfig(heth, dmaconf);
02034 
02035     return HAL_OK;
02036   }
02037   else
02038   {
02039     return HAL_ERROR;
02040   }
02041 }
02042 
02043 /**
02044   * @brief  Configures the Clock range of ETH MDIO interface.
02045   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02046   *         the configuration information for ETHERNET module
02047   * @retval None
02048   */
02049 void HAL_ETH_SetMDIOClockRange(ETH_HandleTypeDef *heth)
02050 {
02051   uint32_t tmpreg, hclk;
02052 
02053   /* Get the ETHERNET MACMDIOAR value */
02054   tmpreg = (heth->Instance)->MACMDIOAR;
02055 
02056         /* Clear CSR Clock Range bits */
02057   tmpreg &= ~ETH_MACMDIOAR_CR;
02058 
02059         /* Get hclk frequency value */
02060   hclk = HAL_RCC_GetHCLKFreq();
02061 
02062         /* Set CR bits depending on hclk value */
02063   if((hclk >= 20000000U)&&(hclk < 35000000U))
02064   {
02065     /* CSR Clock Range between 20-35 MHz */
02066     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV16;
02067   }
02068   else if((hclk >= 35000000U)&&(hclk < 60000000U))
02069   {
02070     /* CSR Clock Range between 35-60 MHz */
02071     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV26;
02072   }
02073   else if((hclk >= 60000000U)&&(hclk < 100000000U))
02074   {
02075     /* CSR Clock Range between 60-100 MHz */
02076     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV42;
02077   }
02078   else if((hclk >= 100000000U)&&(hclk < 150000000U))
02079   {
02080     /* CSR Clock Range between 100-150 MHz */
02081     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV62;
02082   }
02083   else /* (hclk >= 150000000)&&(hclk <= 200000000) */
02084   {
02085     /* CSR Clock Range between 150-200 MHz */
02086     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV102;
02087   }
02088 
02089   /* Configure the CSR Clock Range */
02090   (heth->Instance)->MACMDIOAR = (uint32_t)tmpreg;
02091 }
02092 
02093 /**
02094   * @brief  Set the ETH MAC (L2) Filters configuration.
02095   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02096   *         the configuration information for ETHERNET module
02097   * @param  pFilterConfig: pointer to a ETH_MACFilterConfigTypeDef structure that contains
02098   *         the configuration of the ETH MAC filters.
02099   * @retval HAL status
02100   */
02101 HAL_StatusTypeDef HAL_ETH_SetMACFilterConfig(ETH_HandleTypeDef *heth, ETH_MACFilterConfigTypeDef *pFilterConfig)
02102 {
02103   uint32_t filterconfig;
02104 
02105   if(pFilterConfig == NULL)
02106   {
02107     return HAL_ERROR;
02108   }
02109 
02110   filterconfig = ((uint32_t)pFilterConfig->PromiscuousMode |
02111                   ((uint32_t)pFilterConfig->HashUnicast << 1) |
02112                     ((uint32_t)pFilterConfig->HashMulticast << 2)  |
02113                       ((uint32_t)pFilterConfig->DestAddrInverseFiltering << 3) |
02114                         ((uint32_t)pFilterConfig->PassAllMulticast << 4) |
02115                           ((uint32_t)((pFilterConfig->BroadcastFilter == DISABLE) ? 1U : 0U) << 5) |
02116                             ((uint32_t)pFilterConfig->SrcAddrInverseFiltering << 8) |
02117                               ((uint32_t)pFilterConfig->SrcAddrFiltering << 9) |
02118                                 ((uint32_t)pFilterConfig->HachOrPerfectFilter << 10) |
02119                                   ((uint32_t)pFilterConfig->ReceiveAllMode << 31) |
02120                                     pFilterConfig->ControlPacketsFilter);
02121 
02122   MODIFY_REG(heth->Instance->MACPFR, ETH_MACPFR_MASK, filterconfig);
02123 
02124   return HAL_OK;
02125 }
02126 
02127 /**
02128   * @brief  Get the ETH MAC (L2) Filters configuration.
02129   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02130   *         the configuration information for ETHERNET module
02131   * @param  pFilterConfig: pointer to a ETH_MACFilterConfigTypeDef structure that will hold
02132   *         the configuration of the ETH MAC filters.
02133   * @retval HAL status
02134   */
02135 HAL_StatusTypeDef HAL_ETH_GetMACFilterConfig(ETH_HandleTypeDef *heth, ETH_MACFilterConfigTypeDef *pFilterConfig)
02136 {
02137   if(pFilterConfig == NULL)
02138   {
02139     return HAL_ERROR;
02140   }
02141 
02142   pFilterConfig->PromiscuousMode = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_PR)) > 0U) ? ENABLE : DISABLE;
02143   pFilterConfig->HashUnicast = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_HUC) >> 1) > 0U) ? ENABLE : DISABLE;
02144   pFilterConfig->HashMulticast = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_HMC) >> 2) > 0U) ? ENABLE : DISABLE;
02145   pFilterConfig->DestAddrInverseFiltering = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_DAIF) >> 3) > 0U) ? ENABLE : DISABLE;
02146   pFilterConfig->PassAllMulticast = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_PM) >> 4) > 0U) ? ENABLE : DISABLE;
02147   pFilterConfig->BroadcastFilter = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_DBF) >> 5) == 0U) ? ENABLE : DISABLE;
02148   pFilterConfig->ControlPacketsFilter = READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_PCF);
02149   pFilterConfig->SrcAddrInverseFiltering = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_SAIF) >> 8) > 0U) ? ENABLE : DISABLE;
02150   pFilterConfig->SrcAddrFiltering = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_SAF) >> 9) > 0U) ? ENABLE : DISABLE;
02151   pFilterConfig->HachOrPerfectFilter = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_HPF) >> 10) > 0U) ? ENABLE : DISABLE;
02152   pFilterConfig->ReceiveAllMode = ((READ_BIT(heth->Instance->MACPFR, ETH_MACPFR_RA) >> 31) > 0U) ? ENABLE : DISABLE;
02153 
02154   return HAL_OK;
02155 }
02156 
02157 /**
02158   * @brief  Set the source MAC Address to be matched.
02159   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02160   *         the configuration information for ETHERNET module
02161   * @param  AddrNbr: The MAC address to configure
02162   *          This parameter must be a value of the following:
02163   *            ETH_MAC_ADDRESS1
02164   *            ETH_MAC_ADDRESS2
02165   *            ETH_MAC_ADDRESS3
02166   * @param  pMACAddr: Pointer to MAC address buffer data (6 bytes)
02167   * @retval HAL status
02168   */
02169 HAL_StatusTypeDef HAL_ETH_SetSourceMACAddrMatch(ETH_HandleTypeDef *heth, uint32_t AddrNbr, uint8_t *pMACAddr)
02170 {
02171   uint32_t macaddrhr, macaddrlr;
02172 
02173   if(pMACAddr == NULL)
02174   {
02175     return HAL_ERROR;
02176   }
02177 
02178   /* Get mac addr high reg offset */
02179   macaddrhr = ((uint32_t)&(heth->Instance->MACA0HR) + AddrNbr);
02180   /* Get mac addr low reg offset */
02181   macaddrlr = ((uint32_t)&(heth->Instance->MACA0LR) + AddrNbr);
02182 
02183   /* Set MAC addr bits 32 to 47 */
02184   (*(__IO uint32_t *)macaddrhr) = (((uint32_t)(pMACAddr[5]) << 8) | (uint32_t)pMACAddr[4]);
02185   /* Set MAC addr bits 0 to 31 */
02186   (*(__IO uint32_t *)macaddrlr) = (((uint32_t)(pMACAddr[3]) << 24) | ((uint32_t)(pMACAddr[2]) << 16) |
02187                                    ((uint32_t)(pMACAddr[1]) << 8) | (uint32_t)pMACAddr[0]);
02188 
02189    /* Enable address and set source address bit */
02190   (*(__IO uint32_t *)macaddrhr) |= (ETH_MACAHR_SA | ETH_MACAHR_AE);
02191 
02192   return HAL_OK;
02193 }
02194 
02195 /**
02196   * @brief  Set the ETH Hash Table Value.
02197   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02198   *         the configuration information for ETHERNET module
02199   * @param  pHashTable: pointer to a table of two 32 bit values, that contains
02200   *         the 64 bits of the hash table.
02201   * @retval HAL status
02202   */
02203 HAL_StatusTypeDef HAL_ETH_SetHashTable(ETH_HandleTypeDef *heth, uint32_t *pHashTable)
02204 {
02205   if(pHashTable == NULL)
02206   {
02207     return HAL_ERROR;
02208   }
02209 
02210   heth->Instance->MACHT0R = pHashTable[0];
02211   heth->Instance->MACHT1R = pHashTable[1];
02212 
02213   return HAL_OK;
02214 }
02215 
02216 /**
02217   * @brief  Set the VLAN Identifier for Rx packets
02218   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02219   *         the configuration information for ETHERNET module
02220   * @param  ComparisonBits: 12 or 16 bit comparison mode
02221             must be a value of @ref ETH_VLAN_Tag_Comparison
02222   * @param  VLANIdentifier: VLAN Identifier value
02223   * @retval None
02224   */
02225 void HAL_ETH_SetRxVLANIdentifier(ETH_HandleTypeDef *heth, uint32_t ComparisonBits, uint32_t VLANIdentifier)
02226 {
02227   if(ComparisonBits == ETH_VLANTAGCOMPARISON_16BIT)
02228   {
02229     MODIFY_REG(heth->Instance->MACVTR, ETH_MACVTR_VL , VLANIdentifier);
02230     CLEAR_BIT(heth->Instance->MACVTR, ETH_MACVTR_ETV);
02231   }
02232   else
02233   {
02234     MODIFY_REG(heth->Instance->MACVTR, ETH_MACVTR_VL_VID , VLANIdentifier);
02235     SET_BIT(heth->Instance->MACVTR, ETH_MACVTR_ETV);
02236   }
02237 }
02238 
02239 /**
02240   * @brief  Enters the Power down mode.
02241   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02242   *         the configuration information for ETHERNET module
02243   * @param  pPowerDownConfig: a pointer to ETH_PowerDownConfigTypeDef structure
02244   *         that contains the Power Down configuration
02245   * @retval None.
02246   */
02247 void HAL_ETH_EnterPowerDownMode(ETH_HandleTypeDef *heth, ETH_PowerDownConfigTypeDef *pPowerDownConfig)
02248 {
02249   uint32_t powerdownconfig;
02250 
02251   powerdownconfig = (((uint32_t)pPowerDownConfig->MagicPacket << 1) |
02252                      ((uint32_t)pPowerDownConfig->WakeUpPacket << 2) |
02253                        ((uint32_t)pPowerDownConfig->GlobalUnicast << 9) |
02254                          ((uint32_t)pPowerDownConfig->WakeUpForward << 10) |
02255                            ETH_MACPCSR_PWRDWN);
02256 
02257   /* Enable PMT interrupt */
02258   __HAL_ETH_MAC_ENABLE_IT(heth, ETH_MACIER_PMTIE);
02259 
02260   MODIFY_REG(heth->Instance->MACPCSR, ETH_MACPCSR_MASK, powerdownconfig);
02261 }
02262 
02263 /**
02264   * @brief  Exits from the Power down mode.
02265   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02266   *         the configuration information for ETHERNET module
02267   * @retval None.
02268   */
02269 void HAL_ETH_ExitPowerDownMode(ETH_HandleTypeDef *heth)
02270 {
02271   /* clear wake up sources */
02272   CLEAR_BIT(heth->Instance->MACPCSR, ETH_MACPCSR_RWKPKTEN | ETH_MACPCSR_MGKPKTEN | ETH_MACPCSR_GLBLUCAST | ETH_MACPCSR_RWKPFE);
02273 
02274   if(READ_BIT(heth->Instance->MACPCSR, ETH_MACPCSR_PWRDWN) != 0U)
02275   {
02276     /* Exit power down mode */
02277     CLEAR_BIT(heth->Instance->MACPCSR, ETH_MACPCSR_PWRDWN);
02278   }
02279 
02280   /* Disable PMT interrupt */
02281   __HAL_ETH_MAC_DISABLE_IT(heth, ETH_MACIER_PMTIE);
02282 }
02283 
02284 /**
02285   * @brief  Set the WakeUp filter.
02286   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02287   *         the configuration information for ETHERNET module
02288   * @param  pFilter: pointer to filter registers values
02289   * @param  Count: number of filter registers, must be from 1 to 8.
02290   * @retval None.
02291   */
02292 HAL_StatusTypeDef HAL_ETH_SetWakeUpFilter(ETH_HandleTypeDef *heth, uint32_t *pFilter, uint32_t Count)
02293 {
02294   uint32_t regindex;
02295 
02296   if(pFilter == NULL)
02297   {
02298     return HAL_ERROR;
02299   }
02300 
02301   /* Reset Filter Pointer */
02302   SET_BIT(heth->Instance->MACPCSR, ETH_MACPCSR_RWKFILTRST);
02303 
02304   /* Wake up packet filter config */
02305   for(regindex = 0; regindex < Count; regindex++)
02306   {
02307     /* Write filter regs */
02308     WRITE_REG(heth->Instance->MACRWKPFR, pFilter[regindex]);
02309   }
02310 
02311   return HAL_OK;
02312 }
02313 
02314 /**
02315   * @}
02316   */
02317 
02318 /** @defgroup ETH_Exported_Functions_Group4 Peripheral State and Errors functions
02319   *  @brief   ETH State and Errors functions
02320   *
02321 @verbatim
02322   ==============================================================================
02323                  ##### Peripheral State and Errors functions #####
02324   ==============================================================================
02325  [..]
02326    This subsection provides a set of functions allowing to return the State of
02327    ETH communication process, return Peripheral Errors occurred during communication
02328    process
02329 
02330 
02331 @endverbatim
02332   * @{
02333   */
02334 
02335 /**
02336   * @brief  Returns the ETH state.
02337   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02338   *         the configuration information for ETHERNET module
02339   * @retval HAL state
02340   */
02341 HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth)
02342 {
02343   HAL_ETH_StateTypeDef ret;
02344   HAL_ETH_StateTypeDef gstate = heth->gState;
02345   HAL_ETH_StateTypeDef rxstate =heth->RxState;
02346 
02347   ret = gstate;
02348   ret |= rxstate;
02349   return ret;
02350 }
02351 
02352 /**
02353   * @brief  Returns the ETH error code
02354   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02355   *         the configuration information for ETHERNET module
02356   * @retval ETH Error Code
02357   */
02358 uint32_t HAL_ETH_GetError(ETH_HandleTypeDef *heth)
02359 {
02360   return heth->ErrorCode;
02361 }
02362 
02363 /**
02364   * @brief  Returns the ETH DMA error code
02365   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02366   *         the configuration information for ETHERNET module
02367   * @retval ETH DMA Error Code
02368   */
02369 uint32_t HAL_ETH_GetDMAError(ETH_HandleTypeDef *heth)
02370 {
02371   return heth->DMAErrorCode;
02372 }
02373 
02374 /**
02375   * @brief  Returns the ETH MAC error code
02376   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02377   *         the configuration information for ETHERNET module
02378   * @retval ETH MAC Error Code
02379   */
02380 uint32_t HAL_ETH_GetMACError(ETH_HandleTypeDef *heth)
02381 {
02382   return heth->MACErrorCode;
02383 }
02384 
02385 /**
02386   * @brief  Returns the ETH MAC WakeUp event source
02387   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02388   *         the configuration information for ETHERNET module
02389   * @retval ETH MAC WakeUp event source
02390   */
02391 uint32_t HAL_ETH_GetMACWakeUpSource(ETH_HandleTypeDef *heth)
02392 {
02393   return heth->MACWakeUpEvent;
02394 }
02395 
02396 /**
02397   * @}
02398   */
02399 
02400 /**
02401   * @}
02402   */
02403 
02404 /** @addtogroup ETH_Private_Functions   ETH Private Functions
02405   * @{
02406   */
02407 
02408 static void ETH_SetMACConfig(ETH_HandleTypeDef *heth,  ETH_MACConfigTypeDef *macconf)
02409 {
02410   uint32_t macregval;
02411 
02412   /*------------------------ MACCR Configuration --------------------*/
02413   macregval =(macconf->InterPacketGapVal |
02414               macconf->SourceAddrControl |
02415                 ((uint32_t)macconf->ChecksumOffload<< 27) |
02416                   ((uint32_t)macconf->GiantPacketSizeLimitControl << 23) |
02417                     ((uint32_t)macconf->Support2KPacket  << 22) |
02418                       ((uint32_t)macconf->CRCStripTypePacket << 21) |
02419                         ((uint32_t)macconf->AutomaticPadCRCStrip << 20) |
02420                           ((uint32_t)((macconf->Watchdog == DISABLE) ? 1U : 0U) << 19) |
02421                             ((uint32_t)((macconf->Jabber == DISABLE) ? 1U : 0U) << 17) |
02422                               ((uint32_t)macconf->JumboPacket << 16) |
02423                                 macconf->Speed |
02424                                   macconf->DuplexMode |
02425                                     ((uint32_t)macconf->LoopbackMode << 12) |
02426                                       ((uint32_t)macconf->CarrierSenseBeforeTransmit << 11)|
02427                                         ((uint32_t)((macconf->ReceiveOwn == DISABLE) ? 1U : 0U) << 10)|
02428                                           ((uint32_t)macconf->CarrierSenseDuringTransmit << 9)|
02429                                             ((uint32_t)((macconf->RetryTransmission == DISABLE) ? 1U : 0U) << 8)|
02430                                               macconf->BackOffLimit |
02431                                                 ((uint32_t)macconf->DeferralCheck << 4)|
02432                                                   macconf->PreambleLength);
02433 
02434   /* Write to MACCR */
02435   MODIFY_REG(heth->Instance->MACCR, ETH_MACCR_MASK, macregval);
02436 
02437   /*------------------------ MACECR Configuration --------------------*/
02438   macregval = ((macconf->ExtendedInterPacketGapVal << 25)|
02439                ((uint32_t)macconf->ExtendedInterPacketGap << 24)|
02440                  ((uint32_t)macconf->UnicastSlowProtocolPacketDetect << 18)|
02441                    ((uint32_t)macconf->SlowProtocolDetect << 17)|
02442                      ((uint32_t)((macconf->CRCCheckingRxPackets == DISABLE) ? 1U : 0U)<< 16) |
02443                        macconf->GiantPacketSizeLimit);
02444 
02445   /* Write to MACECR */
02446   MODIFY_REG(heth->Instance->MACECR, ETH_MACECR_MASK, macregval);
02447 
02448   /*------------------------ MACWTR Configuration --------------------*/
02449   macregval = (((uint32_t)macconf->ProgrammableWatchdog << 8) |
02450                macconf->WatchdogTimeout);
02451 
02452   /* Write to MACWTR */
02453   MODIFY_REG(heth->Instance->MACWTR, ETH_MACWTR_MASK, macregval);
02454 
02455   /*------------------------ MACTFCR Configuration --------------------*/
02456   macregval = (((uint32_t)macconf->TransmitFlowControl << 1) |
02457                macconf->PauseLowThreshold |
02458                  ((uint32_t)((macconf->ZeroQuantaPause == DISABLE) ? 1U : 0U)<< 7) |
02459                    (macconf->PauseTime << 16));
02460 
02461   /* Write to MACTFCR */
02462   MODIFY_REG(heth->Instance->MACTFCR, ETH_MACTFCR_MASK, macregval);
02463 
02464   /*------------------------ MACRFCR Configuration --------------------*/
02465   macregval = ((uint32_t)macconf->ReceiveFlowControl |
02466                ((uint32_t)macconf->UnicastPausePacketDetect << 1));
02467 
02468   /* Write to MACRFCR */
02469   MODIFY_REG(heth->Instance->MACRFCR, ETH_MACRFCR_MASK, macregval);
02470 
02471   /*------------------------ MTLTQOMR Configuration --------------------*/
02472   /* Write to MTLTQOMR */
02473   MODIFY_REG(heth->Instance->MTLTQOMR, ETH_MTLTQOMR_MASK, macconf->TransmitQueueMode);
02474 
02475   /*------------------------ MTLRQOMR Configuration --------------------*/
02476   macregval = (macconf->ReceiveQueueMode |
02477                ((uint32_t)((macconf->DropTCPIPChecksumErrorPacket == DISABLE) ? 1U : 0U) << 6) |
02478                  ((uint32_t)macconf->ForwardRxErrorPacket << 4) |
02479                    ((uint32_t)macconf->ForwardRxUndersizedGoodPacket << 3));
02480 
02481   /* Write to MTLRQOMR */
02482   MODIFY_REG(heth->Instance->MTLRQOMR, ETH_MTLRQOMR_MASK, macregval);
02483 }
02484 
02485 static void ETH_SetDMAConfig(ETH_HandleTypeDef *heth,  ETH_DMAConfigTypeDef *dmaconf)
02486 {
02487   uint32_t dmaregval;
02488 
02489   /*------------------------ DMAMR Configuration --------------------*/
02490   MODIFY_REG(heth->Instance->DMAMR, ETH_DMAMR_MASK, dmaconf->DMAArbitration);
02491 
02492   /*------------------------ DMASBMR Configuration --------------------*/
02493   dmaregval = (((uint32_t)dmaconf->AddressAlignedBeats << 12) |
02494                dmaconf->BurstMode |
02495                  ((uint32_t)dmaconf->RebuildINCRxBurst << 15));
02496 
02497   MODIFY_REG(heth->Instance->DMASBMR, ETH_DMASBMR_MASK, dmaregval);
02498 
02499   /*------------------------ DMACCR Configuration --------------------*/
02500   dmaregval = (((uint32_t)dmaconf->PBLx8Mode << 16) |
02501                dmaconf->MaximumSegmentSize);
02502 
02503   MODIFY_REG(heth->Instance->DMACCR, ETH_DMACCR_MASK, dmaregval);
02504 
02505   /*------------------------ DMACTCR Configuration --------------------*/
02506   dmaregval = (dmaconf->TxDMABurstLength |
02507                ((uint32_t)dmaconf->SecondPacketOperate << 4)|
02508                  ((uint32_t)dmaconf->TCPSegmentation << 12));
02509 
02510   MODIFY_REG(heth->Instance->DMACTCR, ETH_DMACTCR_MASK, dmaregval);
02511 
02512   /*------------------------ DMACRCR Configuration --------------------*/
02513   dmaregval = (((uint32_t)dmaconf->FlushRxPacket  << 31) |
02514                dmaconf->RxDMABurstLength);
02515 
02516   /* Write to DMACRCR */
02517   MODIFY_REG(heth->Instance->DMACRCR, ETH_DMACRCR_MASK, dmaregval);
02518 }
02519 
02520 /**
02521   * @brief  Configures Ethernet MAC and DMA with default parameters.
02522   *         called by HAL_ETH_Init() API.
02523   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02524   *         the configuration information for ETHERNET module
02525   * @retval HAL status
02526   */
02527 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth)
02528 {
02529   ETH_MACConfigTypeDef macDefaultConf;
02530   ETH_DMAConfigTypeDef dmaDefaultConf;
02531 
02532   /*--------------- ETHERNET MAC registers default Configuration --------------*/
02533   macDefaultConf.AutomaticPadCRCStrip = ENABLE;
02534   macDefaultConf.BackOffLimit = ETH_BACKOFFLIMIT_10;
02535   macDefaultConf.CarrierSenseBeforeTransmit = DISABLE;
02536   macDefaultConf.CarrierSenseDuringTransmit = DISABLE;
02537   macDefaultConf.ChecksumOffload = ENABLE;
02538   macDefaultConf.CRCCheckingRxPackets = ENABLE;
02539   macDefaultConf.CRCStripTypePacket = ENABLE;
02540   macDefaultConf.DeferralCheck = DISABLE;
02541   macDefaultConf.DropTCPIPChecksumErrorPacket = ENABLE;
02542   macDefaultConf.DuplexMode = ETH_FULLDUPLEX_MODE;
02543   macDefaultConf.ExtendedInterPacketGap = DISABLE;
02544   macDefaultConf.ExtendedInterPacketGapVal = 0x0;
02545   macDefaultConf.ForwardRxErrorPacket = DISABLE;
02546   macDefaultConf.ForwardRxUndersizedGoodPacket = DISABLE;
02547   macDefaultConf.GiantPacketSizeLimit = 0x618;
02548   macDefaultConf.GiantPacketSizeLimitControl = DISABLE;
02549   macDefaultConf.InterPacketGapVal = ETH_INTERPACKETGAP_96BIT;
02550   macDefaultConf.Jabber = ENABLE;
02551   macDefaultConf.JumboPacket = DISABLE;
02552   macDefaultConf.LoopbackMode = DISABLE;
02553   macDefaultConf.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS_4;
02554   macDefaultConf.PauseTime = 0x0;
02555   macDefaultConf.PreambleLength = ETH_PREAMBLELENGTH_7;
02556   macDefaultConf.ProgrammableWatchdog = DISABLE;
02557   macDefaultConf.ReceiveFlowControl = DISABLE;
02558   macDefaultConf.ReceiveOwn = ENABLE;
02559   macDefaultConf.ReceiveQueueMode = ETH_RECEIVESTOREFORWARD;
02560   macDefaultConf.RetryTransmission = ENABLE;
02561   macDefaultConf.SlowProtocolDetect = DISABLE;
02562   macDefaultConf.SourceAddrControl = ETH_SOURCEADDRESS_REPLACE_ADDR0;
02563   macDefaultConf.Speed = ETH_SPEED_100M;
02564   macDefaultConf.Support2KPacket = DISABLE;
02565   macDefaultConf.TransmitQueueMode = ETH_TRANSMITSTOREFORWARD;
02566   macDefaultConf.TransmitFlowControl = DISABLE;
02567   macDefaultConf.UnicastPausePacketDetect = DISABLE;
02568   macDefaultConf.UnicastSlowProtocolPacketDetect = DISABLE;
02569   macDefaultConf.Watchdog = ENABLE;
02570   macDefaultConf.WatchdogTimeout =  ETH_MACWTR_WTO_2KB;
02571   macDefaultConf.ZeroQuantaPause = ENABLE;
02572 
02573   /* MAC default configuration */
02574   ETH_SetMACConfig(heth, &macDefaultConf);
02575 
02576   /*--------------- ETHERNET DMA registers default Configuration --------------*/
02577   dmaDefaultConf.AddressAlignedBeats = ENABLE;
02578   dmaDefaultConf.BurstMode = ETH_BURSTLENGTH_FIXED;
02579   dmaDefaultConf.DMAArbitration = ETH_DMAARBITRATION_RX1_TX1;
02580   dmaDefaultConf.FlushRxPacket = DISABLE;
02581   dmaDefaultConf.PBLx8Mode = DISABLE;
02582   dmaDefaultConf.RebuildINCRxBurst = DISABLE;
02583   dmaDefaultConf.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;
02584   dmaDefaultConf.SecondPacketOperate = DISABLE;
02585   dmaDefaultConf.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;
02586   dmaDefaultConf.TCPSegmentation = DISABLE;
02587   dmaDefaultConf.MaximumSegmentSize = 536;
02588 
02589   /* DMA default configuration */
02590   ETH_SetDMAConfig(heth, &dmaDefaultConf);
02591 }
02592 
02593 /**
02594   * @brief  Configures the Clock range of SMI interface.
02595   *         called by HAL_ETH_Init() API.
02596   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02597   *         the configuration information for ETHERNET module
02598   * @retval None
02599   */
02600 static void ETH_MAC_MDIO_ClkConfig(ETH_HandleTypeDef *heth)
02601 {
02602   uint32_t tmpreg, hclk;
02603 
02604   /* Get the ETHERNET MACMDIOAR value */
02605   tmpreg = (heth->Instance)->MACMDIOAR;
02606 
02607   /* Clear CSR Clock Range bits */
02608   tmpreg &= ~ETH_MACMDIOAR_CR;
02609 
02610   /* Get hclk frequency value */
02611   hclk = HAL_RCC_GetHCLKFreq();
02612 
02613   /* Set CR bits depending on hclk value */
02614   if((hclk >= 20000000U)&&(hclk < 35000000U))
02615   {
02616     /* CSR Clock Range between 20-35 MHz */
02617     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV16;
02618   }
02619   else if((hclk >= 35000000U)&&(hclk < 60000000U))
02620   {
02621     /* CSR Clock Range between 35-60 MHz */
02622     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV26;
02623   }
02624   else if((hclk >= 60000000U)&&(hclk < 100000000U))
02625   {
02626     /* CSR Clock Range between 60-100 MHz */
02627     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV42;
02628   }
02629   else if((hclk >= 100000000U)&&(hclk < 150000000U))
02630   {
02631     /* CSR Clock Range between 100-150 MHz */
02632     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV62;
02633   }
02634   else /* (hclk >= 150000000)&&(hclk <= 200000000) */
02635   {
02636     /* CSR Clock Range between 150-200 MHz */
02637     tmpreg |= (uint32_t)ETH_MACMDIOAR_CR_DIV102;
02638   }
02639 
02640   /* Configure the CSR Clock Range */
02641   (heth->Instance)->MACMDIOAR = (uint32_t)tmpreg;
02642 }
02643 
02644 /**
02645   * @brief  Initializes the DMA Tx descriptors.
02646   *         called by HAL_ETH_Init() API.
02647   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02648   *         the configuration information for ETHERNET module
02649   * @retval None
02650   */
02651 static void ETH_DMATxDescListInit(ETH_HandleTypeDef *heth)
02652 {
02653   ETH_DMADescTypeDef *dmatxdesc;
02654   uint32_t i;
02655 
02656   /* Fill each DMATxDesc descriptor with the right values */
02657   for(i=0; i < (uint32_t)ETH_TX_DESC_CNT; i++)
02658   {
02659     dmatxdesc = heth->Init.TxDesc + i;
02660 
02661     WRITE_REG(dmatxdesc->DESC0, 0x0);
02662     WRITE_REG(dmatxdesc->DESC1, 0x0);
02663     WRITE_REG(dmatxdesc->DESC2, 0x0);
02664     WRITE_REG(dmatxdesc->DESC3, 0x0);
02665 
02666     WRITE_REG(heth->TxDescList.TxDesc[i], (uint32_t)dmatxdesc);
02667   }
02668 
02669   heth->TxDescList.CurTxDesc = 0;
02670 
02671   /* Set Transmit Descriptor Ring Length */
02672   WRITE_REG(heth->Instance->DMACTDRLR, (ETH_TX_DESC_CNT -1));
02673 
02674   /* Set Transmit Descriptor List Address */
02675   WRITE_REG(heth->Instance->DMACTDLAR, (uint32_t) heth->Init.TxDesc);
02676 
02677   /* Set Transmit Descriptor Tail pointer */
02678   WRITE_REG(heth->Instance->DMACTDTPR, (uint32_t) heth->Init.TxDesc);
02679 }
02680 
02681 /**
02682   * @brief  Initializes the DMA Rx descriptors in chain mode.
02683   *         called by HAL_ETH_Init() API.
02684   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02685   *         the configuration information for ETHERNET module
02686   * @retval None
02687   */
02688 static void ETH_DMARxDescListInit(ETH_HandleTypeDef *heth)
02689 {
02690   ETH_DMADescTypeDef *dmarxdesc;
02691   uint32_t i;
02692 
02693   for(i = 0; i < (uint32_t)ETH_RX_DESC_CNT; i++)
02694   {
02695     dmarxdesc =  heth->Init.RxDesc + i;
02696 
02697     WRITE_REG(dmarxdesc->DESC0, 0x0);
02698     WRITE_REG(dmarxdesc->DESC1, 0x0);
02699     WRITE_REG(dmarxdesc->DESC2, 0x0);
02700     WRITE_REG(dmarxdesc->DESC3, 0x0);
02701     WRITE_REG(dmarxdesc->BackupAddr0, 0x0);
02702     WRITE_REG(dmarxdesc->BackupAddr1, 0x0);
02703 
02704     /* Set Rx descritors addresses */
02705     WRITE_REG(heth->RxDescList.RxDesc[i], (uint32_t)dmarxdesc);
02706   }
02707 
02708   WRITE_REG(heth->RxDescList.CurRxDesc, 0);
02709   WRITE_REG(heth->RxDescList.FirstAppDesc, 0);
02710   WRITE_REG(heth->RxDescList.AppDescNbr, 0);
02711   WRITE_REG(heth->RxDescList.ItMode, 0);
02712   WRITE_REG(heth->RxDescList.AppContextDesc, 0);
02713 
02714   /* Set Receive Descriptor Ring Length */
02715   WRITE_REG(heth->Instance->DMACRDRLR, ((uint32_t)(ETH_RX_DESC_CNT - 1)));
02716 
02717   /* Set Receive Descriptor List Address */
02718   WRITE_REG(heth->Instance->DMACRDLAR, (uint32_t) heth->Init.RxDesc);
02719 
02720   /* Set Receive Descriptor Tail pointer Address */
02721   WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (uint32_t)(ETH_RX_DESC_CNT - 1))));
02722 }
02723 
02724 /**
02725   * @brief  Prepare Tx DMA descriptor before transmission.
02726   *         called by HAL_ETH_Transmit_IT and HAL_ETH_Transmit_IT() API.
02727   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains
02728   *         the configuration information for ETHERNET module
02729   * @param  pTxConfig: Tx packet configuration
02730   * @param  ItMode: Enable or disable Tx EOT interrept
02731   * @retval Status
02732   */
02733 static uint32_t ETH_Prepare_Tx_Descriptors(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig, uint32_t ItMode)
02734 {
02735   ETH_TxDescListTypeDef *dmatxdesclist = &heth->TxDescList;
02736   uint32_t descidx = dmatxdesclist->CurTxDesc;
02737   uint32_t firstdescidx = dmatxdesclist->CurTxDesc;
02738   uint32_t descnbr = 0, idx;
02739   ETH_DMADescTypeDef *dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
02740 
02741   ETH_BufferTypeDef  *txbuffer = pTxConfig->TxBuffer;
02742   uint32_t           bd_count = 0;
02743 
02744   /* Current Tx Descriptor Owned by DMA: cannot be used by the application  */
02745   if((READ_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCWBF_OWN) == ETH_DMATXNDESCWBF_OWN) || (dmatxdesclist->PacketAddress[descidx] != NULL))
02746   {
02747     return HAL_ETH_ERROR_BUSY;
02748   }
02749 
02750   /***************************************************************************/
02751   /*****************    Context descriptor configuration (Optional) **********/
02752   /***************************************************************************/
02753   /* If VLAN tag is enabled for this packet */
02754   if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_VLANTAG) != 0U)
02755   {
02756     /* Set vlan tag value */
02757     MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXCDESC_VT, pTxConfig->VlanTag);
02758     /* Set vlan tag valid bit */
02759     SET_BIT(dmatxdesc->DESC3, ETH_DMATXCDESC_VLTV);
02760     /* Set the descriptor as the vlan input source */
02761     SET_BIT(heth->Instance->MACVIR, ETH_MACVIR_VLTI);
02762 
02763     /* if inner VLAN is enabled */
02764     if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_INNERVLANTAG) != 0U)
02765     {
02766       /* Set inner vlan tag value */
02767       MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXCDESC_IVT, (pTxConfig->InnerVlanTag << 16));
02768       /* Set inner vlan tag valid bit */
02769       SET_BIT(dmatxdesc->DESC3, ETH_DMATXCDESC_IVLTV);
02770 
02771       /* Set Vlan Tag control */
02772       MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXCDESC_IVTIR, pTxConfig->InnerVlanCtrl);
02773 
02774       /* Set the descriptor as the inner vlan input source */
02775       SET_BIT(heth->Instance->MACIVIR, ETH_MACIVIR_VLTI);
02776       /* Enable double VLAN processing */
02777       SET_BIT(heth->Instance->MACVTR, ETH_MACVTR_EDVLP);
02778     }
02779   }
02780 
02781   /* if tcp segmentation is enabled for this packet */
02782   if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_TSO) != 0U)
02783   {
02784     /* Set MSS value */
02785     MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXCDESC_MSS, pTxConfig->MaxSegmentSize);
02786     /* Set MSS valid bit */
02787     SET_BIT(dmatxdesc->DESC3, ETH_DMATXCDESC_TCMSSV);
02788   }
02789 
02790   if((READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_VLANTAG) != 0U)|| (READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_TSO) != 0U))
02791   {
02792     /* Set as context descriptor */
02793     SET_BIT(dmatxdesc->DESC3, ETH_DMATXCDESC_CTXT);
02794     /* Set own bit */
02795     SET_BIT(dmatxdesc->DESC3, ETH_DMATXCDESC_OWN);
02796     /* Increment current tx descriptor index */
02797     INCR_TX_DESC_INDEX(descidx, 1U);
02798     /* Get current descriptor address */
02799     dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
02800 
02801     descnbr += 1U;
02802 
02803     /* Current Tx Descriptor Owned by DMA: cannot be used by the application  */
02804     if(READ_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCWBF_OWN) == ETH_DMATXNDESCWBF_OWN)
02805     {
02806       dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[firstdescidx];
02807       /* Clear own bit */
02808       CLEAR_BIT(dmatxdesc->DESC3, ETH_DMATXCDESC_OWN);
02809 
02810       return HAL_ETH_ERROR_BUSY;
02811     }
02812   }
02813 
02814   /***************************************************************************/
02815   /*****************    Normal descriptors configuration     *****************/
02816   /***************************************************************************/
02817 
02818   descnbr += 1U;
02819 
02820   /* Set header or buffer 1 address */
02821   WRITE_REG(dmatxdesc->DESC0, (uint32_t)txbuffer->buffer);
02822   /* Set header or buffer 1 Length */
02823   MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXNDESCRF_B1L, txbuffer->len);
02824 
02825   if(txbuffer->next != NULL)
02826   {
02827     txbuffer = txbuffer->next;
02828     /* Set buffer 2 address */
02829     WRITE_REG(dmatxdesc->DESC1, (uint32_t)txbuffer->buffer);
02830     /* Set buffer 2 Length */
02831     MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXNDESCRF_B2L, (txbuffer->len << 16));
02832   }
02833   else
02834   {
02835     WRITE_REG(dmatxdesc->DESC1, 0x0);
02836     /* Set buffer 2 Length */
02837     MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXNDESCRF_B2L, 0x0U);
02838   }
02839 
02840   if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_TSO) != 0U)
02841   {
02842     /* Set TCP Header length */
02843     MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_THL, (pTxConfig->TCPHeaderLen << 19));
02844     /* Set TCP payload length */
02845     MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_TPL, pTxConfig->PayloadLen);
02846     /* Set TCP Segmentation Enabled bit */
02847     SET_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_TSE);
02848   }
02849   else
02850   {
02851     MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_FL, pTxConfig->Length);
02852 
02853     if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_CSUM) != 0U)
02854     {
02855       MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_CIC, pTxConfig->ChecksumCtrl);
02856     }
02857 
02858     if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_CRCPAD) != 0U)
02859     {
02860       MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_CPC, pTxConfig->CRCPadCtrl);
02861     }
02862   }
02863 
02864   if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_VLANTAG) != 0U)
02865   {
02866     /* Set Vlan Tag control */
02867     MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXNDESCRF_VTIR, pTxConfig->VlanCtrl);
02868   }
02869 
02870   /* Mark it as First Descriptor */
02871   SET_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_FD);
02872   /* Mark it as NORMAL descriptor */
02873   CLEAR_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_CTXT);
02874   /* set OWN bit of FIRST descriptor */
02875   SET_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_OWN);
02876 
02877   /* If source address insertion/replacement is enabled for this packet */
02878   if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_SAIC) != 0U)
02879   {
02880     MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_SAIC, pTxConfig->SrcAddrCtrl);
02881   }
02882 
02883   /* only if the packet is split into more than one descriptors > 1 */
02884   while (txbuffer->next != NULL)
02885   {
02886     /* Clear the LD bit of previous descriptor */
02887     CLEAR_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_LD);
02888     /* Increment current tx descriptor index */
02889     INCR_TX_DESC_INDEX(descidx, 1U);
02890     /* Get current descriptor address */
02891     dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
02892 
02893     /* Clear the FD bit of new Descriptor */
02894     CLEAR_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_FD);
02895 
02896     /* Current Tx Descriptor Owned by DMA: cannot be used by the application  */
02897     if((READ_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_OWN) == ETH_DMATXNDESCRF_OWN) || (dmatxdesclist->PacketAddress[descidx] != NULL))
02898     {
02899       descidx = firstdescidx;
02900       dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
02901 
02902       /* clear previous desc own bit */
02903       for(idx = 0; idx < descnbr; idx ++)
02904       {
02905         CLEAR_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_OWN);
02906 
02907         /* Increment current tx descriptor index */
02908         INCR_TX_DESC_INDEX(descidx, 1U);
02909         /* Get current descriptor address */
02910         dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
02911       }
02912 
02913       return HAL_ETH_ERROR_BUSY;
02914     }
02915 
02916     descnbr += 1U;
02917 
02918     /* Get the next Tx buffer in the list */
02919     txbuffer = txbuffer->next;
02920 
02921     /* Set header or buffer 1 address */
02922     WRITE_REG(dmatxdesc->DESC0, (uint32_t)txbuffer->buffer);
02923     /* Set header or buffer 1 Length */
02924     MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXNDESCRF_B1L, txbuffer->len);
02925 
02926     if (txbuffer->next != NULL)
02927     {
02928       /* Get the next Tx buffer in the list */
02929       txbuffer = txbuffer->next;
02930       /* Set buffer 2 address */
02931       WRITE_REG(dmatxdesc->DESC1, (uint32_t)txbuffer->buffer);
02932       /* Set buffer 2 Length */
02933       MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXNDESCRF_B2L, (txbuffer->len << 16));
02934     }
02935     else
02936     {
02937       WRITE_REG(dmatxdesc->DESC1, 0x0);
02938       /* Set buffer 2 Length */
02939       MODIFY_REG(dmatxdesc->DESC2, ETH_DMATXNDESCRF_B2L, 0x0U);
02940     }
02941 
02942     if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_TSO) != 0U)
02943     {
02944       /* Set TCP payload length */
02945       MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_TPL, pTxConfig->PayloadLen);
02946       /* Set TCP Segmentation Enabled bit */
02947       SET_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_TSE);
02948     }
02949     else
02950     {
02951       /* Set the packet length */
02952       MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_FL, pTxConfig->Length);
02953 
02954       if(READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_CSUM) != 0U)
02955       {
02956         /* Checksum Insertion Control */
02957         MODIFY_REG(dmatxdesc->DESC3, ETH_DMATXNDESCRF_CIC, pTxConfig->ChecksumCtrl);
02958       }
02959     }
02960 
02961     bd_count += 1U;
02962     /* Set Own bit */
02963     SET_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_OWN);
02964     /* Mark it as NORMAL descriptor */
02965     CLEAR_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_CTXT);
02966   }
02967 
02968   if(ItMode != ((uint32_t)RESET))
02969   {
02970     /* Set Interrupt on completion bit */
02971     SET_BIT(dmatxdesc->DESC2, ETH_DMATXNDESCRF_IOC);
02972   }
02973   else
02974   {
02975     /* Clear Interrupt on completion bit */
02976     CLEAR_BIT(dmatxdesc->DESC2, ETH_DMATXNDESCRF_IOC);
02977   }
02978 
02979   /* Mark it as LAST descriptor */
02980   SET_BIT(dmatxdesc->DESC3, ETH_DMATXNDESCRF_LD);
02981   /* Save the current packet address to expose it to the application */
02982   dmatxdesclist->PacketAddress[descidx] = dmatxdesclist->CurrentPacketAddress;
02983 
02984   dmatxdesclist->CurTxDesc = descidx;
02985 
02986   /* disable the interrupt */
02987   __disable_irq();
02988 
02989   dmatxdesclist->BuffersInUse += bd_count + 1U;
02990 
02991   /* Enable interrupts back */
02992   __enable_irq();
02993 
02994 
02995   /* Return function status */
02996   return HAL_ETH_ERROR_NONE;
02997 }
02998 
02999 #if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
03000 static void ETH_InitCallbacksToDefault(ETH_HandleTypeDef *heth)
03001 {
03002   /* Init the ETH Callback settings */
03003   heth->TxCpltCallback   = HAL_ETH_TxCpltCallback;    /* Legacy weak TxCpltCallback   */
03004   heth->RxCpltCallback   = HAL_ETH_RxCpltCallback;    /* Legacy weak RxCpltCallback   */
03005   heth->DMAErrorCallback = HAL_ETH_DMAErrorCallback;  /* Legacy weak DMAErrorCallback */
03006   heth->MACErrorCallback = HAL_ETH_MACErrorCallback;  /* Legacy weak MACErrorCallback */
03007   heth->PMTCallback      = HAL_ETH_PMTCallback;       /* Legacy weak PMTCallback      */
03008   heth->EEECallback      = HAL_ETH_EEECallback;       /* Legacy weak EEECallback      */
03009   heth->WakeUpCallback   = HAL_ETH_WakeUpCallback;    /* Legacy weak WakeUpCallback   */
03010 }
03011 #endif /* USE_HAL_ETH_REGISTER_CALLBACKS */
03012 
03013 /**
03014   * @}
03015   */
03016 
03017 /**
03018   * @}
03019   */
03020 
03021 #endif /* ETH */
03022 
03023 #endif /* HAL_ETH_MODULE_ENABLED */
03024 
03025 /**
03026   * @}
03027   */
03028