]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/STM32Fxx/stm32fxx_hal_eth.c
Sync FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP with the version in GitHub at (23665258ca...
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / STM32Fxx / stm32fxx_hal_eth.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32fxx_hal_eth.c\r
4   * @author  MCD Application Team\r
5   * @version V1.3.2\r
6   * @date    26-June-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       -@- The PTP protocol and the DMA descriptors ring mode are not supported\r
68           in this driver\r
69 \r
70   @endverbatim\r
71   ******************************************************************************\r
72   * @attention\r
73   *\r
74   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
75   *\r
76   * Redistribution and use in source and binary forms, with or without modification,\r
77   * are permitted provided that the following conditions are met:\r
78   *   1. Redistributions of source code must retain the above copyright notice,\r
79   *      this list of conditions and the following disclaimer.\r
80   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
81   *      this list of conditions and the following disclaimer in the documentation\r
82   *      and/or other materials provided with the distribution.\r
83   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
84   *      may be used to endorse or promote products derived from this software\r
85   *      without specific prior written permission.\r
86   *\r
87   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
88   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
89   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
90   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
91   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
92   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
93   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
94   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
95   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
96   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
97   *\r
98   ******************************************************************************\r
99   */\r
100 \r
101 /* Includes ------------------------------------------------------------------*/\r
102 \r
103 #if defined(STM32F7xx)\r
104         #include "stm32f7xx_hal.h"\r
105         #define stm_is_F7       1\r
106 #elif defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\r
107         #include "stm32f4xx_hal.h"\r
108         #define stm_is_F4       1\r
109 #elif defined(STM32F2xx)\r
110         #include "stm32f2xx_hal.h"\r
111         #define stm_is_F2       1\r
112 #else\r
113         #error For what part should this be compiled?\r
114 #endif\r
115 \r
116 #include "stm32fxx_hal_eth.h"\r
117 \r
118 /** @addtogroup STM32F4xx_HAL_Driver\r
119   * @{\r
120   */\r
121 \r
122 /** @defgroup ETH ETH\r
123   * @brief ETH HAL module driver\r
124   * @{\r
125   */\r
126 \r
127 #if !defined( ARRAY_SIZE )\r
128         #define ARRAY_SIZE( x ) ( sizeof ( x ) / sizeof ( x )[ 0 ] )\r
129 #endif\r
130 \r
131 #ifdef HAL_ETH_MODULE_ENABLED\r
132 \r
133 #if( stm_is_F2 != 0 || stm_is_F4 != 0 || stm_is_F7 )\r
134 \r
135 /* Private typedef -----------------------------------------------------------*/\r
136 /* Private define ------------------------------------------------------------*/\r
137 /** @defgroup ETH_Private_Constants ETH Private Constants\r
138   * @{\r
139   */\r
140 \r
141 /**\r
142   * @}\r
143   */\r
144 /* Private macro -------------------------------------------------------------*/\r
145 /* Private variables ---------------------------------------------------------*/\r
146 /* Private function prototypes -----------------------------------------------*/\r
147 /** @defgroup ETH_Private_Functions ETH Private Functions\r
148   * @{\r
149   */\r
150 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err);\r
151 static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr);\r
152 static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth);\r
153 static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth);\r
154 static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth);\r
155 static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth);\r
156 static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth);\r
157 static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth);\r
158 static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth);\r
159 static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth);\r
160 static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth);\r
161 \r
162 /**\r
163   * @}\r
164   */\r
165 /* Private functions ---------------------------------------------------------*/\r
166 \r
167 /** @defgroup ETH_Exported_Functions ETH Exported Functions\r
168   * @{\r
169   */\r
170 \r
171 /** @defgroup ETH_Exported_Functions_Group1 Initialization and de-initialization functions\r
172   *  @brief   Initialization and Configuration functions\r
173   *\r
174   @verbatim\r
175   ===============================================================================\r
176             ##### Initialization and de-initialization functions #####\r
177   ===============================================================================\r
178   [..]  This section provides functions allowing to:\r
179       (+) Initialize and configure the Ethernet peripheral\r
180       (+) De-initialize the Ethernet peripheral\r
181 \r
182   @endverbatim\r
183   * @{\r
184   */\r
185 extern void vMACBProbePhy ( void );\r
186 \r
187 /**\r
188   * @brief  Initializes the Ethernet MAC and DMA according to default\r
189   *         parameters.\r
190   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
191   *         the configuration information for ETHERNET module\r
192   * @retval HAL status\r
193   */\r
194 HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth)\r
195 {\r
196         uint32_t tmpreg = 0uL;\r
197         uint32_t hclk = 60000000uL;\r
198         uint32_t err = ETH_SUCCESS;\r
199 \r
200         /* Check the ETH peripheral state */\r
201         if( heth == NULL )\r
202         {\r
203                 return HAL_ERROR;\r
204         }\r
205 \r
206         /* Check parameters */\r
207         assert_param(IS_ETH_AUTONEGOTIATION(heth->Init.AutoNegotiation));\r
208         assert_param(IS_ETH_RX_MODE(heth->Init.RxMode));\r
209         assert_param(IS_ETH_CHECKSUM_MODE(heth->Init.ChecksumMode));\r
210         assert_param(IS_ETH_MEDIA_INTERFACE(heth->Init.MediaInterface));\r
211 \r
212         if( heth->State == HAL_ETH_STATE_RESET )\r
213         {\r
214                 /* Init the low level hardware : GPIO, CLOCK, NVIC. */\r
215                 HAL_ETH_MspInit( heth );\r
216         }\r
217 \r
218         /* Enable SYSCFG Clock */\r
219         __HAL_RCC_SYSCFG_CLK_ENABLE();\r
220 \r
221         /* Select MII or RMII Mode*/\r
222         SYSCFG->PMC &= ~(SYSCFG_PMC_MII_RMII_SEL);\r
223         SYSCFG->PMC |= (uint32_t)heth->Init.MediaInterface;\r
224 \r
225         /* Ethernet Software reset */\r
226         /* Set the SWR bit: resets all MAC subsystem internal registers and logic */\r
227         /* After reset all the registers holds their respective reset values */\r
228         /* Also enable EDFE: Enhanced descriptor format enable. */\r
229         heth->Instance->DMABMR |= ETH_DMABMR_SR | ETH_DMABMR_EDE;\r
230 \r
231         /* Wait for software reset */\r
232         while ((heth->Instance->DMABMR & ETH_DMABMR_SR) != (uint32_t)RESET)\r
233         {\r
234                 /* If your program hangs here, please check the value of 'ipconfigUSE_RMII'. */\r
235         }\r
236 \r
237         /*-------------------------------- MAC Initialization ----------------------*/\r
238         /* Get the ETHERNET MACMIIAR value */\r
239         tmpreg = heth->Instance->MACMIIAR;\r
240         /* Clear CSR Clock Range CR[2:0] bits */\r
241         tmpreg &= ETH_MACMIIAR_CR_MASK;\r
242 \r
243         /* Get hclk frequency value (e.g. 168,000,000) */\r
244         hclk = HAL_RCC_GetHCLKFreq();\r
245 \r
246         /* Set CR bits depending on hclk value */\r
247         if(( hclk >= 20000000uL ) && ( hclk < 35000000uL ) )\r
248         {\r
249                 /* CSR Clock Range between 20-35 MHz */\r
250                 tmpreg |= ( uint32_t) ETH_MACMIIAR_CR_Div16;\r
251         }\r
252         else if( ( hclk >= 35000000uL ) && ( hclk < 60000000uL ) )\r
253         {\r
254         /* CSR Clock Range between 35-60 MHz */\r
255         tmpreg |= ( uint32_t ) ETH_MACMIIAR_CR_Div26;\r
256         }\r
257         else if( ( hclk >= 60000000uL ) && ( hclk < 100000000uL ) )\r
258         {\r
259                 /* CSR Clock Range between 60-100 MHz */\r
260                 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;\r
261         }\r
262         else if( ( hclk >= 100000000uL ) && ( hclk < 150000000uL ) )\r
263         {\r
264                 /* CSR Clock Range between 100-150 MHz */\r
265                 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div62;\r
266         }\r
267         else /* ( ( hclk >= 150000000uL ) && ( hclk <= 183000000uL ) ) */\r
268         {\r
269                 /* CSR Clock Range between 150-183 MHz */\r
270                 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div102;\r
271         }\r
272 \r
273         /* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */\r
274         heth->Instance->MACMIIAR = (uint32_t)tmpreg;\r
275 \r
276         /* Initialise the MACB and set all PHY properties */\r
277         vMACBProbePhy();\r
278 \r
279         /* Config MAC and DMA */\r
280         ETH_MACDMAConfig(heth, err);\r
281 \r
282         /* Set ETH HAL State to Ready */\r
283         heth->State= HAL_ETH_STATE_READY;\r
284 \r
285         /* Return function status */\r
286         return HAL_OK;\r
287 }\r
288 \r
289 /**\r
290   * @brief  De-Initializes the ETH peripheral.\r
291   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
292   *         the configuration information for ETHERNET module\r
293   * @retval HAL status\r
294   */\r
295 HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth)\r
296 {\r
297         /* Set the ETH peripheral state to BUSY */\r
298         heth->State = HAL_ETH_STATE_BUSY;\r
299 \r
300         /* De-Init the low level hardware : GPIO, CLOCK, NVIC. */\r
301         HAL_ETH_MspDeInit( heth );\r
302 \r
303         /* Set ETH HAL state to Disabled */\r
304         heth->State= HAL_ETH_STATE_RESET;\r
305 \r
306         /* Release Lock */\r
307         __HAL_UNLOCK( heth );\r
308 \r
309         /* Return function status */\r
310         return HAL_OK;\r
311 }\r
312 \r
313 /**\r
314   * @brief  Initializes the ETH MSP.\r
315   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
316   *         the configuration information for ETHERNET module\r
317   * @retval None\r
318   */\r
319 __weak void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)\r
320 {\r
321   /* NOTE : This function Should not be modified, when the callback is needed,\r
322   the HAL_ETH_MspInit could be implemented in the user file\r
323   */\r
324   ( void ) heth;\r
325 }\r
326 \r
327 /**\r
328   * @brief  DeInitializes ETH MSP.\r
329   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
330   *         the configuration information for ETHERNET module\r
331   * @retval None\r
332   */\r
333 __weak void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)\r
334 {\r
335   /* NOTE : This function Should not be modified, when the callback is needed,\r
336   the HAL_ETH_MspDeInit could be implemented in the user file\r
337   */\r
338   ( void ) heth;\r
339 }\r
340 \r
341 /**\r
342   * @}\r
343   */\r
344 \r
345 /** @defgroup ETH_Exported_Functions_Group2 IO operation functions\r
346   *  @brief   Data transfers functions\r
347   *\r
348   @verbatim\r
349   ==============================================================================\r
350                           ##### IO operation functions #####\r
351   ==============================================================================\r
352   [..]  This section provides functions allowing to:\r
353         (+) Transmit a frame\r
354             HAL_ETH_TransmitFrame();\r
355         (+) Receive a frame\r
356             HAL_ETH_GetReceivedFrame();\r
357             HAL_ETH_GetReceivedFrame_IT();\r
358         (+) Read from an External PHY register\r
359             HAL_ETH_ReadPHYRegister();\r
360         (+) Write to an External PHY register\r
361             HAL_ETH_WritePHYRegister();\r
362 \r
363   @endverbatim\r
364 \r
365   * @{\r
366   */\r
367 \r
368 #define ETH_DMA_ALL_INTS \\r
369         ( ETH_DMA_IT_TST | ETH_DMA_IT_PMT | ETH_DMA_IT_MMC | ETH_DMA_IT_NIS | ETH_DMA_IT_AIS | ETH_DMA_IT_ER | \\r
370         ETH_DMA_IT_FBE | ETH_DMA_IT_ET | ETH_DMA_IT_RWT | ETH_DMA_IT_RPS | ETH_DMA_IT_RBU | ETH_DMA_IT_R | \\r
371         ETH_DMA_IT_TU | ETH_DMA_IT_RO | ETH_DMA_IT_TJT | ETH_DMA_IT_TPS | ETH_DMA_IT_T )\r
372 \r
373 //#define ETH_DMA_ALL_INTS              ETH_DMA_IT_RBU | ETH_DMA_FLAG_T | ETH_DMA_FLAG_AIS\r
374 \r
375 #define INT_MASK                ( ( uint32_t ) ~ ( ETH_DMA_IT_TBU ) )\r
376 void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth)\r
377 {\r
378         uint32_t dmasr;\r
379 \r
380         dmasr = heth->Instance->DMASR & ETH_DMA_ALL_INTS;\r
381         heth->Instance->DMASR = dmasr;\r
382 \r
383         /* Frame received */\r
384         if( ( dmasr & ( ETH_DMA_FLAG_R | ETH_DMA_IT_RBU ) ) != 0 )\r
385         {\r
386                 /* Receive complete callback */\r
387                 HAL_ETH_RxCpltCallback( heth );\r
388         }\r
389         /* Frame transmitted */\r
390         if( ( dmasr & ( ETH_DMA_FLAG_T ) ) != 0 )\r
391         {\r
392                 /* Transfer complete callback */\r
393                 HAL_ETH_TxCpltCallback( heth );\r
394         }\r
395 \r
396         /* ETH DMA Error */\r
397         if( ( dmasr & ( ETH_DMA_FLAG_AIS ) ) != 0 )\r
398         {\r
399                 /* Ethernet Error callback */\r
400                 HAL_ETH_ErrorCallback( heth );\r
401         }\r
402 }\r
403 \r
404 /**\r
405   * @brief  Tx Transfer completed callbacks.\r
406   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
407   *         the configuration information for ETHERNET module\r
408   * @retval None\r
409   */\r
410 __weak void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)\r
411 {\r
412   /* NOTE : This function Should not be modified, when the callback is needed,\r
413   the HAL_ETH_TxCpltCallback could be implemented in the user file\r
414   */\r
415   ( void ) heth;\r
416 }\r
417 \r
418 /**\r
419   * @brief  Rx Transfer completed callbacks.\r
420   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
421   *         the configuration information for ETHERNET module\r
422   * @retval None\r
423   */\r
424 __weak void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)\r
425 {\r
426   /* NOTE : This function Should not be modified, when the callback is needed,\r
427   the HAL_ETH_TxCpltCallback could be implemented in the user file\r
428   */\r
429   ( void ) heth;\r
430 }\r
431 \r
432 /**\r
433   * @brief  Ethernet transfer error callbacks\r
434   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
435   *         the configuration information for ETHERNET module\r
436   * @retval None\r
437   */\r
438 __weak void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)\r
439 {\r
440   /* NOTE : This function Should not be modified, when the callback is needed,\r
441   the HAL_ETH_TxCpltCallback could be implemented in the user file\r
442   */\r
443   ( void ) heth;\r
444 }\r
445 \r
446 /**\r
447   * @brief  Reads a PHY register\r
448   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
449   *         the configuration information for ETHERNET module\r
450   * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.\r
451   *                This parameter can be one of the following values:\r
452   *                   PHY_BCR: Transceiver Basic Control Register,\r
453   *                   PHY_BSR: Transceiver Basic Status Register.\r
454   *                   More PHY register could be read depending on the used PHY\r
455   * @param RegValue: PHY register value\r
456   * @retval HAL status\r
457   */\r
458 HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t *RegValue)\r
459 {\r
460 uint32_t tmpreg = 0uL;\r
461 uint32_t tickstart = 0uL;\r
462 HAL_StatusTypeDef xResult;\r
463 \r
464         /* Check parameters */\r
465         assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));\r
466 \r
467         /* Check the ETH peripheral state */\r
468         if( heth->State == HAL_ETH_STATE_BUSY_RD )\r
469         {\r
470                 xResult = HAL_BUSY;\r
471         }\r
472         else\r
473         {\r
474                 __HAL_LOCK( heth );\r
475 \r
476                 /* Set ETH HAL State to BUSY_RD */\r
477                 heth->State = HAL_ETH_STATE_BUSY_RD;\r
478 \r
479                 /* Get the ETHERNET MACMIIAR value */\r
480                 tmpreg = heth->Instance->MACMIIAR;\r
481 \r
482                 /* Keep only the CSR Clock Range CR[2:0] bits value */\r
483                 tmpreg &= ~ETH_MACMIIAR_CR_MASK;\r
484 \r
485                 /* Prepare the MII address register value */\r
486                 tmpreg |= ( ( ( uint32_t )heth->Init.PhyAddress << 11) & ETH_MACMIIAR_PA );    /* Set the PHY device address   */\r
487                 tmpreg |= ( ( ( uint32_t )PHYReg << 6 ) & ETH_MACMIIAR_MR );                   /* Set the PHY register address */\r
488                 tmpreg &= ~ETH_MACMIIAR_MW;                                           /* Set the read mode            */\r
489                 tmpreg |= ETH_MACMIIAR_MB;                                            /* Set the MII Busy bit         */\r
490 \r
491                 /* Write the result value into the MII Address register */\r
492                 heth->Instance->MACMIIAR = tmpreg;\r
493 \r
494                 /* Get tick */\r
495                 tickstart = HAL_GetTick();\r
496 \r
497                 /* Check for the Busy flag */\r
498                 while( 1 )\r
499                 {\r
500                         tmpreg = heth->Instance->MACMIIAR;\r
501 \r
502                         if( ( tmpreg & ETH_MACMIIAR_MB ) == 0uL )\r
503                         {\r
504                                 /* Get MACMIIDR value */\r
505                                 *RegValue = ( uint32_t ) heth->Instance->MACMIIDR;\r
506                                 xResult = HAL_OK;\r
507                                 break;\r
508                         }\r
509                         /* Check for the Timeout */\r
510                         if( ( HAL_GetTick( ) - tickstart ) > PHY_READ_TO )\r
511                         {\r
512                                 xResult = HAL_TIMEOUT;\r
513                                 break;\r
514                         }\r
515 \r
516                 }\r
517 \r
518                 /* Set ETH HAL State to READY */\r
519                 heth->State = HAL_ETH_STATE_READY;\r
520 \r
521                 /* Process Unlocked */\r
522                 __HAL_UNLOCK( heth );\r
523         }\r
524 \r
525         /* Return function status */\r
526         return xResult;\r
527 }\r
528 \r
529 /**\r
530   * @brief  Writes to a PHY register.\r
531   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
532   *         the configuration information for ETHERNET module\r
533   * @param  PHYReg: PHY register address, is the index of one of the 32 PHY register.\r
534   *          This parameter can be one of the following values:\r
535   *             PHY_BCR: Transceiver Control Register.\r
536   *             More PHY register could be written depending on the used PHY\r
537   * @param  RegValue: the value to write\r
538   * @retval HAL status\r
539   */\r
540 HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t RegValue)\r
541 {\r
542 uint32_t tmpreg = 0;\r
543 uint32_t tickstart = 0;\r
544 HAL_StatusTypeDef xResult;\r
545 \r
546         /* Check parameters */\r
547         assert_param( IS_ETH_PHY_ADDRESS( heth->Init.PhyAddress ) );\r
548 \r
549         /* Check the ETH peripheral state */\r
550         if( heth->State == HAL_ETH_STATE_BUSY_WR )\r
551         {\r
552                 xResult = HAL_BUSY;\r
553         }\r
554         else\r
555         {\r
556                 __HAL_LOCK( heth );\r
557 \r
558                 /* Set ETH HAL State to BUSY_WR */\r
559                 heth->State = HAL_ETH_STATE_BUSY_WR;\r
560 \r
561                 /* Get the ETHERNET MACMIIAR value */\r
562                 tmpreg = heth->Instance->MACMIIAR;\r
563 \r
564                 /* Keep only the CSR Clock Range CR[2:0] bits value */\r
565                 tmpreg &= ~ETH_MACMIIAR_CR_MASK;\r
566 \r
567                 /* Prepare the MII register address value */\r
568                 tmpreg |= ( ( ( uint32_t ) heth->Init.PhyAddress << 11 ) & ETH_MACMIIAR_PA ); /* Set the PHY device address */\r
569                 tmpreg |= ( ( ( uint32_t ) PHYReg << 6 ) & ETH_MACMIIAR_MR );                 /* Set the PHY register address */\r
570                 tmpreg |= ETH_MACMIIAR_MW;                                          /* Set the write mode */\r
571                 tmpreg |= ETH_MACMIIAR_MB;                                          /* Set the MII Busy bit */\r
572 \r
573                 /* Give the value to the MII data register */\r
574                 heth->Instance->MACMIIDR = ( uint16_t ) RegValue;\r
575 \r
576                 /* Write the result value into the MII Address register */\r
577                 heth->Instance->MACMIIAR = tmpreg;\r
578 \r
579                 /* Get tick */\r
580                 tickstart = HAL_GetTick();\r
581 \r
582                 /* Check for the Busy flag */\r
583                 while( 1 )\r
584                 {\r
585                         tmpreg = heth->Instance->MACMIIAR;\r
586 \r
587                         if( ( tmpreg & ETH_MACMIIAR_MB ) == 0ul )\r
588                         {\r
589                                 xResult = HAL_OK;\r
590                                 break;\r
591                         }\r
592                         /* Check for the Timeout */\r
593                         if( ( HAL_GetTick( ) - tickstart ) > PHY_WRITE_TO )\r
594                         {\r
595                                 xResult = HAL_TIMEOUT;\r
596                                 break;\r
597                         }\r
598                 }\r
599 \r
600                 /* Set ETH HAL State to READY */\r
601                 heth->State = HAL_ETH_STATE_READY;\r
602                 /* Process Unlocked */\r
603                 __HAL_UNLOCK( heth );\r
604         }\r
605 \r
606         /* Return function status */\r
607         return xResult;\r
608 }\r
609 \r
610 /**\r
611   * @}\r
612   */\r
613 \r
614 /** @defgroup ETH_Exported_Functions_Group3 Peripheral Control functions\r
615  *  @brief    Peripheral Control functions\r
616  *\r
617 @verbatim\r
618  ===============================================================================\r
619                   ##### Peripheral Control functions #####\r
620  ===============================================================================\r
621     [..]  This section provides functions allowing to:\r
622       (+) Enable MAC and DMA transmission and reception.\r
623           HAL_ETH_Start();\r
624       (+) Disable MAC and DMA transmission and reception.\r
625           HAL_ETH_Stop();\r
626       (+) Set the MAC configuration in runtime mode\r
627           HAL_ETH_ConfigMAC();\r
628       (+) Set the DMA configuration in runtime mode\r
629           HAL_ETH_ConfigDMA();\r
630 \r
631 @endverbatim\r
632   * @{\r
633   */\r
634 \r
635  /**\r
636   * @brief  Enables Ethernet MAC and DMA reception/transmission\r
637   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
638   *         the configuration information for ETHERNET module\r
639   * @retval HAL status\r
640   */\r
641 HAL_StatusTypeDef HAL_ETH_Start( ETH_HandleTypeDef *heth )\r
642 {\r
643         /* Process Locked */\r
644         __HAL_LOCK( heth );\r
645 \r
646         /* Set the ETH peripheral state to BUSY */\r
647         heth->State = HAL_ETH_STATE_BUSY;\r
648 \r
649         /* Enable transmit state machine of the MAC for transmission on the MII */\r
650         ETH_MACTransmissionEnable( heth );\r
651 \r
652         /* Enable receive state machine of the MAC for reception from the MII */\r
653         ETH_MACReceptionEnable( heth );\r
654 \r
655         /* Flush Transmit FIFO */\r
656         ETH_FlushTransmitFIFO( heth );\r
657 \r
658         /* Start DMA transmission */\r
659         ETH_DMATransmissionEnable( heth );\r
660 \r
661         /* Start DMA reception */\r
662         ETH_DMAReceptionEnable( heth );\r
663 \r
664         /* Set the ETH state to READY*/\r
665         heth->State= HAL_ETH_STATE_READY;\r
666 \r
667         /* Process Unlocked */\r
668         __HAL_UNLOCK( heth );\r
669 \r
670         /* Return function status */\r
671         return HAL_OK;\r
672 }\r
673 \r
674 /**\r
675   * @brief  Stop Ethernet MAC and DMA reception/transmission\r
676   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
677   *         the configuration information for ETHERNET module\r
678   * @retval HAL status\r
679   */\r
680 HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth)\r
681 {\r
682   /* Process Locked */\r
683   __HAL_LOCK( heth );\r
684 \r
685   /* Set the ETH peripheral state to BUSY */\r
686   heth->State = HAL_ETH_STATE_BUSY;\r
687 \r
688   /* Stop DMA transmission */\r
689   ETH_DMATransmissionDisable( heth );\r
690 \r
691   /* Stop DMA reception */\r
692   ETH_DMAReceptionDisable( heth );\r
693 \r
694   /* Disable receive state machine of the MAC for reception from the MII */\r
695   ETH_MACReceptionDisable( heth );\r
696 \r
697   /* Flush Transmit FIFO */\r
698   ETH_FlushTransmitFIFO( heth );\r
699 \r
700   /* Disable transmit state machine of the MAC for transmission on the MII */\r
701   ETH_MACTransmissionDisable( heth );\r
702 \r
703   /* Set the ETH state*/\r
704   heth->State = HAL_ETH_STATE_READY;\r
705 \r
706   /* Process Unlocked */\r
707   __HAL_UNLOCK( heth );\r
708 \r
709   /* Return function status */\r
710   return HAL_OK;\r
711 }\r
712 \r
713 static void vRegisterDelay()\r
714 {\r
715 uint32_t uxCount;\r
716         /*\r
717          * Regarding the HAL delay functions, I noticed that HAL delay is being used to workaround the\r
718          * "Successive write operations to the same register might not be fully taken into account" errata.\r
719          * The workaround requires a delay of four TX_CLK/RX_CLK clock cycles. For a 10 Mbit connection,\r
720          * these clocks are running at 2.5 MHz, so this delay would be at most 1.6 microseconds.\r
721          * 180 Mhz = 288 loops\r
722          * 168 Mhz = 269 loops\r
723          * 100 Mhz = 160 loops\r
724          *  84 Mhz = 134 loops\r
725          */\r
726         #define WAIT_TIME_NS    1600uL                  /* 1.6 microseconds */\r
727         #define CPU_MAX_FREQ    SystemCoreClock /* 84, 100, 168 or 180 MHz */\r
728         uint32_t NOP_COUNT = ( WAIT_TIME_NS * ( CPU_MAX_FREQ / 1000uL ) ) / 1000000uL;\r
729         for( uxCount = NOP_COUNT; uxCount > 0uL; uxCount-- )\r
730         {\r
731                 __NOP();\r
732         }\r
733 }\r
734 \r
735 static void prvWriteMACFCR( ETH_HandleTypeDef *heth, uint32_t ulValue)\r
736 {\r
737         /* Enable the MAC transmission */\r
738         heth->Instance->MACFCR = ulValue;\r
739 \r
740         /* Wait until the write operation will be taken into account:\r
741         at least four TX_CLK/RX_CLK clock cycles.\r
742         Read it back, wait a ms and */\r
743         ( void ) heth->Instance->MACFCR;\r
744 \r
745         vRegisterDelay();\r
746 \r
747         heth->Instance->MACFCR = ulValue;\r
748 }\r
749 \r
750 static void prvWriteDMAOMR( ETH_HandleTypeDef *heth, uint32_t ulValue)\r
751 {\r
752         /* Enable the MAC transmission */\r
753         heth->Instance->DMAOMR = ulValue;\r
754 \r
755         /* Wait until the write operation will be taken into account:\r
756         at least four TX_CLK/RX_CLK clock cycles.\r
757         Read it back, wait a ms and */\r
758         ( void ) heth->Instance->DMAOMR;\r
759 \r
760         vRegisterDelay();\r
761 \r
762         heth->Instance->DMAOMR = ulValue;\r
763 }\r
764 \r
765 static void prvWriteMACCR( ETH_HandleTypeDef *heth, uint32_t ulValue)\r
766 {\r
767         /* Enable the MAC transmission */\r
768         heth->Instance->MACCR = ulValue;\r
769 \r
770         /* Wait until the write operation will be taken into account:\r
771         at least four TX_CLK/RX_CLK clock cycles.\r
772         Read it back, wait a ms and */\r
773         ( void ) heth->Instance->MACCR;\r
774 \r
775         vRegisterDelay();\r
776 \r
777         heth->Instance->MACCR = ulValue;\r
778 }\r
779 \r
780 /**\r
781   * @brief  Set ETH MAC Configuration.\r
782   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
783   *         the configuration information for ETHERNET module\r
784   * @param  macconf: MAC Configuration structure\r
785   * @retval HAL status\r
786   */\r
787 HAL_StatusTypeDef HAL_ETH_ConfigMAC(ETH_HandleTypeDef *heth, ETH_MACInitTypeDef *macconf)\r
788 {\r
789         uint32_t tmpreg = 0uL;\r
790 \r
791         /* Process Locked */\r
792         __HAL_LOCK( heth );\r
793 \r
794         /* Set the ETH peripheral state to BUSY */\r
795         heth->State= HAL_ETH_STATE_BUSY;\r
796 \r
797         assert_param(IS_ETH_SPEED(heth->Init.Speed));\r
798         assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode));\r
799 \r
800         if (macconf != NULL)\r
801         {\r
802                 /* Check the parameters */\r
803                 assert_param(IS_ETH_WATCHDOG(macconf->Watchdog));\r
804                 assert_param(IS_ETH_JABBER(macconf->Jabber));\r
805                 assert_param(IS_ETH_INTER_FRAME_GAP(macconf->InterFrameGap));\r
806                 assert_param(IS_ETH_CARRIER_SENSE(macconf->CarrierSense));\r
807                 assert_param(IS_ETH_RECEIVE_OWN(macconf->ReceiveOwn));\r
808                 assert_param(IS_ETH_LOOPBACK_MODE(macconf->LoopbackMode));\r
809                 assert_param(IS_ETH_CHECKSUM_OFFLOAD(macconf->ChecksumOffload));\r
810                 assert_param(IS_ETH_RETRY_TRANSMISSION(macconf->RetryTransmission));\r
811                 assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(macconf->AutomaticPadCRCStrip));\r
812                 assert_param(IS_ETH_BACKOFF_LIMIT(macconf->BackOffLimit));\r
813                 assert_param(IS_ETH_DEFERRAL_CHECK(macconf->DeferralCheck));\r
814                 assert_param(IS_ETH_RECEIVE_ALL(macconf->ReceiveAll));\r
815                 assert_param(IS_ETH_SOURCE_ADDR_FILTER(macconf->SourceAddrFilter));\r
816                 assert_param(IS_ETH_CONTROL_FRAMES(macconf->PassControlFrames));\r
817                 assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(macconf->BroadcastFramesReception));\r
818                 assert_param(IS_ETH_DESTINATION_ADDR_FILTER(macconf->DestinationAddrFilter));\r
819                 assert_param(IS_ETH_PROMISCUOUS_MODE(macconf->PromiscuousMode));\r
820                 assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(macconf->MulticastFramesFilter));\r
821                 assert_param(IS_ETH_UNICAST_FRAMES_FILTER(macconf->UnicastFramesFilter));\r
822                 assert_param(IS_ETH_PAUSE_TIME(macconf->PauseTime));\r
823                 assert_param(IS_ETH_ZEROQUANTA_PAUSE(macconf->ZeroQuantaPause));\r
824                 assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(macconf->PauseLowThreshold));\r
825                 assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(macconf->UnicastPauseFrameDetect));\r
826                 assert_param(IS_ETH_RECEIVE_FLOWCONTROL(macconf->ReceiveFlowControl));\r
827                 assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(macconf->TransmitFlowControl));\r
828                 assert_param(IS_ETH_VLAN_TAG_COMPARISON(macconf->VLANTagComparison));\r
829                 assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(macconf->VLANTagIdentifier));\r
830 \r
831                 /*------------------------ ETHERNET MACCR Configuration --------------------*/\r
832                 /* Get the ETHERNET MACCR value */\r
833                 tmpreg = heth->Instance->MACCR;\r
834                 /* Clear WD, PCE, PS, TE and RE bits */\r
835                 tmpreg &= ETH_MACCR_CLEAR_MASK;\r
836 \r
837                 tmpreg |= (uint32_t)(\r
838                         macconf->Watchdog |\r
839                         macconf->Jabber |\r
840                         macconf->InterFrameGap |\r
841                         macconf->CarrierSense |\r
842                         heth->Init.Speed |\r
843                         macconf->ReceiveOwn |\r
844                         macconf->LoopbackMode |\r
845                         heth->Init.DuplexMode |\r
846                         macconf->ChecksumOffload |\r
847                         macconf->RetryTransmission |\r
848                         macconf->AutomaticPadCRCStrip |\r
849                         macconf->BackOffLimit |\r
850                         macconf->DeferralCheck);\r
851 \r
852                 /* Write to ETHERNET MACCR */\r
853                 prvWriteMACCR( heth, tmpreg );\r
854 \r
855                 /*----------------------- ETHERNET MACFFR Configuration --------------------*/\r
856                 /* Write to ETHERNET MACFFR */\r
857                 heth->Instance->MACFFR = (uint32_t)(\r
858                         macconf->ReceiveAll |\r
859                         macconf->SourceAddrFilter |\r
860                         macconf->PassControlFrames |\r
861                         macconf->BroadcastFramesReception |\r
862                         macconf->DestinationAddrFilter |\r
863                         macconf->PromiscuousMode |\r
864                         macconf->MulticastFramesFilter |\r
865                         macconf->UnicastFramesFilter);\r
866 \r
867                 /* Wait until the write operation will be taken into account :\r
868                 at least four TX_CLK/RX_CLK clock cycles */\r
869                 tmpreg = heth->Instance->MACFFR;\r
870                 vRegisterDelay();\r
871                 heth->Instance->MACFFR = tmpreg;\r
872 \r
873                 /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/\r
874                 /* Write to ETHERNET MACHTHR */\r
875                 heth->Instance->MACHTHR = (uint32_t)macconf->HashTableHigh;\r
876 \r
877                 /* Write to ETHERNET MACHTLR */\r
878                 heth->Instance->MACHTLR = (uint32_t)macconf->HashTableLow;\r
879                 /*----------------------- ETHERNET MACFCR Configuration --------------------*/\r
880 \r
881                 /* Get the ETHERNET MACFCR value */\r
882                 tmpreg = heth->Instance->MACFCR;\r
883                 /* Clear xx bits */\r
884                 tmpreg &= ETH_MACFCR_CLEAR_MASK;\r
885 \r
886                 tmpreg |= (uint32_t)((\r
887                         macconf->PauseTime << 16) |\r
888                         macconf->ZeroQuantaPause |\r
889                         macconf->PauseLowThreshold |\r
890                         macconf->UnicastPauseFrameDetect |\r
891                         macconf->ReceiveFlowControl |\r
892                         macconf->TransmitFlowControl);\r
893 \r
894                 /* Write to ETHERNET MACFCR */\r
895                 prvWriteMACFCR( heth, tmpreg );\r
896 \r
897                 /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/\r
898                 heth->Instance->MACVLANTR = (uint32_t)(macconf->VLANTagComparison |\r
899                 macconf->VLANTagIdentifier);\r
900 \r
901                 /* Wait until the write operation will be taken into account :\r
902                 at least four TX_CLK/RX_CLK clock cycles */\r
903                 tmpreg = heth->Instance->MACVLANTR;\r
904                 vRegisterDelay();\r
905                 heth->Instance->MACVLANTR = tmpreg;\r
906         }\r
907         else /* macconf == NULL : here we just configure Speed and Duplex mode */\r
908         {\r
909                 /*------------------------ ETHERNET MACCR Configuration --------------------*/\r
910                 /* Get the ETHERNET MACCR value */\r
911                 tmpreg = heth->Instance->MACCR;\r
912 \r
913                 /* Clear FES and DM bits */\r
914                 tmpreg &= ~( ( uint32_t ) 0x00004800uL );\r
915 \r
916                 tmpreg |= (uint32_t)(heth->Init.Speed | heth->Init.DuplexMode);\r
917 \r
918                 /* Write to ETHERNET MACCR */\r
919                 prvWriteMACCR( heth, tmpreg );\r
920         }\r
921 \r
922         /* Set the ETH state to Ready */\r
923         heth->State= HAL_ETH_STATE_READY;\r
924 \r
925         /* Process Unlocked */\r
926         __HAL_UNLOCK( heth );\r
927 \r
928         /* Return function status */\r
929         return HAL_OK;\r
930 }\r
931 \r
932 /**\r
933   * @brief  Sets ETH DMA Configuration.\r
934   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
935   *         the configuration information for ETHERNET module\r
936   * @param  dmaconf: DMA Configuration structure\r
937   * @retval HAL status\r
938   */\r
939 HAL_StatusTypeDef HAL_ETH_ConfigDMA(ETH_HandleTypeDef *heth, ETH_DMAInitTypeDef *dmaconf)\r
940 {\r
941         uint32_t tmpreg = 0uL;\r
942 \r
943         /* Process Locked */\r
944         __HAL_LOCK( heth );\r
945 \r
946         /* Set the ETH peripheral state to BUSY */\r
947         heth->State= HAL_ETH_STATE_BUSY;\r
948 \r
949         /* Check parameters */\r
950         assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(dmaconf->DropTCPIPChecksumErrorFrame));\r
951         assert_param(IS_ETH_RECEIVE_STORE_FORWARD(dmaconf->ReceiveStoreForward));\r
952         assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(dmaconf->FlushReceivedFrame));\r
953         assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(dmaconf->TransmitStoreForward));\r
954         assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(dmaconf->TransmitThresholdControl));\r
955         assert_param(IS_ETH_FORWARD_ERROR_FRAMES(dmaconf->ForwardErrorFrames));\r
956         assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(dmaconf->ForwardUndersizedGoodFrames));\r
957         assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(dmaconf->ReceiveThresholdControl));\r
958         assert_param(IS_ETH_SECOND_FRAME_OPERATE(dmaconf->SecondFrameOperate));\r
959         assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(dmaconf->AddressAlignedBeats));\r
960         assert_param(IS_ETH_FIXED_BURST(dmaconf->FixedBurst));\r
961         assert_param(IS_ETH_RXDMA_BURST_LENGTH(dmaconf->RxDMABurstLength));\r
962         assert_param(IS_ETH_TXDMA_BURST_LENGTH(dmaconf->TxDMABurstLength));\r
963         assert_param(IS_ETH_ENHANCED_DESCRIPTOR_FORMAT(dmaconf->EnhancedDescriptorFormat));\r
964         assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(dmaconf->DescriptorSkipLength));\r
965         assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(dmaconf->DMAArbitration));\r
966 \r
967         /*----------------------- ETHERNET DMAOMR Configuration --------------------*/\r
968         /* Get the ETHERNET DMAOMR value */\r
969         tmpreg = heth->Instance->DMAOMR;\r
970         /* Clear xx bits */\r
971         tmpreg &= ETH_DMAOMR_CLEAR_MASK;\r
972 \r
973         tmpreg |= (uint32_t)(\r
974                 dmaconf->DropTCPIPChecksumErrorFrame |\r
975                 dmaconf->ReceiveStoreForward |\r
976                 dmaconf->FlushReceivedFrame |\r
977                 dmaconf->TransmitStoreForward |\r
978                 dmaconf->TransmitThresholdControl |\r
979                 dmaconf->ForwardErrorFrames |\r
980                 dmaconf->ForwardUndersizedGoodFrames |\r
981                 dmaconf->ReceiveThresholdControl |\r
982                 dmaconf->SecondFrameOperate);\r
983 \r
984         /* Write to ETHERNET DMAOMR */\r
985         prvWriteDMAOMR( heth, tmpreg );\r
986 \r
987         /*----------------------- ETHERNET DMABMR Configuration --------------------*/\r
988         heth->Instance->DMABMR = (uint32_t)(dmaconf->AddressAlignedBeats |\r
989         dmaconf->FixedBurst |\r
990         dmaconf->RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */\r
991         dmaconf->TxDMABurstLength |\r
992         dmaconf->EnhancedDescriptorFormat |\r
993         (dmaconf->DescriptorSkipLength << 2) |\r
994         dmaconf->DMAArbitration |\r
995         ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */\r
996 \r
997         /* Wait until the write operation will be taken into account:\r
998         at least four TX_CLK/RX_CLK clock cycles */\r
999         tmpreg = heth->Instance->DMABMR;\r
1000         vRegisterDelay();\r
1001         heth->Instance->DMABMR = tmpreg;\r
1002 \r
1003         /* Set the ETH state to Ready */\r
1004         heth->State= HAL_ETH_STATE_READY;\r
1005 \r
1006         /* Process Unlocked */\r
1007         __HAL_UNLOCK( heth );\r
1008 \r
1009         /* Return function status */\r
1010         return HAL_OK;\r
1011 }\r
1012 \r
1013 /**\r
1014   * @}\r
1015   */\r
1016 \r
1017 /** @defgroup ETH_Exported_Functions_Group4 Peripheral State functions\r
1018   *  @brief   Peripheral State functions\r
1019   *\r
1020   @verbatim\r
1021   ===============================================================================\r
1022                          ##### Peripheral State functions #####\r
1023   ===============================================================================\r
1024   [..]\r
1025   This subsection permits to get in run-time the status of the peripheral\r
1026   and the data flow.\r
1027        (+) Get the ETH handle state:\r
1028            HAL_ETH_GetState();\r
1029 \r
1030 \r
1031   @endverbatim\r
1032   * @{\r
1033   */\r
1034 \r
1035 /**\r
1036   * @brief  Return the ETH HAL state\r
1037   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1038   *         the configuration information for ETHERNET module\r
1039   * @retval HAL state\r
1040   */\r
1041 HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth)\r
1042 {\r
1043   /* Return ETH state */\r
1044   return heth->State;\r
1045 }\r
1046 \r
1047 /**\r
1048   * @}\r
1049   */\r
1050 \r
1051 /**\r
1052   * @}\r
1053   */\r
1054 \r
1055 /** @addtogroup ETH_Private_Functions\r
1056   * @{\r
1057   */\r
1058 \r
1059 /**\r
1060   * @brief  Configures Ethernet MAC and DMA with default parameters.\r
1061   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1062   *         the configuration information for ETHERNET module\r
1063   * @param  err: Ethernet Init error\r
1064   * @retval HAL status\r
1065   */\r
1066 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err)\r
1067 {\r
1068   ETH_MACInitTypeDef macinit;\r
1069   ETH_DMAInitTypeDef dmainit;\r
1070   uint32_t tmpreg = 0uL;\r
1071 \r
1072   if (err != ETH_SUCCESS) /* Auto-negotiation failed */\r
1073   {\r
1074     /* Set Ethernet duplex mode to Full-duplex */\r
1075     heth->Init.DuplexMode = ETH_MODE_FULLDUPLEX;\r
1076 \r
1077     /* Set Ethernet speed to 100M */\r
1078     heth->Init.Speed = ETH_SPEED_100M;\r
1079   }\r
1080 \r
1081   /* Ethernet MAC default initialization **************************************/\r
1082   macinit.Watchdog = ETH_WATCHDOG_ENABLE;\r
1083   macinit.Jabber = ETH_JABBER_ENABLE;\r
1084   macinit.InterFrameGap = ETH_INTERFRAMEGAP_96BIT;\r
1085   macinit.CarrierSense = ETH_CARRIERSENCE_ENABLE;\r
1086   macinit.ReceiveOwn = ETH_RECEIVEOWN_ENABLE;\r
1087   macinit.LoopbackMode = ETH_LOOPBACKMODE_DISABLE;\r
1088   if(heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)\r
1089   {\r
1090     macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;\r
1091   }\r
1092   else\r
1093   {\r
1094     macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;\r
1095   }\r
1096   macinit.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE;\r
1097   macinit.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE;\r
1098   macinit.BackOffLimit = ETH_BACKOFFLIMIT_10;\r
1099   macinit.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE;\r
1100   macinit.ReceiveAll = ETH_RECEIVEAll_DISABLE;\r
1101   macinit.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE;\r
1102   macinit.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL;\r
1103   macinit.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE;\r
1104   macinit.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL;\r
1105   macinit.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE;\r
1106   macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;\r
1107   macinit.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT;\r
1108   macinit.HashTableHigh = 0x0uL;\r
1109   macinit.HashTableLow = 0x0uL;\r
1110   macinit.PauseTime = 0x0uL;\r
1111   macinit.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE;\r
1112   macinit.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;\r
1113   macinit.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE;\r
1114   macinit.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE;\r
1115   macinit.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE;\r
1116   macinit.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT;\r
1117   macinit.VLANTagIdentifier = 0x0uL;\r
1118 \r
1119   /*------------------------ ETHERNET MACCR Configuration --------------------*/\r
1120   /* Get the ETHERNET MACCR value */\r
1121   tmpreg = heth->Instance->MACCR;\r
1122   /* Clear WD, PCE, PS, TE and RE bits */\r
1123   tmpreg &= ETH_MACCR_CLEAR_MASK;\r
1124   /* Set the WD bit according to ETH Watchdog value */\r
1125   /* Set the JD: bit according to ETH Jabber value */\r
1126   /* Set the IFG bit according to ETH InterFrameGap value */\r
1127   /* Set the DCRS bit according to ETH CarrierSense value */\r
1128   /* Set the FES bit according to ETH Speed value */\r
1129   /* Set the DO bit according to ETH ReceiveOwn value */\r
1130   /* Set the LM bit according to ETH LoopbackMode value */\r
1131   /* Set the DM bit according to ETH Mode value */\r
1132   /* Set the IPCO bit according to ETH ChecksumOffload value */\r
1133   /* Set the DR bit according to ETH RetryTransmission value */\r
1134   /* Set the ACS bit according to ETH AutomaticPadCRCStrip value */\r
1135   /* Set the BL bit according to ETH BackOffLimit value */\r
1136   /* Set the DC bit according to ETH DeferralCheck value */\r
1137   tmpreg |= (uint32_t)(macinit.Watchdog |\r
1138                        macinit.Jabber |\r
1139                        macinit.InterFrameGap |\r
1140                        macinit.CarrierSense |\r
1141                        heth->Init.Speed |\r
1142                        macinit.ReceiveOwn |\r
1143                        macinit.LoopbackMode |\r
1144                        heth->Init.DuplexMode |\r
1145                        macinit.ChecksumOffload |\r
1146                        macinit.RetryTransmission |\r
1147                        macinit.AutomaticPadCRCStrip |\r
1148                        macinit.BackOffLimit |\r
1149                        macinit.DeferralCheck);\r
1150 \r
1151   /* Write to ETHERNET MACCR */\r
1152   prvWriteMACCR( heth, tmpreg );\r
1153 \r
1154   /*----------------------- ETHERNET MACFFR Configuration --------------------*/\r
1155   /* Set the RA bit according to ETH ReceiveAll value */\r
1156   /* Set the SAF and SAIF bits according to ETH SourceAddrFilter value */\r
1157   /* Set the PCF bit according to ETH PassControlFrames value */\r
1158   /* Set the DBF bit according to ETH BroadcastFramesReception value */\r
1159   /* Set the DAIF bit according to ETH DestinationAddrFilter value */\r
1160   /* Set the PR bit according to ETH PromiscuousMode value */\r
1161   /* Set the PM, HMC and HPF bits according to ETH MulticastFramesFilter value */\r
1162   /* Set the HUC and HPF bits according to ETH UnicastFramesFilter value */\r
1163   /* Write to ETHERNET MACFFR */\r
1164   heth->Instance->MACFFR = (uint32_t)(macinit.ReceiveAll |\r
1165                                         macinit.SourceAddrFilter |\r
1166                                         macinit.PassControlFrames |\r
1167                                         macinit.BroadcastFramesReception |\r
1168                                         macinit.DestinationAddrFilter |\r
1169                                         macinit.PromiscuousMode |\r
1170                                         macinit.MulticastFramesFilter |\r
1171                                         macinit.UnicastFramesFilter);\r
1172 \r
1173    /* Wait until the write operation will be taken into account:\r
1174       at least four TX_CLK/RX_CLK clock cycles */\r
1175    tmpreg = heth->Instance->MACFFR;\r
1176    vRegisterDelay();\r
1177    heth->Instance->MACFFR = tmpreg;\r
1178 \r
1179    /*--------------- ETHERNET MACHTHR and MACHTLR Configuration --------------*/\r
1180    /* Write to ETHERNET MACHTHR */\r
1181    heth->Instance->MACHTHR = (uint32_t)macinit.HashTableHigh;\r
1182 \r
1183    /* Write to ETHERNET MACHTLR */\r
1184    heth->Instance->MACHTLR = (uint32_t)macinit.HashTableLow;\r
1185    /*----------------------- ETHERNET MACFCR Configuration -------------------*/\r
1186 \r
1187    /* Get the ETHERNET MACFCR value */\r
1188    tmpreg = heth->Instance->MACFCR;\r
1189    /* Clear xx bits */\r
1190    tmpreg &= ETH_MACFCR_CLEAR_MASK;\r
1191 \r
1192    /* Set the PT bit according to ETH PauseTime value */\r
1193    /* Set the DZPQ bit according to ETH ZeroQuantaPause value */\r
1194    /* Set the PLT bit according to ETH PauseLowThreshold value */\r
1195    /* Set the UP bit according to ETH UnicastPauseFrameDetect value */\r
1196    /* Set the RFE bit according to ETH ReceiveFlowControl value */\r
1197    /* Set the TFE bit according to ETH TransmitFlowControl value */\r
1198    tmpreg |= (uint32_t)((macinit.PauseTime << 16) |\r
1199                         macinit.ZeroQuantaPause |\r
1200                         macinit.PauseLowThreshold |\r
1201                         macinit.UnicastPauseFrameDetect |\r
1202                         macinit.ReceiveFlowControl |\r
1203                         macinit.TransmitFlowControl);\r
1204 \r
1205    /* Write to ETHERNET MACFCR */\r
1206    prvWriteMACFCR( heth, tmpreg );\r
1207 \r
1208    /*----------------------- ETHERNET MACVLANTR Configuration ----------------*/\r
1209    /* Set the ETV bit according to ETH VLANTagComparison value */\r
1210    /* Set the VL bit according to ETH VLANTagIdentifier value */\r
1211    heth->Instance->MACVLANTR = (uint32_t)(macinit.VLANTagComparison |\r
1212                                             macinit.VLANTagIdentifier);\r
1213 \r
1214     /* Wait until the write operation will be taken into account:\r
1215        at least four TX_CLK/RX_CLK clock cycles */\r
1216     tmpreg = heth->Instance->MACVLANTR;\r
1217     vRegisterDelay();\r
1218     heth->Instance->MACVLANTR = tmpreg;\r
1219 \r
1220     /* Ethernet DMA default initialization ************************************/\r
1221     dmainit.DropTCPIPChecksumErrorFrame = ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE;\r
1222     dmainit.ReceiveStoreForward = ETH_RECEIVESTOREFORWARD_ENABLE;\r
1223     dmainit.FlushReceivedFrame = ETH_FLUSHRECEIVEDFRAME_ENABLE;\r
1224     dmainit.TransmitStoreForward = ETH_TRANSMITSTOREFORWARD_ENABLE;\r
1225     dmainit.TransmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;\r
1226     dmainit.ForwardErrorFrames = ETH_FORWARDERRORFRAMES_DISABLE;\r
1227     dmainit.ForwardUndersizedGoodFrames = ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE;\r
1228     dmainit.ReceiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;\r
1229     dmainit.SecondFrameOperate = ETH_SECONDFRAMEOPERARTE_ENABLE;\r
1230     dmainit.AddressAlignedBeats = ETH_ADDRESSALIGNEDBEATS_ENABLE;\r
1231     dmainit.FixedBurst = ETH_FIXEDBURST_ENABLE;\r
1232     dmainit.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;\r
1233     dmainit.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;\r
1234     dmainit.EnhancedDescriptorFormat = ETH_DMAENHANCEDDESCRIPTOR_ENABLE;\r
1235     dmainit.DescriptorSkipLength = 0x0uL;\r
1236     dmainit.DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;\r
1237 \r
1238     /* Get the ETHERNET DMAOMR value */\r
1239     tmpreg = heth->Instance->DMAOMR;\r
1240     /* Clear xx bits */\r
1241     tmpreg &= ETH_DMAOMR_CLEAR_MASK;\r
1242 \r
1243     /* Set the DT bit according to ETH DropTCPIPChecksumErrorFrame value */\r
1244     /* Set the RSF bit according to ETH ReceiveStoreForward value */\r
1245     /* Set the DFF bit according to ETH FlushReceivedFrame value */\r
1246     /* Set the TSF bit according to ETH TransmitStoreForward value */\r
1247     /* Set the TTC bit according to ETH TransmitThresholdControl value */\r
1248     /* Set the FEF bit according to ETH ForwardErrorFrames value */\r
1249     /* Set the FUF bit according to ETH ForwardUndersizedGoodFrames value */\r
1250     /* Set the RTC bit according to ETH ReceiveThresholdControl value */\r
1251     /* Set the OSF bit according to ETH SecondFrameOperate value */\r
1252     tmpreg |= (uint32_t)(dmainit.DropTCPIPChecksumErrorFrame |\r
1253                          dmainit.ReceiveStoreForward |\r
1254                          dmainit.FlushReceivedFrame |\r
1255                          dmainit.TransmitStoreForward |\r
1256                          dmainit.TransmitThresholdControl |\r
1257                          dmainit.ForwardErrorFrames |\r
1258                          dmainit.ForwardUndersizedGoodFrames |\r
1259                          dmainit.ReceiveThresholdControl |\r
1260                          dmainit.SecondFrameOperate);\r
1261 \r
1262     /* Write to ETHERNET DMAOMR */\r
1263     prvWriteDMAOMR( heth, tmpreg );\r
1264 \r
1265     /*----------------------- ETHERNET DMABMR Configuration ------------------*/\r
1266     /* Set the AAL bit according to ETH AddressAlignedBeats value */\r
1267     /* Set the FB bit according to ETH FixedBurst value */\r
1268     /* Set the RPBL and 4*PBL bits according to ETH RxDMABurstLength value */\r
1269     /* Set the PBL and 4*PBL bits according to ETH TxDMABurstLength value */\r
1270     /* Set the Enhanced DMA descriptors bit according to ETH EnhancedDescriptorFormat value*/\r
1271     /* Set the DSL bit according to ETH DesciptorSkipLength value */\r
1272     /* Set the PR and DA bits according to ETH DMAArbitration value */\r
1273     heth->Instance->DMABMR = (uint32_t)(dmainit.AddressAlignedBeats |\r
1274                                           dmainit.FixedBurst |\r
1275                                           dmainit.RxDMABurstLength |    /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */\r
1276                                           dmainit.TxDMABurstLength |\r
1277                                           dmainit.EnhancedDescriptorFormat |\r
1278                                           (dmainit.DescriptorSkipLength << 2) |\r
1279                                           dmainit.DMAArbitration |\r
1280                                           ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */\r
1281 \r
1282      /* Wait until the write operation will be taken into account:\r
1283         at least four TX_CLK/RX_CLK clock cycles */\r
1284      tmpreg = heth->Instance->DMABMR;\r
1285      vRegisterDelay();\r
1286      heth->Instance->DMABMR = tmpreg;\r
1287 \r
1288      if(heth->Init.RxMode == ETH_RXINTERRUPT_MODE)\r
1289      {\r
1290        /* Enable the Ethernet Rx Interrupt */\r
1291        __HAL_ETH_DMA_ENABLE_IT(( heth ), ETH_DMA_IT_NIS | ETH_DMA_IT_R);\r
1292      }\r
1293 \r
1294      /* Initialize MAC address in ethernet MAC */\r
1295      ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr);\r
1296 }\r
1297 \r
1298 /**\r
1299   * @brief  Configures the selected MAC address.\r
1300   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1301   *         the configuration information for ETHERNET module\r
1302   * @param  MacAddr: The MAC address to configure\r
1303   *          This parameter can be one of the following values:\r
1304   *             @arg ETH_MAC_Address0: MAC Address0\r
1305   *             @arg ETH_MAC_Address1: MAC Address1\r
1306   *             @arg ETH_MAC_Address2: MAC Address2\r
1307   *             @arg ETH_MAC_Address3: MAC Address3\r
1308   * @param  Addr: Pointer to MAC address buffer data (6 bytes)\r
1309   * @retval HAL status\r
1310   */\r
1311 static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr)\r
1312 {\r
1313         uint32_t tmpreg;\r
1314 \r
1315         ( void ) heth;\r
1316 \r
1317         /* Check the parameters */\r
1318         assert_param( IS_ETH_MAC_ADDRESS0123( MacAddr ) );\r
1319 \r
1320         /* Calculate the selected MAC address high register */\r
1321         /* Register ETH_MACA0HR: Bit 31 MO: Always 1. */\r
1322         tmpreg = 0x80000000uL | ( ( uint32_t )Addr[ 5 ] << 8) | (uint32_t)Addr[ 4 ];\r
1323         /* Load the selected MAC address high register */\r
1324         ( * ( __IO uint32_t * ) ( ( uint32_t ) ( ETH_MAC_ADDR_HBASE + MacAddr ) ) ) = tmpreg;\r
1325         /* Calculate the selected MAC address low register */\r
1326         tmpreg = ( ( uint32_t )Addr[ 3 ] << 24 ) | ( ( uint32_t )Addr[ 2 ] << 16 ) | ( ( uint32_t )Addr[ 1 ] << 8 ) | Addr[ 0 ];\r
1327 \r
1328         /* Load the selected MAC address low register */\r
1329         ( * ( __IO uint32_t * ) ( ( uint32_t ) ( ETH_MAC_ADDR_LBASE + MacAddr ) ) ) = tmpreg;\r
1330 }\r
1331 \r
1332 /**\r
1333   * @brief  Enables the MAC transmission.\r
1334   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1335   *         the configuration information for ETHERNET module\r
1336   * @retval None\r
1337   */\r
1338 static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth)\r
1339 {\r
1340         uint32_t tmpreg = heth->Instance->MACCR | ETH_MACCR_TE;\r
1341 \r
1342         prvWriteMACCR( heth, tmpreg );\r
1343 }\r
1344 \r
1345 /**\r
1346   * @brief  Disables the MAC transmission.\r
1347   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1348   *         the configuration information for ETHERNET module\r
1349   * @retval None\r
1350   */\r
1351 static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth)\r
1352 {\r
1353         uint32_t tmpreg = heth->Instance->MACCR & ~( ETH_MACCR_TE );\r
1354 \r
1355         prvWriteMACCR( heth, tmpreg );\r
1356 }\r
1357 \r
1358 /**\r
1359   * @brief  Enables the MAC reception.\r
1360   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1361   *         the configuration information for ETHERNET module\r
1362   * @retval None\r
1363   */\r
1364 static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth)\r
1365 {\r
1366         __IO uint32_t tmpreg = heth->Instance->MACCR | ETH_MACCR_RE;\r
1367 \r
1368         prvWriteMACCR( heth, tmpreg );\r
1369 }\r
1370 \r
1371 /**\r
1372   * @brief  Disables the MAC reception.\r
1373   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1374   *         the configuration information for ETHERNET module\r
1375   * @retval None\r
1376   */\r
1377 static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth)\r
1378 {\r
1379         __IO uint32_t tmpreg = heth->Instance->MACCR & ~( ETH_MACCR_RE );\r
1380 \r
1381         prvWriteMACCR( heth, tmpreg );\r
1382 }\r
1383 \r
1384 /**\r
1385   * @brief  Enables the DMA transmission.\r
1386   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1387   *         the configuration information for ETHERNET module\r
1388   * @retval None\r
1389   */\r
1390 static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth)\r
1391 {\r
1392         /* Enable the DMA transmission */\r
1393         __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_ST;\r
1394 \r
1395         prvWriteDMAOMR( heth, tmpreg );\r
1396 }\r
1397 \r
1398 /**\r
1399   * @brief  Disables the DMA transmission.\r
1400   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1401   *         the configuration information for ETHERNET module\r
1402   * @retval None\r
1403   */\r
1404 static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth)\r
1405 {\r
1406         /* Disable the DMA transmission */\r
1407         __IO uint32_t tmpreg = heth->Instance->DMAOMR & ~( ETH_DMAOMR_ST );\r
1408 \r
1409         prvWriteDMAOMR( heth, tmpreg );\r
1410 }\r
1411 \r
1412 /**\r
1413   * @brief  Enables the DMA reception.\r
1414   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1415   *         the configuration information for ETHERNET module\r
1416   * @retval None\r
1417   */\r
1418 static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth)\r
1419 {\r
1420         /* Enable the DMA reception */\r
1421         __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_SR;\r
1422 \r
1423         prvWriteDMAOMR( heth, tmpreg );\r
1424 }\r
1425 \r
1426 /**\r
1427   * @brief  Disables the DMA reception.\r
1428   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1429   *         the configuration information for ETHERNET module\r
1430   * @retval None\r
1431   */\r
1432 static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth)\r
1433 {\r
1434         /* Disable the DMA reception */\r
1435         __IO uint32_t tmpreg = heth->Instance->DMAOMR & ~( ETH_DMAOMR_SR );\r
1436 \r
1437         prvWriteDMAOMR( heth, tmpreg );\r
1438 }\r
1439 \r
1440 /**\r
1441   * @brief  Clears the ETHERNET transmit FIFO.\r
1442   * @param  heth: pointer to a ETH_HandleTypeDef structure that contains\r
1443   *         the configuration information for ETHERNET module\r
1444   * @retval None\r
1445   */\r
1446 static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth)\r
1447 {\r
1448         /* Set the Flush Transmit FIFO bit */\r
1449         __IO uint32_t tmpreg = heth->Instance->DMAOMR | ETH_DMAOMR_FTF;\r
1450 \r
1451         prvWriteDMAOMR( heth, tmpreg );\r
1452 }\r
1453 \r
1454 /**\r
1455   * @}\r
1456   */\r
1457 #endif /* stm_is_F2 != 0 || stm_is_F4 != 0 || stm_is_F7 */\r
1458 \r
1459 #endif /* HAL_ETH_MODULE_ENABLED */\r
1460 /**\r
1461   * @}\r
1462   */\r
1463 \r
1464 /**\r
1465   * @}\r
1466   */\r
1467 \r
1468 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r