]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL/ST_Library/stm32f7xx_hal_eth.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL / ST_Library / stm32f7xx_hal_eth.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f7xx_hal_eth.c\r
4   * @author  MCD Application Team\r
5   * @version V0.3.0\r
6   * @date    06-March-2015\r
7   * @brief   ETH HAL module driver.\r
8   *          This file provides firmware functions to manage the following \r
9   *          functionalities of the Ethernet (ETH) peripheral:\r
10   *           + Initialization and de-initialization functions\r
11   *           + IO operation functions\r
12   *           + Peripheral Control functions \r
13   *           + Peripheral State and Errors functions\r
14   *\r
15   @verbatim\r
16   ==============================================================================\r
17                     ##### How to use this driver #####\r
18   ==============================================================================\r
19     [..]\r
20       (#)Declare a ETH_HandleTypeDef handle structure, for example:\r
21          ETH_HandleTypeDef  heth;\r
22         \r
23       (#)Fill parameters of Init structure in heth handle\r
24   \r
25       (#)Call HAL_ETH_Init() API to initialize the Ethernet peripheral (MAC, DMA, ...) \r
26 \r
27       (#)Initialize the ETH low level resources through the HAL_ETH_MspInit() API:\r
28           (##) Enable the Ethernet interface clock using \r
29                (+++) __HAL_RCC_ETHMAC_CLK_ENABLE();\r
30                (+++) __HAL_RCC_ETHMACTX_CLK_ENABLE();\r
31                (+++) __HAL_RCC_ETHMACRX_CLK_ENABLE();\r
32            \r
33           (##) Initialize the related GPIO clocks\r
34           (##) Configure Ethernet pin-out\r
35           (##) Configure Ethernet NVIC interrupt (IT mode)   \r
36     \r
37       (#)Initialize Ethernet DMA Descriptors in chain mode and point to allocated buffers:\r
38           (##) HAL_ETH_DMATxDescListInit(); for Transmission process\r
39           (##) HAL_ETH_DMARxDescListInit(); for Reception process\r
40 \r
41       (#)Enable MAC and DMA transmission and reception:\r
42           (##) HAL_ETH_Start();\r
43 \r
44       (#)Prepare ETH DMA TX Descriptors and give the hand to ETH DMA to transfer \r
45          the frame to MAC TX FIFO:\r
46          (##) HAL_ETH_TransmitFrame();\r
47 \r
48       (#)Poll for a received frame in ETH RX DMA Descriptors and get received \r
49          frame parameters\r
50          (##) HAL_ETH_GetReceivedFrame(); (should be called into an infinite loop)\r
51 \r
52       (#) Get a received frame when an ETH RX interrupt occurs:\r
53          (##) HAL_ETH_GetReceivedFrame_IT(); (called in IT mode only)\r
54 \r
55       (#) Communicate with external PHY device:\r
56          (##) Read a specific register from the PHY  \r
57               HAL_ETH_ReadPHYRegister();\r
58          (##) Write data to a specific RHY register:\r
59               HAL_ETH_WritePHYRegister();\r
60 \r
61       (#) Configure the Ethernet MAC after ETH peripheral initialization\r
62           HAL_ETH_ConfigMAC(); all MAC parameters should be filled.\r
63       \r
64       (#) Configure the Ethernet DMA after ETH peripheral initialization\r
65           HAL_ETH_ConfigDMA(); all DMA parameters should be filled.\r
66 \r
67   @endverbatim\r
68   ******************************************************************************\r
69   * @attention\r
70   *\r
71   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
72   *\r
73   * Redistribution and use in source and binary forms, with or without modification,\r
74   * are permitted provided that the following conditions are met:\r
75   *   1. Redistributions of source code must retain the above copyright notice,\r
76   *      this list of conditions and the following disclaimer.\r
77   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
78   *      this list of conditions and the following disclaimer in the documentation\r
79   *      and/or other materials provided with the distribution.\r
80   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
81   *      may be used to endorse or promote products derived from this software\r
82   *      without specific prior written permission.\r
83   *\r
84   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
85   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
86   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
87   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
88   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
89   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
90   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
91   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
92   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
93   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
94   *\r
95   ******************************************************************************\r
96   */ \r
97 \r
98 /* Includes ------------------------------------------------------------------*/\r
99 #include "stm32f7xx_hal.h"\r
100 \r
101 /** @addtogroup STM32F7xx_HAL_Driver\r
102   * @{\r
103   */\r
104 \r
105 /** @defgroup ETH ETH \r
106   * @brief ETH HAL module driver\r
107   * @{\r
108   */\r
109 \r
110 #ifdef HAL_ETH_MODULE_ENABLED\r
111 \r
112 /* Private typedef -----------------------------------------------------------*/\r
113 /* Private define ------------------------------------------------------------*/\r
114 /** @defgroup ETH_Private_Constants ETH Private Constants\r
115   * @{\r
116   */\r
117 #define LINKED_STATE_TIMEOUT_VALUE          ((uint32_t)2000)  /* 2000 ms */\r
118 #define AUTONEGO_COMPLETED_TIMEOUT_VALUE    ((uint32_t)1000)  /* 1000 ms */\r
119 \r
120 /**\r
121   * @}\r
122   */\r
123 /* Private macro -------------------------------------------------------------*/\r
124 /* Private variables ---------------------------------------------------------*/\r
125 /* Private function prototypes -----------------------------------------------*/\r
126 /** @defgroup ETH_Private_Functions ETH Private Functions\r
127   * @{\r
128   */\r
129 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err);\r
130 static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr);\r
131 static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth);\r
132 static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth);\r
133 static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth);\r
134 static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth);\r
135 static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth);\r
136 static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth);\r
137 static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth);\r
138 static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth);\r
139 static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth);\r
140 \r
141 /**\r
142   * @}\r
143   */\r
144 /* Private functions ---------------------------------------------------------*/\r
145 \r
146 /** @defgroup ETH_Exported_Functions ETH Exported Functions\r
147   * @{\r
148   */\r
149 \r
150 /** @defgroup ETH_Exported_Functions_Group1 Initialization and de-initialization functions \r
151   *  @brief   Initialization and Configuration functions \r
152   *\r
153   @verbatim    \r
154   ===============================================================================\r
155             ##### Initialization and de-initialization functions #####\r
156   ===============================================================================\r
157   [..]  This section provides functions allowing to:\r
158       (+) Initialize and configure the Ethernet peripheral\r
159       (+) De-initialize the Ethernet peripheral\r
160 \r
161   @endverbatim\r
162   * @{\r
163   */\r
164 \r
165 /**\r
166   * @brief  Initializes the Ethernet MAC and DMA according to default\r
167   *         parameters.\r
168   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
169   *         the configuration information for ETHERNET module\r
170   * @retval HAL status\r
171   */\r
172 HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth)\r
173 {\r
174   uint32_t tempreg = 0, phyreg = 0;\r
175   uint32_t hclk = 60000000;\r
176   uint32_t tickstart = 0;\r
177   uint32_t err = ETH_SUCCESS;\r
178   \r
179   /* Check the ETH peripheral state */\r
180   if(heth == NULL)\r
181   {\r
182     return HAL_ERROR;\r
183   }\r
184   \r
185   /* Check parameters */\r
186   assert_param(IS_ETH_AUTONEGOTIATION(heth->Init.AutoNegotiation));\r
187   assert_param(IS_ETH_RX_MODE(heth->Init.RxMode));\r
188   assert_param(IS_ETH_CHECKSUM_MODE(heth->Init.ChecksumMode));\r
189   assert_param(IS_ETH_MEDIA_INTERFACE(heth->Init.MediaInterface));  \r
190   \r
191   if(heth->State == HAL_ETH_STATE_RESET)\r
192   {\r
193     /* Init the low level hardware : GPIO, CLOCK, NVIC. */\r
194     HAL_ETH_MspInit(heth);\r
195   }\r
196   \r
197   /* Enable SYSCFG Clock */\r
198   __HAL_RCC_SYSCFG_CLK_ENABLE();\r
199   \r
200   /* Select MII or RMII Mode*/\r
201   SYSCFG->PMC &= ~(SYSCFG_PMC_MII_RMII_SEL);\r
202   SYSCFG->PMC |= (uint32_t)heth->Init.MediaInterface;\r
203   \r
204   /* Ethernet Software reset */\r
205   /* Set the SWR bit: resets all MAC subsystem internal registers and logic */\r
206   /* After reset all the registers holds their respective reset values */\r
207   (heth->Instance)->DMABMR |= ETH_DMABMR_SR;\r
208   \r
209   /* Wait for software reset */\r
210   while (((heth->Instance)->DMABMR & ETH_DMABMR_SR) != (uint32_t)RESET)\r
211   {\r
212   }\r
213   \r
214   /*-------------------------------- MAC Initialization ----------------------*/\r
215   /* Get the ETHERNET MACMIIAR value */\r
216   tempreg = (heth->Instance)->MACMIIAR;\r
217   /* Clear CSR Clock Range CR[2:0] bits */\r
218   tempreg &= ETH_MACMIIAR_CR_MASK;\r
219   \r
220   /* Get hclk frequency value */\r
221   hclk = HAL_RCC_GetHCLKFreq();\r
222   \r
223   /* Set CR bits depending on hclk value */\r
224   if((hclk >= 20000000)&&(hclk < 35000000))\r
225   {\r
226     /* CSR Clock Range between 20-35 MHz */\r
227     tempreg |= (uint32_t)ETH_MACMIIAR_CR_Div16;\r
228   }\r
229   else if((hclk >= 35000000)&&(hclk < 60000000))\r
230   {\r
231     /* CSR Clock Range between 35-60 MHz */ \r
232     tempreg |= (uint32_t)ETH_MACMIIAR_CR_Div26;\r
233   }  \r
234   else if((hclk >= 60000000)&&(hclk < 100000000))\r
235   {\r
236     /* CSR Clock Range between 60-100 MHz */ \r
237     tempreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;\r
238   }  \r
239   else if((hclk >= 100000000)&&(hclk < 150000000))\r
240   {\r
241     /* CSR Clock Range between 100-150 MHz */ \r
242     tempreg |= (uint32_t)ETH_MACMIIAR_CR_Div62;\r
243   }\r
244   else /* ((hclk >= 150000000)&&(hclk <= 200000000)) */\r
245   {\r
246     /* CSR Clock Range between 150-200 MHz */ \r
247     tempreg |= (uint32_t)ETH_MACMIIAR_CR_Div102;    \r
248   }\r
249   \r
250   /* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */\r
251   (heth->Instance)->MACMIIAR = (uint32_t)tempreg;\r
252   \r
253   /*-------------------- PHY initialization and configuration ----------------*/\r
254   /* Put the PHY in reset mode */\r
255   if((HAL_ETH_WritePHYRegister(heth, PHY_BCR, PHY_RESET)) != HAL_OK)\r
256   {\r
257     /* In case of write timeout */\r
258     err = ETH_ERROR;\r
259     \r
260     /* Config MAC and DMA */\r
261     ETH_MACDMAConfig(heth, err);\r
262     \r
263     /* Set the ETH peripheral state to READY */\r
264     heth->State = HAL_ETH_STATE_READY;\r
265     \r
266     /* Return HAL_ERROR */\r
267     return HAL_ERROR;\r
268   }\r
269   \r
270   /* Delay to assure PHY reset */\r
271   HAL_Delay(PHY_RESET_DELAY);\r
272   \r
273   if((heth->Init).AutoNegotiation != ETH_AUTONEGOTIATION_DISABLE)\r
274   {\r
275     /* Get tick */\r
276     tickstart = HAL_GetTick();\r
277     \r
278     /* We wait for linked status */\r
279     do\r
280     {\r
281       HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg);\r
282       \r
283       /* Check for the Timeout */\r
284       if((HAL_GetTick() - tickstart ) > LINKED_STATE_TIMEOUT_VALUE)\r
285       {\r
286         /* In case of write timeout */\r
287         err = ETH_ERROR;\r
288       \r
289         /* Config MAC and DMA */\r
290         ETH_MACDMAConfig(heth, err);\r
291         \r
292         heth->State= HAL_ETH_STATE_READY;\r
293   \r
294         /* Process Unlocked */\r
295         __HAL_UNLOCK(heth);\r
296     \r
297         return HAL_TIMEOUT;\r
298       }\r
299     } while (((phyreg & PHY_LINKED_STATUS) != PHY_LINKED_STATUS));\r
300 \r
301     \r
302     /* Enable Auto-Negotiation */\r
303     if((HAL_ETH_WritePHYRegister(heth, PHY_BCR, PHY_AUTONEGOTIATION)) != HAL_OK)\r
304     {\r
305       /* In case of write timeout */\r
306       err = ETH_ERROR;\r
307       \r
308       /* Config MAC and DMA */\r
309       ETH_MACDMAConfig(heth, err);\r
310       \r
311       /* Set the ETH peripheral state to READY */\r
312       heth->State = HAL_ETH_STATE_READY;\r
313       \r
314       /* Return HAL_ERROR */\r
315       return HAL_ERROR;   \r
316     }\r
317     \r
318     /* Get tick */\r
319     tickstart = HAL_GetTick();\r
320     \r
321     /* Wait until the auto-negotiation will be completed */\r
322     do\r
323     {\r
324       HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg);\r
325       \r
326       /* Check for the Timeout */\r
327       if((HAL_GetTick() - tickstart ) > AUTONEGO_COMPLETED_TIMEOUT_VALUE)\r
328       {\r
329         /* In case of write timeout */\r
330         err = ETH_ERROR;\r
331       \r
332         /* Config MAC and DMA */\r
333         ETH_MACDMAConfig(heth, err);\r
334         \r
335         heth->State= HAL_ETH_STATE_READY;\r
336   \r
337         /* Process Unlocked */\r
338         __HAL_UNLOCK(heth);\r
339     \r
340         return HAL_TIMEOUT;\r
341       }\r
342       \r
343     } while (((phyreg & PHY_AUTONEGO_COMPLETE) != PHY_AUTONEGO_COMPLETE));\r
344     \r
345     /* Read the result of the auto-negotiation */\r
346     if((HAL_ETH_ReadPHYRegister(heth, PHY_SR, &phyreg)) != HAL_OK)\r
347     {\r
348       /* In case of write timeout */\r
349       err = ETH_ERROR;\r
350       \r
351       /* Config MAC and DMA */\r
352       ETH_MACDMAConfig(heth, err);\r
353       \r
354       /* Set the ETH peripheral state to READY */\r
355       heth->State = HAL_ETH_STATE_READY;\r
356       \r
357       /* Return HAL_ERROR */\r
358       return HAL_ERROR;   \r
359     }\r
360     \r
361     /* Configure the MAC with the Duplex Mode fixed by the auto-negotiation process */\r
362     if((phyreg & PHY_DUPLEX_STATUS) != (uint32_t)RESET)\r
363     {\r
364       /* Set Ethernet duplex mode to Full-duplex following the auto-negotiation */\r
365       (heth->Init).DuplexMode = ETH_MODE_FULLDUPLEX;  \r
366     }\r
367     else\r
368     {\r
369       /* Set Ethernet duplex mode to Half-duplex following the auto-negotiation */\r
370       (heth->Init).DuplexMode = ETH_MODE_HALFDUPLEX;           \r
371     }\r
372     /* Configure the MAC with the speed fixed by the auto-negotiation process */\r
373     if((phyreg & PHY_SPEED_STATUS) == PHY_SPEED_STATUS)\r
374     {  \r
375       /* Set Ethernet speed to 10M following the auto-negotiation */\r
376       (heth->Init).Speed = ETH_SPEED_10M; \r
377     }\r
378     else\r
379     {   \r
380       /* Set Ethernet speed to 100M following the auto-negotiation */ \r
381       (heth->Init).Speed = ETH_SPEED_100M;\r
382     }\r
383   }\r
384   else /* AutoNegotiation Disable */\r
385   {\r
386     /* Check parameters */\r
387     assert_param(IS_ETH_SPEED(heth->Init.Speed));\r
388     assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode));\r
389     \r
390     /* Set MAC Speed and Duplex Mode */\r
391     if(HAL_ETH_WritePHYRegister(heth, PHY_BCR, ((uint16_t)((heth->Init).DuplexMode >> 3) |\r
392                                                 (uint16_t)((heth->Init).Speed >> 1))) != HAL_OK)\r
393     {\r
394       /* In case of write timeout */\r
395       err = ETH_ERROR;\r
396       \r
397       /* Config MAC and DMA */\r
398       ETH_MACDMAConfig(heth, err);\r
399       \r
400       /* Set the ETH peripheral state to READY */\r
401       heth->State = HAL_ETH_STATE_READY;\r
402       \r
403       /* Return HAL_ERROR */\r
404       return HAL_ERROR;\r
405     }  \r
406     \r
407     /* Delay to assure PHY configuration */\r
408     HAL_Delay(PHY_CONFIG_DELAY);\r
409   }\r
410   \r
411   /* Config MAC and DMA */\r
412   ETH_MACDMAConfig(heth, err);\r
413   \r
414   /* Set ETH HAL State to Ready */\r
415   heth->State= HAL_ETH_STATE_READY;\r
416   \r
417   /* Return function status */\r
418   return HAL_OK;\r
419 }\r
420 \r
421 /**\r
422   * @brief  De-Initializes the ETH peripheral. \r
423   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
424   *         the configuration information for ETHERNET module\r
425   * @retval HAL status\r
426   */\r
427 HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth)\r
428 {\r
429   /* Set the ETH peripheral state to BUSY */\r
430   heth->State = HAL_ETH_STATE_BUSY;\r
431   \r
432   /* De-Init the low level hardware : GPIO, CLOCK, NVIC. */\r
433   HAL_ETH_MspDeInit(heth);\r
434   \r
435   /* Set ETH HAL state to Disabled */\r
436   heth->State= HAL_ETH_STATE_RESET;\r
437 \r
438   /* Release Lock */\r
439   __HAL_UNLOCK(heth);\r
440 \r
441   /* Return function status */\r
442   return HAL_OK;\r
443 }\r
444 \r
445 /**\r
446   * @brief  Initializes the DMA Tx descriptors in chain mode.\r
447   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
448   *         the configuration information for ETHERNET module  \r
449   * @param  DMATxDescTab: Pointer to the first Tx desc list \r
450   * @param  TxBuff: Pointer to the first TxBuffer list\r
451   * @param  TxBuffCount: Number of the used Tx desc in the list\r
452   * @retval HAL status\r
453   */\r
454 HAL_StatusTypeDef HAL_ETH_DMATxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMATxDescTab, uint8_t *TxBuff, uint32_t TxBuffCount)\r
455 {\r
456   uint32_t i = 0;\r
457   ETH_DMADescTypeDef *dmatxdesc;\r
458   \r
459   /* Process Locked */\r
460   __HAL_LOCK(heth);\r
461   \r
462   /* Set the ETH peripheral state to BUSY */\r
463   heth->State = HAL_ETH_STATE_BUSY;\r
464   \r
465   /* Set the DMATxDescToSet pointer with the first one of the DMATxDescTab list */\r
466   heth->TxDesc = DMATxDescTab;\r
467   \r
468   /* Fill each DMATxDesc descriptor with the right values */   \r
469   for(i=0; i < TxBuffCount; i++)\r
470   {\r
471     /* Get the pointer on the ith member of the Tx Desc list */\r
472     dmatxdesc = DMATxDescTab + i;\r
473     \r
474     /* Set Second Address Chained bit */\r
475     dmatxdesc->Status = ETH_DMATXDESC_TCH;  \r
476     \r
477     /* Set Buffer1 address pointer */\r
478     dmatxdesc->Buffer1Addr = (uint32_t)(&TxBuff[i*ETH_TX_BUF_SIZE]);\r
479     \r
480     if ((heth->Init).ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)\r
481     {\r
482       /* Set the DMA Tx descriptors checksum insertion */\r
483       dmatxdesc->Status |= ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL;\r
484     }\r
485     \r
486     /* Initialize the next descriptor with the Next Descriptor Polling Enable */\r
487     if(i < (TxBuffCount-1))\r
488     {\r
489       /* Set next descriptor address register with next descriptor base address */\r
490       dmatxdesc->Buffer2NextDescAddr = (uint32_t)(DMATxDescTab+i+1);\r
491     }\r
492     else\r
493     {\r
494       /* For last descriptor, set next descriptor address register equal to the first descriptor base address */ \r
495       dmatxdesc->Buffer2NextDescAddr = (uint32_t) DMATxDescTab;  \r
496     }\r
497   }\r
498   \r
499   /* Set Transmit Descriptor List Address Register */\r
500   (heth->Instance)->DMATDLAR = (uint32_t) DMATxDescTab;\r
501   \r
502   /* Set ETH HAL State to Ready */\r
503   heth->State= HAL_ETH_STATE_READY;\r
504   \r
505   /* Process Unlocked */\r
506   __HAL_UNLOCK(heth);\r
507   \r
508   /* Return function status */\r
509   return HAL_OK;\r
510 }\r
511 \r
512 /**\r
513   * @brief  Initializes the DMA Rx descriptors in chain mode.\r
514   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
515   *         the configuration information for ETHERNET module  \r
516   * @param  DMARxDescTab: Pointer to the first Rx desc list \r
517   * @param  RxBuff: Pointer to the first RxBuffer list\r
518   * @param  RxBuffCount: Number of the used Rx desc in the list\r
519   * @retval HAL status\r
520   */\r
521 HAL_StatusTypeDef HAL_ETH_DMARxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMARxDescTab, uint8_t *RxBuff, uint32_t RxBuffCount)\r
522 {\r
523   uint32_t i = 0;\r
524   ETH_DMADescTypeDef *DMARxDesc;\r
525   \r
526   /* Process Locked */\r
527   __HAL_LOCK(heth);\r
528   \r
529   /* Set the ETH peripheral state to BUSY */\r
530   heth->State = HAL_ETH_STATE_BUSY;\r
531   \r
532   /* Set the Ethernet RxDesc pointer with the first one of the DMARxDescTab list */\r
533   heth->RxDesc = DMARxDescTab; \r
534   \r
535   /* Fill each DMARxDesc descriptor with the right values */\r
536   for(i=0; i < RxBuffCount; i++)\r
537   {\r
538     /* Get the pointer on the ith member of the Rx Desc list */\r
539     DMARxDesc = DMARxDescTab+i;\r
540     \r
541     /* Set Own bit of the Rx descriptor Status */\r
542     DMARxDesc->Status = ETH_DMARXDESC_OWN;\r
543     \r
544     /* Set Buffer1 size and Second Address Chained bit */\r
545     DMARxDesc->ControlBufferSize = ETH_DMARXDESC_RCH | ETH_RX_BUF_SIZE;  \r
546     \r
547     /* Set Buffer1 address pointer */\r
548     DMARxDesc->Buffer1Addr = (uint32_t)(&RxBuff[i*ETH_RX_BUF_SIZE]);\r
549     \r
550     if((heth->Init).RxMode == ETH_RXINTERRUPT_MODE)\r
551     {\r
552       /* Enable Ethernet DMA Rx Descriptor interrupt */\r
553       DMARxDesc->ControlBufferSize &= ~ETH_DMARXDESC_DIC;\r
554     }\r
555     \r
556     /* Initialize the next descriptor with the Next Descriptor Polling Enable */\r
557     if(i < (RxBuffCount-1))\r
558     {\r
559       /* Set next descriptor address register with next descriptor base address */\r
560       DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab+i+1); \r
561     }\r
562     else\r
563     {\r
564       /* For last descriptor, set next descriptor address register equal to the first descriptor base address */ \r
565       DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab); \r
566     }\r
567   }\r
568   \r
569   /* Set Receive Descriptor List Address Register */\r
570   (heth->Instance)->DMARDLAR = (uint32_t) DMARxDescTab;\r
571   \r
572   /* Set ETH HAL State to Ready */\r
573   heth->State= HAL_ETH_STATE_READY;\r
574   \r
575   /* Process Unlocked */\r
576   __HAL_UNLOCK(heth);\r
577   \r
578   /* Return function status */\r
579   return HAL_OK;\r
580 }\r
581 \r
582 /**\r
583   * @brief  Initializes the ETH MSP.\r
584   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
585   *         the configuration information for ETHERNET module\r
586   * @retval None\r
587   */\r
588 __weak void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)\r
589 {\r
590   /* NOTE : This function Should not be modified, when the callback is needed,\r
591   the HAL_ETH_MspInit could be implemented in the user file\r
592   */\r
593 }\r
594 \r
595 /**\r
596   * @brief  DeInitializes ETH MSP.\r
597   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
598   *         the configuration information for ETHERNET module\r
599   * @retval None\r
600   */\r
601 __weak void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)\r
602 {\r
603   /* NOTE : This function Should not be modified, when the callback is needed,\r
604   the HAL_ETH_MspDeInit could be implemented in the user file\r
605   */\r
606 }\r
607 \r
608 /**\r
609   * @}\r
610   */\r
611 \r
612 /** @defgroup ETH_Exported_Functions_Group2 IO operation functions \r
613   *  @brief   Data transfers functions \r
614   *\r
615   @verbatim   \r
616   ==============================================================================\r
617                           ##### IO operation functions #####\r
618   ==============================================================================  \r
619   [..]  This section provides functions allowing to:\r
620         (+) Transmit a frame\r
621             HAL_ETH_TransmitFrame();\r
622         (+) Receive a frame\r
623             HAL_ETH_GetReceivedFrame();\r
624             HAL_ETH_GetReceivedFrame_IT();\r
625         (+) Read from an External PHY register\r
626             HAL_ETH_ReadPHYRegister();\r
627         (+) Write to an External PHY register\r
628             HAL_ETH_WritePHYRegister();\r
629 \r
630   @endverbatim\r
631   \r
632   * @{\r
633   */\r
634 \r
635 /**\r
636   * @brief  Sends an Ethernet frame. \r
637   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
638   *         the configuration information for ETHERNET module\r
639   * @param  FrameLength: Amount of data to be sent\r
640   * @retval HAL status\r
641   */\r
642 HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameLength)\r
643 {\r
644   uint32_t bufcount = 0, size = 0, i = 0;\r
645   \r
646   /* Process Locked */\r
647   __HAL_LOCK(heth);\r
648   \r
649   /* Set the ETH peripheral state to BUSY */\r
650   heth->State = HAL_ETH_STATE_BUSY;\r
651   \r
652   if (FrameLength == 0) \r
653   {\r
654     /* Set ETH HAL state to READY */\r
655     heth->State = HAL_ETH_STATE_READY;\r
656     \r
657     /* Process Unlocked */\r
658     __HAL_UNLOCK(heth);\r
659     \r
660     return  HAL_ERROR;                                    \r
661   }  \r
662   \r
663   /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */\r
664   if(((heth->TxDesc)->Status & ETH_DMATXDESC_OWN) != (uint32_t)RESET)\r
665   {  \r
666     /* OWN bit set */\r
667     heth->State = HAL_ETH_STATE_BUSY_TX;\r
668     \r
669     /* Process Unlocked */\r
670     __HAL_UNLOCK(heth);\r
671     \r
672     return HAL_ERROR;\r
673   }\r
674   \r
675   /* Get the number of needed Tx buffers for the current frame */\r
676   if (FrameLength > ETH_TX_BUF_SIZE)\r
677   {\r
678     bufcount = FrameLength/ETH_TX_BUF_SIZE;\r
679     if (FrameLength % ETH_TX_BUF_SIZE) \r
680     {\r
681       bufcount++;\r
682     }\r
683   }\r
684   else \r
685   {  \r
686     bufcount = 1;\r
687   }\r
688   if (bufcount == 1)\r
689   {\r
690     /* Set LAST and FIRST segment */\r
691     heth->TxDesc->Status |=ETH_DMATXDESC_FS|ETH_DMATXDESC_LS;\r
692     /* Set frame size */\r
693     heth->TxDesc->ControlBufferSize = (FrameLength & ETH_DMATXDESC_TBS1);\r
694     /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */\r
695     heth->TxDesc->Status |= ETH_DMATXDESC_OWN;\r
696     /* Point to next descriptor */\r
697     heth->TxDesc= (ETH_DMADescTypeDef *)(heth->TxDesc->Buffer2NextDescAddr);\r
698   }\r
699   else\r
700   {\r
701     for (i=0; i< bufcount; i++)\r
702     {\r
703       /* Clear FIRST and LAST segment bits */\r
704       heth->TxDesc->Status &= ~(ETH_DMATXDESC_FS | ETH_DMATXDESC_LS);\r
705       \r
706       if (i == 0) \r
707       {\r
708         /* Setting the first segment bit */\r
709         heth->TxDesc->Status |= ETH_DMATXDESC_FS;  \r
710       }\r
711       \r
712       /* Program size */\r
713       heth->TxDesc->ControlBufferSize = (ETH_TX_BUF_SIZE & ETH_DMATXDESC_TBS1);\r
714       \r
715       if (i == (bufcount-1))\r
716       {\r
717         /* Setting the last segment bit */\r
718         heth->TxDesc->Status |= ETH_DMATXDESC_LS;\r
719         size = FrameLength - (bufcount-1)*ETH_TX_BUF_SIZE;\r
720         heth->TxDesc->ControlBufferSize = (size & ETH_DMATXDESC_TBS1);\r
721       }\r
722       \r
723       /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */\r
724       heth->TxDesc->Status |= ETH_DMATXDESC_OWN;\r
725       /* point to next descriptor */\r
726       heth->TxDesc = (ETH_DMADescTypeDef *)(heth->TxDesc->Buffer2NextDescAddr);\r
727     }\r
728   }\r
729   \r
730   /* When Tx Buffer unavailable flag is set: clear it and resume transmission */\r
731   if (((heth->Instance)->DMASR & ETH_DMASR_TBUS) != (uint32_t)RESET)\r
732   {\r
733     /* Clear TBUS ETHERNET DMA flag */\r
734     (heth->Instance)->DMASR = ETH_DMASR_TBUS;\r
735     /* Resume DMA transmission*/\r
736     (heth->Instance)->DMATPDR = 0;\r
737   }\r
738   \r
739   /* Set ETH HAL State to Ready */\r
740   heth->State = HAL_ETH_STATE_READY;\r
741   \r
742   /* Process Unlocked */\r
743   __HAL_UNLOCK(heth);\r
744   \r
745   /* Return function status */\r
746   return HAL_OK;\r
747 }\r
748 \r
749 /**\r
750   * @brief  Checks for received frames. \r
751   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
752   *         the configuration information for ETHERNET module\r
753   * @retval HAL status\r
754   */\r
755 HAL_StatusTypeDef HAL_ETH_GetReceivedFrame(ETH_HandleTypeDef *heth)\r
756 {\r
757   uint32_t framelength = 0;\r
758   \r
759   /* Process Locked */\r
760   __HAL_LOCK(heth);\r
761   \r
762   /* Check the ETH state to BUSY */\r
763   heth->State = HAL_ETH_STATE_BUSY;\r
764   \r
765   /* Check if segment is not owned by DMA */\r
766   /* (((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) && ((heth->RxDesc->Status & ETH_DMARXDESC_LS) != (uint32_t)RESET)) */\r
767   if(((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET))\r
768   {\r
769     /* Check if last segment */\r
770     if(((heth->RxDesc->Status & ETH_DMARXDESC_LS) != (uint32_t)RESET)) \r
771     {\r
772       /* increment segment count */\r
773       (heth->RxFrameInfos).SegCount++;\r
774       \r
775       /* Check if last segment is first segment: one segment contains the frame */\r
776       if ((heth->RxFrameInfos).SegCount == 1)\r
777       {\r
778         (heth->RxFrameInfos).FSRxDesc =heth->RxDesc;\r
779       }\r
780       \r
781       heth->RxFrameInfos.LSRxDesc = heth->RxDesc;\r
782       \r
783       /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */\r
784       framelength = (((heth->RxDesc)->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4;\r
785       heth->RxFrameInfos.length = framelength;\r
786       \r
787       /* Get the address of the buffer start address */\r
788       heth->RxFrameInfos.buffer = ((heth->RxFrameInfos).FSRxDesc)->Buffer1Addr;\r
789       /* point to next descriptor */\r
790       heth->RxDesc = (ETH_DMADescTypeDef*) ((heth->RxDesc)->Buffer2NextDescAddr);\r
791       \r
792       /* Set HAL State to Ready */\r
793       heth->State = HAL_ETH_STATE_READY;\r
794       \r
795       /* Process Unlocked */\r
796       __HAL_UNLOCK(heth);\r
797       \r
798       /* Return function status */\r
799       return HAL_OK;\r
800     }\r
801     /* Check if first segment */\r
802     else if((heth->RxDesc->Status & ETH_DMARXDESC_FS) != (uint32_t)RESET)\r
803     {\r
804       (heth->RxFrameInfos).FSRxDesc = heth->RxDesc;\r
805       (heth->RxFrameInfos).LSRxDesc = NULL;\r
806       (heth->RxFrameInfos).SegCount = 1;\r
807       /* Point to next descriptor */\r
808       heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);\r
809     }\r
810     /* Check if intermediate segment */ \r
811     else\r
812     {\r
813       (heth->RxFrameInfos).SegCount++;\r
814       /* Point to next descriptor */\r
815       heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);\r
816     } \r
817   }\r
818   \r
819   /* Set ETH HAL State to Ready */\r
820   heth->State = HAL_ETH_STATE_READY;\r
821   \r
822   /* Process Unlocked */\r
823   __HAL_UNLOCK(heth);\r
824   \r
825   /* Return function status */\r
826   return HAL_ERROR;\r
827 }\r
828 \r
829 /**\r
830   * @brief  Gets the Received frame in interrupt mode. \r
831   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
832   *         the configuration information for ETHERNET module\r
833   * @retval HAL status\r
834   */\r
835 HAL_StatusTypeDef HAL_ETH_GetReceivedFrame_IT(ETH_HandleTypeDef *heth)\r
836 {\r
837   uint32_t descriptorscancounter = 0;\r
838   \r
839   /* Process Locked */\r
840   __HAL_LOCK(heth);\r
841   \r
842   /* Set ETH HAL State to BUSY */\r
843   heth->State = HAL_ETH_STATE_BUSY;\r
844   \r
845   /* Scan descriptors owned by CPU */\r
846   while (((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) && (descriptorscancounter < ETH_RXBUFNB))\r
847   {\r
848     /* Just for security */\r
849     descriptorscancounter++;\r
850     \r
851     /* Check if first segment in frame */\r
852     /* ((heth->RxDesc->Status & ETH_DMARXDESC_FS) != (uint32_t)RESET) && ((heth->RxDesc->Status & ETH_DMARXDESC_LS) == (uint32_t)RESET)) */  \r
853     if((heth->RxDesc->Status & (ETH_DMARXDESC_FS | ETH_DMARXDESC_LS)) == (uint32_t)ETH_DMARXDESC_FS)\r
854     { \r
855       heth->RxFrameInfos.FSRxDesc = heth->RxDesc;\r
856       heth->RxFrameInfos.SegCount = 1;   \r
857       /* Point to next descriptor */\r
858       heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);\r
859     }\r
860     /* Check if intermediate segment */\r
861     /* ((heth->RxDesc->Status & ETH_DMARXDESC_LS) == (uint32_t)RESET)&& ((heth->RxDesc->Status & ETH_DMARXDESC_FS) == (uint32_t)RESET)) */\r
862     else if ((heth->RxDesc->Status & (ETH_DMARXDESC_LS | ETH_DMARXDESC_FS)) == (uint32_t)RESET)\r
863     {\r
864       /* Increment segment count */\r
865       (heth->RxFrameInfos.SegCount)++;\r
866       /* Point to next descriptor */\r
867       heth->RxDesc = (ETH_DMADescTypeDef*)(heth->RxDesc->Buffer2NextDescAddr);\r
868     }\r
869     /* Should be last segment */\r
870     else\r
871     { \r
872       /* Last segment */\r
873       heth->RxFrameInfos.LSRxDesc = heth->RxDesc;\r
874       \r
875       /* Increment segment count */\r
876       (heth->RxFrameInfos.SegCount)++;\r
877       \r
878       /* Check if last segment is first segment: one segment contains the frame */\r
879       if ((heth->RxFrameInfos.SegCount) == 1)\r
880       {\r
881         heth->RxFrameInfos.FSRxDesc = heth->RxDesc;\r
882       }\r
883       \r
884       /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */\r
885       heth->RxFrameInfos.length = (((heth->RxDesc)->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4;\r
886       \r
887       /* Get the address of the buffer start address */ \r
888       heth->RxFrameInfos.buffer =((heth->RxFrameInfos).FSRxDesc)->Buffer1Addr;\r
889       \r
890       /* Point to next descriptor */      \r
891       heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);\r
892       \r
893       /* Set HAL State to Ready */\r
894       heth->State = HAL_ETH_STATE_READY;\r
895       \r
896       /* Process Unlocked */\r
897       __HAL_UNLOCK(heth);\r
898   \r
899       /* Return function status */\r
900       return HAL_OK;\r
901     }\r
902   }\r
903 \r
904   /* Set HAL State to Ready */\r
905   heth->State = HAL_ETH_STATE_READY;\r
906   \r
907   /* Process Unlocked */\r
908   __HAL_UNLOCK(heth);\r
909   \r
910   /* Return function status */\r
911   return HAL_ERROR;\r
912 }\r
913 \r
914 /**\r
915   * @brief  This function handles ETH interrupt request.\r
916   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
917   *         the configuration information for ETHERNET module\r
918   * @retval HAL status\r
919   */\r
920 void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth)\r
921 {\r
922   /* Frame received */\r
923   if (__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_R)) \r
924   {\r
925     /* Receive complete callback */\r
926     HAL_ETH_RxCpltCallback(heth);\r
927     \r
928      /* Clear the Eth DMA Rx IT pending bits */\r
929     __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_R);\r
930 \r
931     /* Set HAL State to Ready */\r
932     heth->State = HAL_ETH_STATE_READY;\r
933     \r
934     /* Process Unlocked */\r
935     __HAL_UNLOCK(heth);\r
936 \r
937   }\r
938   /* Frame transmitted */\r
939   else if (__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_T)) \r
940   {\r
941     /* Transfer complete callback */\r
942     HAL_ETH_TxCpltCallback(heth);\r
943     \r
944     /* Clear the Eth DMA Tx IT pending bits */\r
945     __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_T);\r
946 \r
947     /* Set HAL State to Ready */\r
948     heth->State = HAL_ETH_STATE_READY;\r
949     \r
950     /* Process Unlocked */\r
951     __HAL_UNLOCK(heth);\r
952   }\r
953   \r
954   /* Clear the interrupt flags */\r
955   __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_NIS);\r
956   \r
957   /* ETH DMA Error */\r
958   if(__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_AIS))\r
959   {\r
960     /* Ethernet Error callback */\r
961     HAL_ETH_ErrorCallback(heth);\r
962 \r
963     /* Clear the interrupt flags */\r
964     __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_FLAG_AIS);\r
965   \r
966     /* Set HAL State to Ready */\r
967     heth->State = HAL_ETH_STATE_READY;\r
968     \r
969     /* Process Unlocked */\r
970     __HAL_UNLOCK(heth);\r
971   }\r
972 }\r
973 \r
974 /**\r
975   * @brief  Tx Transfer completed callbacks.\r
976   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
977   *         the configuration information for ETHERNET module\r
978   * @retval None\r
979   */\r
980 __weak void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)\r
981 {\r
982   /* NOTE : This function Should not be modified, when the callback is needed,\r
983   the HAL_ETH_TxCpltCallback could be implemented in the user file\r
984   */ \r
985 }\r
986 \r
987 /**\r
988   * @brief  Rx Transfer completed callbacks.\r
989   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
990   *         the configuration information for ETHERNET module\r
991   * @retval None\r
992   */\r
993 __weak void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)\r
994 {\r
995   /* NOTE : This function Should not be modified, when the callback is needed,\r
996   the HAL_ETH_TxCpltCallback could be implemented in the user file\r
997   */ \r
998 }\r
999 \r
1000 /**\r
1001   * @brief  Ethernet transfer error callbacks\r
1002   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1003   *         the configuration information for ETHERNET module\r
1004   * @retval None\r
1005   */\r
1006 __weak void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)\r
1007 {\r
1008   /* NOTE : This function Should not be modified, when the callback is needed,\r
1009   the HAL_ETH_TxCpltCallback could be implemented in the user file\r
1010   */ \r
1011 }\r
1012 \r
1013 /**\r
1014   * @brief  Reads a PHY register\r
1015   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1016   *         the configuration information for ETHERNET module                  \r
1017   * @param PHYReg: PHY register address, is the index of one of the 32 PHY register. \r
1018   *                This parameter can be one of the following values: \r
1019   *                   PHY_BCR: Transceiver Basic Control Register, \r
1020   *                   PHY_BSR: Transceiver Basic Status Register.   \r
1021   *                   More PHY register could be read depending on the used PHY\r
1022   * @param RegValue: PHY register value                  \r
1023   * @retval HAL status\r
1024   */\r
1025 HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t *RegValue)\r
1026 {\r
1027   uint32_t tmpreg = 0;     \r
1028   uint32_t tickstart = 0;\r
1029   \r
1030   /* Check parameters */\r
1031   assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));\r
1032   \r
1033   /* Check the ETH peripheral state */\r
1034   if(heth->State == HAL_ETH_STATE_BUSY_RD)\r
1035   {\r
1036     return HAL_BUSY;\r
1037   }\r
1038   /* Set ETH HAL State to BUSY_RD */\r
1039   heth->State = HAL_ETH_STATE_BUSY_RD;\r
1040   \r
1041   /* Get the ETHERNET MACMIIAR value */\r
1042   tmpreg = heth->Instance->MACMIIAR;\r
1043   \r
1044   /* Keep only the CSR Clock Range CR[2:0] bits value */\r
1045   tmpreg &= ~ETH_MACMIIAR_CR_MASK;\r
1046   \r
1047   /* Prepare the MII address register value */\r
1048   tmpreg |=(((uint32_t)heth->Init.PhyAddress << 11) & ETH_MACMIIAR_PA); /* Set the PHY device address   */\r
1049   tmpreg |=(((uint32_t)PHYReg<<6) & ETH_MACMIIAR_MR);                   /* Set the PHY register address */\r
1050   tmpreg &= ~ETH_MACMIIAR_MW;                                           /* Set the read mode            */\r
1051   tmpreg |= ETH_MACMIIAR_MB;                                            /* Set the MII Busy bit         */\r
1052   \r
1053   /* Write the result value into the MII Address register */\r
1054   heth->Instance->MACMIIAR = tmpreg;\r
1055   \r
1056   /* Get tick */\r
1057   tickstart = HAL_GetTick();\r
1058   \r
1059   /* Check for the Busy flag */\r
1060   while((tmpreg & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB)\r
1061   {\r
1062     /* Check for the Timeout */\r
1063     if((HAL_GetTick() - tickstart ) > PHY_READ_TO)\r
1064     {\r
1065       heth->State= HAL_ETH_STATE_READY;\r
1066   \r
1067       /* Process Unlocked */\r
1068       __HAL_UNLOCK(heth);\r
1069     \r
1070       return HAL_TIMEOUT;\r
1071     }\r
1072     \r
1073     tmpreg = heth->Instance->MACMIIAR;\r
1074   }\r
1075   \r
1076   /* Get MACMIIDR value */\r
1077   *RegValue = (uint16_t)(heth->Instance->MACMIIDR);\r
1078   \r
1079   /* Set ETH HAL State to READY */\r
1080   heth->State = HAL_ETH_STATE_READY;\r
1081   \r
1082   /* Return function status */\r
1083   return HAL_OK;\r
1084 }\r
1085 \r
1086 /**\r
1087   * @brief  Writes to a PHY register.\r
1088   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1089   *         the configuration information for ETHERNET module  \r
1090   * @param  PHYReg: PHY register address, is the index of one of the 32 PHY register. \r
1091   *          This parameter can be one of the following values: \r
1092   *             PHY_BCR: Transceiver Control Register.  \r
1093   *             More PHY register could be written depending on the used PHY\r
1094   * @param  RegValue: the value to write\r
1095   * @retval HAL status\r
1096   */\r
1097 HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t RegValue)\r
1098 {\r
1099   uint32_t tmpreg = 0;\r
1100   uint32_t tickstart = 0;\r
1101   \r
1102   /* Check parameters */\r
1103   assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));\r
1104   \r
1105   /* Check the ETH peripheral state */\r
1106   if(heth->State == HAL_ETH_STATE_BUSY_WR)\r
1107   {\r
1108     return HAL_BUSY;\r
1109   }\r
1110   /* Set ETH HAL State to BUSY_WR */\r
1111   heth->State = HAL_ETH_STATE_BUSY_WR;\r
1112   \r
1113   /* Get the ETHERNET MACMIIAR value */\r
1114   tmpreg = heth->Instance->MACMIIAR;\r
1115   \r
1116   /* Keep only the CSR Clock Range CR[2:0] bits value */\r
1117   tmpreg &= ~ETH_MACMIIAR_CR_MASK;\r
1118   \r
1119   /* Prepare the MII register address value */\r
1120   tmpreg |=(((uint32_t)heth->Init.PhyAddress<<11) & ETH_MACMIIAR_PA); /* Set the PHY device address */\r
1121   tmpreg |=(((uint32_t)PHYReg<<6) & ETH_MACMIIAR_MR);                 /* Set the PHY register address */\r
1122   tmpreg |= ETH_MACMIIAR_MW;                                          /* Set the write mode */\r
1123   tmpreg |= ETH_MACMIIAR_MB;                                          /* Set the MII Busy bit */\r
1124   \r
1125   /* Give the value to the MII data register */\r
1126   heth->Instance->MACMIIDR = (uint16_t)RegValue;\r
1127   \r
1128   /* Write the result value into the MII Address register */\r
1129   heth->Instance->MACMIIAR = tmpreg;\r
1130   \r
1131   /* Get tick */\r
1132   tickstart = HAL_GetTick();\r
1133   \r
1134   /* Check for the Busy flag */\r
1135   while((tmpreg & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB)\r
1136   {\r
1137     /* Check for the Timeout */\r
1138     if((HAL_GetTick() - tickstart ) > PHY_WRITE_TO)\r
1139     {\r
1140       heth->State= HAL_ETH_STATE_READY;\r
1141   \r
1142       /* Process Unlocked */\r
1143       __HAL_UNLOCK(heth);\r
1144     \r
1145       return HAL_TIMEOUT;\r
1146     }\r
1147     \r
1148     tmpreg = heth->Instance->MACMIIAR;\r
1149   }\r
1150   \r
1151   /* Set ETH HAL State to READY */\r
1152   heth->State = HAL_ETH_STATE_READY;\r
1153   \r
1154   /* Return function status */\r
1155   return HAL_OK; \r
1156 }\r
1157 \r
1158 /**\r
1159   * @}\r
1160   */\r
1161 \r
1162 /** @defgroup ETH_Exported_Functions_Group3 Peripheral Control functions\r
1163  *  @brief    Peripheral Control functions \r
1164  *\r
1165 @verbatim   \r
1166  ===============================================================================\r
1167                   ##### Peripheral Control functions #####\r
1168  ===============================================================================  \r
1169     [..]  This section provides functions allowing to:\r
1170       (+) Enable MAC and DMA transmission and reception.\r
1171           HAL_ETH_Start();\r
1172       (+) Disable MAC and DMA transmission and reception. \r
1173           HAL_ETH_Stop();\r
1174       (+) Set the MAC configuration in runtime mode\r
1175           HAL_ETH_ConfigMAC();\r
1176       (+) Set the DMA configuration in runtime mode\r
1177           HAL_ETH_ConfigDMA();\r
1178 \r
1179 @endverbatim\r
1180   * @{\r
1181   */ \r
1182 \r
1183  /**\r
1184   * @brief  Enables Ethernet MAC and DMA reception/transmission \r
1185   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1186   *         the configuration information for ETHERNET module\r
1187   * @retval HAL status\r
1188   */\r
1189 HAL_StatusTypeDef HAL_ETH_Start(ETH_HandleTypeDef *heth)\r
1190 {  \r
1191   /* Process Locked */\r
1192   __HAL_LOCK(heth);\r
1193   \r
1194   /* Set the ETH peripheral state to BUSY */\r
1195   heth->State = HAL_ETH_STATE_BUSY;\r
1196   \r
1197   /* Enable transmit state machine of the MAC for transmission on the MII */\r
1198   ETH_MACTransmissionEnable(heth);\r
1199   \r
1200   /* Enable receive state machine of the MAC for reception from the MII */\r
1201   ETH_MACReceptionEnable(heth);\r
1202   \r
1203   /* Flush Transmit FIFO */\r
1204   ETH_FlushTransmitFIFO(heth);\r
1205   \r
1206   /* Start DMA transmission */\r
1207   ETH_DMATransmissionEnable(heth);\r
1208   \r
1209   /* Start DMA reception */\r
1210   ETH_DMAReceptionEnable(heth);\r
1211   \r
1212   /* Set the ETH state to READY*/\r
1213   heth->State= HAL_ETH_STATE_READY;\r
1214   \r
1215   /* Process Unlocked */\r
1216   __HAL_UNLOCK(heth);\r
1217   \r
1218   /* Return function status */\r
1219   return HAL_OK;\r
1220 }\r
1221 \r
1222 /**\r
1223   * @brief  Stop Ethernet MAC and DMA reception/transmission \r
1224   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1225   *         the configuration information for ETHERNET module\r
1226   * @retval HAL status\r
1227   */\r
1228 HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth)\r
1229 {  \r
1230   /* Process Locked */\r
1231   __HAL_LOCK(heth);\r
1232   \r
1233   /* Set the ETH peripheral state to BUSY */\r
1234   heth->State = HAL_ETH_STATE_BUSY;\r
1235   \r
1236   /* Stop DMA transmission */\r
1237   ETH_DMATransmissionDisable(heth);\r
1238   \r
1239   /* Stop DMA reception */\r
1240   ETH_DMAReceptionDisable(heth);\r
1241   \r
1242   /* Disable receive state machine of the MAC for reception from the MII */\r
1243   ETH_MACReceptionDisable(heth);\r
1244   \r
1245   /* Flush Transmit FIFO */\r
1246   ETH_FlushTransmitFIFO(heth);\r
1247   \r
1248   /* Disable transmit state machine of the MAC for transmission on the MII */\r
1249   ETH_MACTransmissionDisable(heth);\r
1250   \r
1251   /* Set the ETH state*/\r
1252   heth->State = HAL_ETH_STATE_READY;\r
1253   \r
1254   /* Process Unlocked */\r
1255   __HAL_UNLOCK(heth);\r
1256   \r
1257   /* Return function status */\r
1258   return HAL_OK;\r
1259 }\r
1260 \r
1261 /**\r
1262   * @brief  Set ETH MAC Configuration.\r
1263   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1264   *         the configuration information for ETHERNET module\r
1265   * @param  macconf: MAC Configuration structure  \r
1266   * @retval HAL status\r
1267   */\r
1268 HAL_StatusTypeDef HAL_ETH_ConfigMAC(ETH_HandleTypeDef *heth, ETH_MACInitTypeDef *macconf)\r
1269 {\r
1270   uint32_t tmpreg = 0;\r
1271   \r
1272   /* Process Locked */\r
1273   __HAL_LOCK(heth);\r
1274   \r
1275   /* Set the ETH peripheral state to BUSY */\r
1276   heth->State= HAL_ETH_STATE_BUSY;\r
1277   \r
1278   assert_param(IS_ETH_SPEED(heth->Init.Speed));\r
1279   assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode)); \r
1280   \r
1281   if (macconf != NULL)\r
1282   {\r
1283     /* Check the parameters */\r
1284     assert_param(IS_ETH_WATCHDOG(macconf->Watchdog));\r
1285     assert_param(IS_ETH_JABBER(macconf->Jabber));\r
1286     assert_param(IS_ETH_INTER_FRAME_GAP(macconf->InterFrameGap));\r
1287     assert_param(IS_ETH_CARRIER_SENSE(macconf->CarrierSense));\r
1288     assert_param(IS_ETH_RECEIVE_OWN(macconf->ReceiveOwn));\r
1289     assert_param(IS_ETH_LOOPBACK_MODE(macconf->LoopbackMode));\r
1290     assert_param(IS_ETH_CHECKSUM_OFFLOAD(macconf->ChecksumOffload));\r
1291     assert_param(IS_ETH_RETRY_TRANSMISSION(macconf->RetryTransmission));\r
1292     assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(macconf->AutomaticPadCRCStrip));\r
1293     assert_param(IS_ETH_BACKOFF_LIMIT(macconf->BackOffLimit));\r
1294     assert_param(IS_ETH_DEFERRAL_CHECK(macconf->DeferralCheck));\r
1295     assert_param(IS_ETH_RECEIVE_ALL(macconf->ReceiveAll));\r
1296     assert_param(IS_ETH_SOURCE_ADDR_FILTER(macconf->SourceAddrFilter));\r
1297     assert_param(IS_ETH_CONTROL_FRAMES(macconf->PassControlFrames));\r
1298     assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(macconf->BroadcastFramesReception));\r
1299     assert_param(IS_ETH_DESTINATION_ADDR_FILTER(macconf->DestinationAddrFilter));\r
1300     assert_param(IS_ETH_PROMISCUOUS_MODE(macconf->PromiscuousMode));\r
1301     assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(macconf->MulticastFramesFilter));\r
1302     assert_param(IS_ETH_UNICAST_FRAMES_FILTER(macconf->UnicastFramesFilter));\r
1303     assert_param(IS_ETH_PAUSE_TIME(macconf->PauseTime));\r
1304     assert_param(IS_ETH_ZEROQUANTA_PAUSE(macconf->ZeroQuantaPause));\r
1305     assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(macconf->PauseLowThreshold));\r
1306     assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(macconf->UnicastPauseFrameDetect));\r
1307     assert_param(IS_ETH_RECEIVE_FLOWCONTROL(macconf->ReceiveFlowControl));\r
1308     assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(macconf->TransmitFlowControl));\r
1309     assert_param(IS_ETH_VLAN_TAG_COMPARISON(macconf->VLANTagComparison));\r
1310     assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(macconf->VLANTagIdentifier));\r
1311     \r
1312     /*------------------------ ETHERNET MACCR Configuration --------------------*/\r
1313     /* Get the ETHERNET MACCR value */\r
1314     tmpreg = (heth->Instance)->MACCR;\r
1315     /* Clear WD, PCE, PS, TE and RE bits */\r
1316     tmpreg &= ETH_MACCR_CLEAR_MASK;\r
1317     \r
1318     tmpreg |= (uint32_t)(macconf->Watchdog | \r
1319                          macconf->Jabber | \r
1320                          macconf->InterFrameGap |\r
1321                          macconf->CarrierSense |\r
1322                          (heth->Init).Speed | \r
1323                          macconf->ReceiveOwn |\r
1324                          macconf->LoopbackMode |\r
1325                          (heth->Init).DuplexMode | \r
1326                          macconf->ChecksumOffload |    \r
1327                          macconf->RetryTransmission | \r
1328                          macconf->AutomaticPadCRCStrip | \r
1329                          macconf->BackOffLimit | \r
1330                          macconf->DeferralCheck);\r
1331     \r
1332     /* Write to ETHERNET MACCR */\r
1333     (heth->Instance)->MACCR = (uint32_t)tmpreg;\r
1334     \r
1335     /* Wait until the write operation will be taken into account :\r
1336     at least four TX_CLK/RX_CLK clock cycles */\r
1337     tmpreg = (heth->Instance)->MACCR;\r
1338     HAL_Delay(ETH_REG_WRITE_DELAY);\r
1339     (heth->Instance)->MACCR = tmpreg; \r
1340     \r
1341     /*----------------------- ETHERNET MACFFR Configuration --------------------*/ \r
1342     /* Write to ETHERNET MACFFR */  \r
1343     (heth->Instance)->MACFFR = (uint32_t)(macconf->ReceiveAll | \r
1344                                           macconf->SourceAddrFilter |\r
1345                                           macconf->PassControlFrames |\r
1346                                           macconf->BroadcastFramesReception | \r
1347                                           macconf->DestinationAddrFilter |\r
1348                                           macconf->PromiscuousMode |\r
1349                                           macconf->MulticastFramesFilter |\r
1350                                           macconf->UnicastFramesFilter);\r
1351      \r
1352      /* Wait until the write operation will be taken into account :\r
1353      at least four TX_CLK/RX_CLK clock cycles */\r
1354      tmpreg = (heth->Instance)->MACFFR;\r
1355      HAL_Delay(ETH_REG_WRITE_DELAY);\r
1356      (heth->Instance)->MACFFR = tmpreg;\r
1357      \r
1358      /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/\r
1359      /* Write to ETHERNET MACHTHR */\r
1360      (heth->Instance)->MACHTHR = (uint32_t)macconf->HashTableHigh;\r
1361      \r
1362      /* Write to ETHERNET MACHTLR */\r
1363      (heth->Instance)->MACHTLR = (uint32_t)macconf->HashTableLow;\r
1364      /*----------------------- ETHERNET MACFCR Configuration --------------------*/\r
1365      \r
1366      /* Get the ETHERNET MACFCR value */  \r
1367      tmpreg = (heth->Instance)->MACFCR;\r
1368      /* Clear xx bits */\r
1369      tmpreg &= ETH_MACFCR_CLEAR_MASK;\r
1370      \r
1371      tmpreg |= (uint32_t)((macconf->PauseTime << 16) | \r
1372                           macconf->ZeroQuantaPause |\r
1373                           macconf->PauseLowThreshold |\r
1374                           macconf->UnicastPauseFrameDetect | \r
1375                           macconf->ReceiveFlowControl |\r
1376                           macconf->TransmitFlowControl); \r
1377      \r
1378      /* Write to ETHERNET MACFCR */\r
1379      (heth->Instance)->MACFCR = (uint32_t)tmpreg;\r
1380      \r
1381      /* Wait until the write operation will be taken into account :\r
1382      at least four TX_CLK/RX_CLK clock cycles */\r
1383      tmpreg = (heth->Instance)->MACFCR;\r
1384      HAL_Delay(ETH_REG_WRITE_DELAY);\r
1385      (heth->Instance)->MACFCR = tmpreg;\r
1386      \r
1387      /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/\r
1388      (heth->Instance)->MACVLANTR = (uint32_t)(macconf->VLANTagComparison | \r
1389                                               macconf->VLANTagIdentifier);\r
1390       \r
1391       /* Wait until the write operation will be taken into account :\r
1392       at least four TX_CLK/RX_CLK clock cycles */\r
1393       tmpreg = (heth->Instance)->MACVLANTR;\r
1394       HAL_Delay(ETH_REG_WRITE_DELAY);\r
1395       (heth->Instance)->MACVLANTR = tmpreg;\r
1396   }\r
1397   else /* macconf == NULL : here we just configure Speed and Duplex mode */\r
1398   {\r
1399     /*------------------------ ETHERNET MACCR Configuration --------------------*/\r
1400     /* Get the ETHERNET MACCR value */\r
1401     tmpreg = (heth->Instance)->MACCR;\r
1402     \r
1403     /* Clear FES and DM bits */\r
1404     tmpreg &= ~((uint32_t)0x00004800);\r
1405     \r
1406     tmpreg |= (uint32_t)(heth->Init.Speed | heth->Init.DuplexMode);\r
1407     \r
1408     /* Write to ETHERNET MACCR */\r
1409     (heth->Instance)->MACCR = (uint32_t)tmpreg;\r
1410     \r
1411     /* Wait until the write operation will be taken into account:\r
1412     at least four TX_CLK/RX_CLK clock cycles */\r
1413     tmpreg = (heth->Instance)->MACCR;\r
1414     HAL_Delay(ETH_REG_WRITE_DELAY);\r
1415     (heth->Instance)->MACCR = tmpreg;\r
1416   }\r
1417   \r
1418   /* Set the ETH state to Ready */\r
1419   heth->State= HAL_ETH_STATE_READY;\r
1420   \r
1421   /* Process Unlocked */\r
1422   __HAL_UNLOCK(heth);\r
1423   \r
1424   /* Return function status */\r
1425   return HAL_OK;  \r
1426 }\r
1427 \r
1428 /**\r
1429   * @brief  Sets ETH DMA Configuration.\r
1430   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1431   *         the configuration information for ETHERNET module\r
1432   * @param  dmaconf: DMA Configuration structure  \r
1433   * @retval HAL status\r
1434   */\r
1435 HAL_StatusTypeDef HAL_ETH_ConfigDMA(ETH_HandleTypeDef *heth, ETH_DMAInitTypeDef *dmaconf)\r
1436 {\r
1437   uint32_t tmpreg = 0;\r
1438 \r
1439   /* Process Locked */\r
1440   __HAL_LOCK(heth);\r
1441   \r
1442   /* Set the ETH peripheral state to BUSY */\r
1443   heth->State= HAL_ETH_STATE_BUSY;\r
1444 \r
1445   /* Check parameters */\r
1446   assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(dmaconf->DropTCPIPChecksumErrorFrame));\r
1447   assert_param(IS_ETH_RECEIVE_STORE_FORWARD(dmaconf->ReceiveStoreForward));\r
1448   assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(dmaconf->FlushReceivedFrame));\r
1449   assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(dmaconf->TransmitStoreForward));\r
1450   assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(dmaconf->TransmitThresholdControl));\r
1451   assert_param(IS_ETH_FORWARD_ERROR_FRAMES(dmaconf->ForwardErrorFrames));\r
1452   assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(dmaconf->ForwardUndersizedGoodFrames));\r
1453   assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(dmaconf->ReceiveThresholdControl));\r
1454   assert_param(IS_ETH_SECOND_FRAME_OPERATE(dmaconf->SecondFrameOperate));\r
1455   assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(dmaconf->AddressAlignedBeats));\r
1456   assert_param(IS_ETH_FIXED_BURST(dmaconf->FixedBurst));\r
1457   assert_param(IS_ETH_RXDMA_BURST_LENGTH(dmaconf->RxDMABurstLength));\r
1458   assert_param(IS_ETH_TXDMA_BURST_LENGTH(dmaconf->TxDMABurstLength));\r
1459   assert_param(IS_ETH_ENHANCED_DESCRIPTOR_FORMAT(dmaconf->EnhancedDescriptorFormat));\r
1460   assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(dmaconf->DescriptorSkipLength));\r
1461   assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(dmaconf->DMAArbitration));\r
1462   \r
1463   /*----------------------- ETHERNET DMAOMR Configuration --------------------*/\r
1464   /* Get the ETHERNET DMAOMR value */\r
1465   tmpreg = (heth->Instance)->DMAOMR;\r
1466   /* Clear xx bits */\r
1467   tmpreg &= ETH_DMAOMR_CLEAR_MASK;\r
1468 \r
1469   tmpreg |= (uint32_t)(dmaconf->DropTCPIPChecksumErrorFrame | \r
1470                        dmaconf->ReceiveStoreForward |\r
1471                        dmaconf->FlushReceivedFrame |\r
1472                        dmaconf->TransmitStoreForward | \r
1473                        dmaconf->TransmitThresholdControl |\r
1474                        dmaconf->ForwardErrorFrames |\r
1475                        dmaconf->ForwardUndersizedGoodFrames |\r
1476                        dmaconf->ReceiveThresholdControl |\r
1477                        dmaconf->SecondFrameOperate);\r
1478 \r
1479   /* Write to ETHERNET DMAOMR */\r
1480   (heth->Instance)->DMAOMR = (uint32_t)tmpreg;\r
1481 \r
1482   /* Wait until the write operation will be taken into account:\r
1483   at least four TX_CLK/RX_CLK clock cycles */\r
1484   tmpreg = (heth->Instance)->DMAOMR;\r
1485   HAL_Delay(ETH_REG_WRITE_DELAY);\r
1486   (heth->Instance)->DMAOMR = tmpreg;\r
1487 \r
1488   /*----------------------- ETHERNET DMABMR Configuration --------------------*/\r
1489   (heth->Instance)->DMABMR = (uint32_t)(dmaconf->AddressAlignedBeats | \r
1490                                          dmaconf->FixedBurst |\r
1491                                          dmaconf->RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */\r
1492                                          dmaconf->TxDMABurstLength |\r
1493                                          dmaconf->EnhancedDescriptorFormat |\r
1494                                          (dmaconf->DescriptorSkipLength << 2) |\r
1495                                          dmaconf->DMAArbitration | \r
1496                                          ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */\r
1497 \r
1498    /* Wait until the write operation will be taken into account:\r
1499       at least four TX_CLK/RX_CLK clock cycles */\r
1500    tmpreg = (heth->Instance)->DMABMR;\r
1501    HAL_Delay(ETH_REG_WRITE_DELAY);\r
1502    (heth->Instance)->DMABMR = tmpreg;\r
1503 \r
1504    /* Set the ETH state to Ready */\r
1505    heth->State= HAL_ETH_STATE_READY;\r
1506    \r
1507    /* Process Unlocked */\r
1508    __HAL_UNLOCK(heth);\r
1509    \r
1510    /* Return function status */\r
1511    return HAL_OK; \r
1512 }\r
1513 \r
1514 /**\r
1515   * @}\r
1516   */\r
1517 \r
1518 /** @defgroup ETH_Exported_Functions_Group4 Peripheral State functions \r
1519   *  @brief   Peripheral State functions \r
1520   *\r
1521   @verbatim   \r
1522   ===============================================================================\r
1523                          ##### Peripheral State functions #####\r
1524   ===============================================================================  \r
1525   [..]\r
1526   This subsection permits to get in run-time the status of the peripheral \r
1527   and the data flow.\r
1528        (+) Get the ETH handle state:\r
1529            HAL_ETH_GetState();\r
1530            \r
1531 \r
1532   @endverbatim\r
1533   * @{\r
1534   */\r
1535 \r
1536 /**\r
1537   * @brief  Return the ETH HAL state\r
1538   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1539   *         the configuration information for ETHERNET module\r
1540   * @retval HAL state\r
1541   */\r
1542 HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth)\r
1543 {  \r
1544   /* Return ETH state */\r
1545   return heth->State;\r
1546 }\r
1547 \r
1548 /**\r
1549   * @}\r
1550   */\r
1551   \r
1552 /**\r
1553   * @}\r
1554   */\r
1555   \r
1556 /** @addtogroup ETH_Private_Functions\r
1557   * @{\r
1558   */\r
1559 \r
1560 /**\r
1561   * @brief  Configures Ethernet MAC and DMA with default parameters.\r
1562   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1563   *         the configuration information for ETHERNET module\r
1564   * @param  err: Ethernet Init error\r
1565   * @retval HAL status\r
1566   */\r
1567 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err)\r
1568 {\r
1569   ETH_MACInitTypeDef macinit;\r
1570   ETH_DMAInitTypeDef dmainit;\r
1571   uint32_t tmpreg = 0;\r
1572   \r
1573   if (err != ETH_SUCCESS) /* Auto-negotiation failed */\r
1574   {\r
1575     /* Set Ethernet duplex mode to Full-duplex */\r
1576     (heth->Init).DuplexMode = ETH_MODE_FULLDUPLEX;\r
1577     \r
1578     /* Set Ethernet speed to 100M */\r
1579     (heth->Init).Speed = ETH_SPEED_100M;\r
1580   }\r
1581   \r
1582   /* Ethernet MAC default initialization **************************************/\r
1583   macinit.Watchdog = ETH_WATCHDOG_ENABLE;\r
1584   macinit.Jabber = ETH_JABBER_ENABLE;\r
1585   macinit.InterFrameGap = ETH_INTERFRAMEGAP_96BIT;\r
1586   macinit.CarrierSense = ETH_CARRIERSENCE_ENABLE;\r
1587   macinit.ReceiveOwn = ETH_RECEIVEOWN_ENABLE;\r
1588   macinit.LoopbackMode = ETH_LOOPBACKMODE_DISABLE;\r
1589   if(heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)\r
1590   {\r
1591     macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;\r
1592   }\r
1593   else\r
1594   {\r
1595     macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;\r
1596   }\r
1597   macinit.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE;\r
1598   macinit.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE;\r
1599   macinit.BackOffLimit = ETH_BACKOFFLIMIT_10;\r
1600   macinit.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE;\r
1601   macinit.ReceiveAll = ETH_RECEIVEAll_DISABLE;\r
1602   macinit.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE;\r
1603   macinit.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL;\r
1604   macinit.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE;\r
1605   macinit.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL;\r
1606   macinit.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE;\r
1607   macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;\r
1608   macinit.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT;\r
1609   macinit.HashTableHigh = 0x0;\r
1610   macinit.HashTableLow = 0x0;\r
1611   macinit.PauseTime = 0x0;\r
1612   macinit.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE;\r
1613   macinit.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;\r
1614   macinit.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE;\r
1615   macinit.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE;\r
1616   macinit.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE;\r
1617   macinit.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT;\r
1618   macinit.VLANTagIdentifier = 0x0;\r
1619   \r
1620   /*------------------------ ETHERNET MACCR Configuration --------------------*/\r
1621   /* Get the ETHERNET MACCR value */\r
1622   tmpreg = (heth->Instance)->MACCR;\r
1623   /* Clear WD, PCE, PS, TE and RE bits */\r
1624   tmpreg &= ETH_MACCR_CLEAR_MASK;\r
1625   /* Set the WD bit according to ETH Watchdog value */\r
1626   /* Set the JD: bit according to ETH Jabber value */\r
1627   /* Set the IFG bit according to ETH InterFrameGap value */\r
1628   /* Set the DCRS bit according to ETH CarrierSense value */\r
1629   /* Set the FES bit according to ETH Speed value */ \r
1630   /* Set the DO bit according to ETH ReceiveOwn value */ \r
1631   /* Set the LM bit according to ETH LoopbackMode value */\r
1632   /* Set the DM bit according to ETH Mode value */ \r
1633   /* Set the IPCO bit according to ETH ChecksumOffload value */\r
1634   /* Set the DR bit according to ETH RetryTransmission value */\r
1635   /* Set the ACS bit according to ETH AutomaticPadCRCStrip value */\r
1636   /* Set the BL bit according to ETH BackOffLimit value */\r
1637   /* Set the DC bit according to ETH DeferralCheck value */\r
1638   tmpreg |= (uint32_t)(macinit.Watchdog | \r
1639                        macinit.Jabber | \r
1640                        macinit.InterFrameGap |\r
1641                        macinit.CarrierSense |\r
1642                        (heth->Init).Speed | \r
1643                        macinit.ReceiveOwn |\r
1644                        macinit.LoopbackMode |\r
1645                        (heth->Init).DuplexMode | \r
1646                        macinit.ChecksumOffload |    \r
1647                        macinit.RetryTransmission | \r
1648                        macinit.AutomaticPadCRCStrip | \r
1649                        macinit.BackOffLimit | \r
1650                        macinit.DeferralCheck);\r
1651   \r
1652   /* Write to ETHERNET MACCR */\r
1653   (heth->Instance)->MACCR = (uint32_t)tmpreg;\r
1654   \r
1655   /* Wait until the write operation will be taken into account:\r
1656      at least four TX_CLK/RX_CLK clock cycles */\r
1657   tmpreg = (heth->Instance)->MACCR;\r
1658   HAL_Delay(ETH_REG_WRITE_DELAY);\r
1659   (heth->Instance)->MACCR = tmpreg; \r
1660   \r
1661   /*----------------------- ETHERNET MACFFR Configuration --------------------*/ \r
1662   /* Set the RA bit according to ETH ReceiveAll value */\r
1663   /* Set the SAF and SAIF bits according to ETH SourceAddrFilter value */\r
1664   /* Set the PCF bit according to ETH PassControlFrames value */\r
1665   /* Set the DBF bit according to ETH BroadcastFramesReception value */\r
1666   /* Set the DAIF bit according to ETH DestinationAddrFilter value */\r
1667   /* Set the PR bit according to ETH PromiscuousMode value */\r
1668   /* Set the PM, HMC and HPF bits according to ETH MulticastFramesFilter value */\r
1669   /* Set the HUC and HPF bits according to ETH UnicastFramesFilter value */\r
1670   /* Write to ETHERNET MACFFR */  \r
1671   (heth->Instance)->MACFFR = (uint32_t)(macinit.ReceiveAll | \r
1672                                         macinit.SourceAddrFilter |\r
1673                                         macinit.PassControlFrames |\r
1674                                         macinit.BroadcastFramesReception | \r
1675                                         macinit.DestinationAddrFilter |\r
1676                                         macinit.PromiscuousMode |\r
1677                                         macinit.MulticastFramesFilter |\r
1678                                         macinit.UnicastFramesFilter);\r
1679    \r
1680    /* Wait until the write operation will be taken into account:\r
1681       at least four TX_CLK/RX_CLK clock cycles */\r
1682    tmpreg = (heth->Instance)->MACFFR;\r
1683    HAL_Delay(ETH_REG_WRITE_DELAY);\r
1684    (heth->Instance)->MACFFR = tmpreg;\r
1685    \r
1686    /*--------------- ETHERNET MACHTHR and MACHTLR Configuration --------------*/\r
1687    /* Write to ETHERNET MACHTHR */\r
1688    (heth->Instance)->MACHTHR = (uint32_t)macinit.HashTableHigh;\r
1689    \r
1690    /* Write to ETHERNET MACHTLR */\r
1691    (heth->Instance)->MACHTLR = (uint32_t)macinit.HashTableLow;\r
1692    /*----------------------- ETHERNET MACFCR Configuration -------------------*/\r
1693    \r
1694    /* Get the ETHERNET MACFCR value */  \r
1695    tmpreg = (heth->Instance)->MACFCR;\r
1696    /* Clear xx bits */\r
1697    tmpreg &= ETH_MACFCR_CLEAR_MASK;\r
1698    \r
1699    /* Set the PT bit according to ETH PauseTime value */\r
1700    /* Set the DZPQ bit according to ETH ZeroQuantaPause value */\r
1701    /* Set the PLT bit according to ETH PauseLowThreshold value */\r
1702    /* Set the UP bit according to ETH UnicastPauseFrameDetect value */\r
1703    /* Set the RFE bit according to ETH ReceiveFlowControl value */\r
1704    /* Set the TFE bit according to ETH TransmitFlowControl value */ \r
1705    tmpreg |= (uint32_t)((macinit.PauseTime << 16) | \r
1706                         macinit.ZeroQuantaPause |\r
1707                         macinit.PauseLowThreshold |\r
1708                         macinit.UnicastPauseFrameDetect | \r
1709                         macinit.ReceiveFlowControl |\r
1710                         macinit.TransmitFlowControl); \r
1711    \r
1712    /* Write to ETHERNET MACFCR */\r
1713    (heth->Instance)->MACFCR = (uint32_t)tmpreg;\r
1714    \r
1715    /* Wait until the write operation will be taken into account:\r
1716    at least four TX_CLK/RX_CLK clock cycles */\r
1717    tmpreg = (heth->Instance)->MACFCR;\r
1718    HAL_Delay(ETH_REG_WRITE_DELAY);\r
1719    (heth->Instance)->MACFCR = tmpreg;\r
1720    \r
1721    /*----------------------- ETHERNET MACVLANTR Configuration ----------------*/\r
1722    /* Set the ETV bit according to ETH VLANTagComparison value */\r
1723    /* Set the VL bit according to ETH VLANTagIdentifier value */  \r
1724    (heth->Instance)->MACVLANTR = (uint32_t)(macinit.VLANTagComparison | \r
1725                                             macinit.VLANTagIdentifier);\r
1726     \r
1727     /* Wait until the write operation will be taken into account:\r
1728        at least four TX_CLK/RX_CLK clock cycles */\r
1729     tmpreg = (heth->Instance)->MACVLANTR;\r
1730     HAL_Delay(ETH_REG_WRITE_DELAY);\r
1731     (heth->Instance)->MACVLANTR = tmpreg;\r
1732     \r
1733     /* Ethernet DMA default initialization ************************************/\r
1734     dmainit.DropTCPIPChecksumErrorFrame = ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE;\r
1735     dmainit.ReceiveStoreForward = ETH_RECEIVESTOREFORWARD_ENABLE;\r
1736     dmainit.FlushReceivedFrame = ETH_FLUSHRECEIVEDFRAME_ENABLE;\r
1737     dmainit.TransmitStoreForward = ETH_TRANSMITSTOREFORWARD_ENABLE;  \r
1738     dmainit.TransmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;\r
1739     dmainit.ForwardErrorFrames = ETH_FORWARDERRORFRAMES_DISABLE;\r
1740     dmainit.ForwardUndersizedGoodFrames = ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE;\r
1741     dmainit.ReceiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;\r
1742     dmainit.SecondFrameOperate = ETH_SECONDFRAMEOPERARTE_ENABLE;\r
1743     dmainit.AddressAlignedBeats = ETH_ADDRESSALIGNEDBEATS_ENABLE;\r
1744     dmainit.FixedBurst = ETH_FIXEDBURST_ENABLE;\r
1745     dmainit.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;\r
1746     dmainit.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;\r
1747     dmainit.EnhancedDescriptorFormat = ETH_DMAENHANCEDDESCRIPTOR_ENABLE;\r
1748     dmainit.DescriptorSkipLength = 0x0;\r
1749     dmainit.DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;\r
1750     \r
1751     /* Get the ETHERNET DMAOMR value */\r
1752     tmpreg = (heth->Instance)->DMAOMR;\r
1753     /* Clear xx bits */\r
1754     tmpreg &= ETH_DMAOMR_CLEAR_MASK;\r
1755     \r
1756     /* Set the DT bit according to ETH DropTCPIPChecksumErrorFrame value */\r
1757     /* Set the RSF bit according to ETH ReceiveStoreForward value */\r
1758     /* Set the DFF bit according to ETH FlushReceivedFrame value */\r
1759     /* Set the TSF bit according to ETH TransmitStoreForward value */\r
1760     /* Set the TTC bit according to ETH TransmitThresholdControl value */\r
1761     /* Set the FEF bit according to ETH ForwardErrorFrames value */\r
1762     /* Set the FUF bit according to ETH ForwardUndersizedGoodFrames value */\r
1763     /* Set the RTC bit according to ETH ReceiveThresholdControl value */\r
1764     /* Set the OSF bit according to ETH SecondFrameOperate value */\r
1765     tmpreg |= (uint32_t)(dmainit.DropTCPIPChecksumErrorFrame | \r
1766                          dmainit.ReceiveStoreForward |\r
1767                          dmainit.FlushReceivedFrame |\r
1768                          dmainit.TransmitStoreForward | \r
1769                          dmainit.TransmitThresholdControl |\r
1770                          dmainit.ForwardErrorFrames |\r
1771                          dmainit.ForwardUndersizedGoodFrames |\r
1772                          dmainit.ReceiveThresholdControl |\r
1773                          dmainit.SecondFrameOperate);\r
1774     \r
1775     /* Write to ETHERNET DMAOMR */\r
1776     (heth->Instance)->DMAOMR = (uint32_t)tmpreg;\r
1777     \r
1778     /* Wait until the write operation will be taken into account:\r
1779        at least four TX_CLK/RX_CLK clock cycles */\r
1780     tmpreg = (heth->Instance)->DMAOMR;\r
1781     HAL_Delay(ETH_REG_WRITE_DELAY);\r
1782     (heth->Instance)->DMAOMR = tmpreg;\r
1783     \r
1784     /*----------------------- ETHERNET DMABMR Configuration ------------------*/\r
1785     /* Set the AAL bit according to ETH AddressAlignedBeats value */\r
1786     /* Set the FB bit according to ETH FixedBurst value */\r
1787     /* Set the RPBL and 4*PBL bits according to ETH RxDMABurstLength value */\r
1788     /* Set the PBL and 4*PBL bits according to ETH TxDMABurstLength value */\r
1789     /* Set the Enhanced DMA descriptors bit according to ETH EnhancedDescriptorFormat value*/\r
1790     /* Set the DSL bit according to ETH DesciptorSkipLength value */\r
1791     /* Set the PR and DA bits according to ETH DMAArbitration value */\r
1792     (heth->Instance)->DMABMR = (uint32_t)(dmainit.AddressAlignedBeats | \r
1793                                           dmainit.FixedBurst |\r
1794                                           dmainit.RxDMABurstLength |    /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */\r
1795                                           dmainit.TxDMABurstLength |\r
1796                                           dmainit.EnhancedDescriptorFormat |\r
1797                                           (dmainit.DescriptorSkipLength << 2) |\r
1798                                           dmainit.DMAArbitration |\r
1799                                           ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */\r
1800      \r
1801      /* Wait until the write operation will be taken into account:\r
1802         at least four TX_CLK/RX_CLK clock cycles */\r
1803      tmpreg = (heth->Instance)->DMABMR;\r
1804      HAL_Delay(ETH_REG_WRITE_DELAY);\r
1805      (heth->Instance)->DMABMR = tmpreg;\r
1806 \r
1807      if((heth->Init).RxMode == ETH_RXINTERRUPT_MODE)\r
1808      {\r
1809        /* Enable the Ethernet Rx Interrupt */\r
1810        __HAL_ETH_DMA_ENABLE_IT((heth), ETH_DMA_IT_NIS | ETH_DMA_IT_R);\r
1811      }\r
1812 \r
1813      /* Initialize MAC address in ethernet MAC */ \r
1814      ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr);\r
1815 }\r
1816 \r
1817 /**\r
1818   * @brief  Configures the selected MAC address.\r
1819   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1820   *         the configuration information for ETHERNET module\r
1821   * @param  MacAddr: The MAC address to configure\r
1822   *          This parameter can be one of the following values:\r
1823   *             @arg ETH_MAC_Address0: MAC Address0 \r
1824   *             @arg ETH_MAC_Address1: MAC Address1 \r
1825   *             @arg ETH_MAC_Address2: MAC Address2\r
1826   *             @arg ETH_MAC_Address3: MAC Address3\r
1827   * @param  Addr: Pointer to MAC address buffer data (6 bytes)\r
1828   * @retval HAL status\r
1829   */\r
1830 static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr)\r
1831 {\r
1832   uint32_t tmpreg;\r
1833   \r
1834   /* Check the parameters */\r
1835   assert_param(IS_ETH_MAC_ADDRESS0123(MacAddr));\r
1836   \r
1837   /* Calculate the selected MAC address high register */\r
1838   tmpreg = ((uint32_t)Addr[5] << 8) | (uint32_t)Addr[4];\r
1839   /* Load the selected MAC address high register */\r
1840   (*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_HBASE + MacAddr))) = tmpreg;\r
1841   /* Calculate the selected MAC address low register */\r
1842   tmpreg = ((uint32_t)Addr[3] << 24) | ((uint32_t)Addr[2] << 16) | ((uint32_t)Addr[1] << 8) | Addr[0];\r
1843   \r
1844   /* Load the selected MAC address low register */\r
1845   (*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_LBASE + MacAddr))) = tmpreg;\r
1846 }\r
1847 \r
1848 /**\r
1849   * @brief  Enables the MAC transmission.\r
1850   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1851   *         the configuration information for ETHERNET module  \r
1852   * @retval None\r
1853   */\r
1854 static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth)\r
1855\r
1856   __IO uint32_t tmpreg = 0;\r
1857   \r
1858   /* Enable the MAC transmission */\r
1859   (heth->Instance)->MACCR |= ETH_MACCR_TE;\r
1860   \r
1861   /* Wait until the write operation will be taken into account:\r
1862      at least four TX_CLK/RX_CLK clock cycles */\r
1863   tmpreg = (heth->Instance)->MACCR;\r
1864   HAL_Delay(ETH_REG_WRITE_DELAY);\r
1865   (heth->Instance)->MACCR = tmpreg;\r
1866 }\r
1867 \r
1868 /**\r
1869   * @brief  Disables the MAC transmission.\r
1870   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1871   *         the configuration information for ETHERNET module  \r
1872   * @retval None\r
1873   */\r
1874 static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth)\r
1875\r
1876   __IO uint32_t tmpreg = 0;\r
1877   \r
1878   /* Disable the MAC transmission */\r
1879   (heth->Instance)->MACCR &= ~ETH_MACCR_TE;\r
1880   \r
1881   /* Wait until the write operation will be taken into account:\r
1882      at least four TX_CLK/RX_CLK clock cycles */\r
1883   tmpreg = (heth->Instance)->MACCR;\r
1884   HAL_Delay(ETH_REG_WRITE_DELAY);\r
1885   (heth->Instance)->MACCR = tmpreg;\r
1886 }\r
1887 \r
1888 /**\r
1889   * @brief  Enables the MAC reception.\r
1890   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1891   *         the configuration information for ETHERNET module   \r
1892   * @retval None\r
1893   */\r
1894 static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth)\r
1895\r
1896   __IO uint32_t tmpreg = 0;\r
1897   \r
1898   /* Enable the MAC reception */\r
1899   (heth->Instance)->MACCR |= ETH_MACCR_RE;\r
1900   \r
1901   /* Wait until the write operation will be taken into account:\r
1902      at least four TX_CLK/RX_CLK clock cycles */\r
1903   tmpreg = (heth->Instance)->MACCR;\r
1904   HAL_Delay(ETH_REG_WRITE_DELAY);\r
1905   (heth->Instance)->MACCR = tmpreg;\r
1906 }\r
1907 \r
1908 /**\r
1909   * @brief  Disables the MAC reception.\r
1910   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1911   *         the configuration information for ETHERNET module   \r
1912   * @retval None\r
1913   */\r
1914 static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth)\r
1915\r
1916   __IO uint32_t tmpreg = 0;\r
1917   \r
1918   /* Disable the MAC reception */\r
1919   (heth->Instance)->MACCR &= ~ETH_MACCR_RE; \r
1920   \r
1921   /* Wait until the write operation will be taken into account:\r
1922      at least four TX_CLK/RX_CLK clock cycles */\r
1923   tmpreg = (heth->Instance)->MACCR;\r
1924   HAL_Delay(ETH_REG_WRITE_DELAY);\r
1925   (heth->Instance)->MACCR = tmpreg;\r
1926 }\r
1927 \r
1928 /**\r
1929   * @brief  Enables the DMA transmission.\r
1930   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1931   *         the configuration information for ETHERNET module   \r
1932   * @retval None\r
1933   */\r
1934 static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth)\r
1935 {\r
1936   /* Enable the DMA transmission */\r
1937   (heth->Instance)->DMAOMR |= ETH_DMAOMR_ST;  \r
1938 }\r
1939 \r
1940 /**\r
1941   * @brief  Disables the DMA transmission.\r
1942   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1943   *         the configuration information for ETHERNET module   \r
1944   * @retval None\r
1945   */\r
1946 static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth)\r
1947\r
1948   /* Disable the DMA transmission */\r
1949   (heth->Instance)->DMAOMR &= ~ETH_DMAOMR_ST;\r
1950 }\r
1951 \r
1952 /**\r
1953   * @brief  Enables the DMA reception.\r
1954   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1955   *         the configuration information for ETHERNET module \r
1956   * @retval None\r
1957   */\r
1958 static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth)\r
1959 {  \r
1960   /* Enable the DMA reception */\r
1961   (heth->Instance)->DMAOMR |= ETH_DMAOMR_SR;  \r
1962 }\r
1963 \r
1964 /**\r
1965   * @brief  Disables the DMA reception.\r
1966   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1967   *         the configuration information for ETHERNET module \r
1968   * @retval None\r
1969   */\r
1970 static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth)\r
1971\r
1972   /* Disable the DMA reception */\r
1973   (heth->Instance)->DMAOMR &= ~ETH_DMAOMR_SR;\r
1974 }\r
1975 \r
1976 /**\r
1977   * @brief  Clears the ETHERNET transmit FIFO.\r
1978   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1979   *         the configuration information for ETHERNET module\r
1980   * @retval None\r
1981   */\r
1982 static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth)\r
1983 {\r
1984   __IO uint32_t tmpreg = 0;\r
1985   \r
1986   /* Set the Flush Transmit FIFO bit */\r
1987   (heth->Instance)->DMAOMR |= ETH_DMAOMR_FTF;\r
1988   \r
1989   /* Wait until the write operation will be taken into account:\r
1990      at least four TX_CLK/RX_CLK clock cycles */\r
1991   tmpreg = (heth->Instance)->DMAOMR;\r
1992   HAL_Delay(ETH_REG_WRITE_DELAY);\r
1993   (heth->Instance)->DMAOMR = tmpreg;\r
1994 }\r
1995 \r
1996 /**\r
1997   * @}\r
1998   */\r
1999 \r
2000 #endif /* HAL_ETH_MODULE_ENABLED */\r
2001 /**\r
2002   * @}\r
2003   */\r
2004 \r
2005 /**\r
2006   * @}\r
2007   */\r
2008 \r
2009 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r