2 ******************************************************************************
3 * @file stm32f1xx_hal_eth.c
4 * @author MCD Application Team
6 * @date 15-December-2014
7 * @brief ETH HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Ethernet (ETH) peripheral:
10 * + Initialization and de-initialization functions
11 * + IO operation functions
12 * + Peripheral Control functions
13 * + Peripheral State and Errors functions
16 ==============================================================================
17 ##### How to use this driver #####
18 ==============================================================================
20 (#)Declare a ETH_HandleTypeDef handle structure, for example:
21 ETH_HandleTypeDef heth;
23 (#)Fill parameters of Init structure in heth handle
25 (#)Call HAL_ETH_Init() API to initialize the Ethernet peripheral (MAC, DMA, ...)
27 (#)Initialize the ETH low level resources through the HAL_ETH_MspInit() API:
28 (##) Enable the Ethernet interface clock using
29 (+++) __HAL_RCC_ETHMAC_CLK_ENABLE();
30 (+++) __HAL_RCC_ETHMACTX_CLK_ENABLE();
31 (+++) __HAL_RCC_ETHMACRX_CLK_ENABLE();
33 (##) Initialize the related GPIO clocks
34 (##) Configure Ethernet pin-out
35 (##) Configure Ethernet NVIC interrupt (IT mode)
37 (#)Initialize Ethernet DMA Descriptors in chain mode and point to allocated buffers:
38 (##) HAL_ETH_DMATxDescListInit(); for Transmission process
39 (##) HAL_ETH_DMARxDescListInit(); for Reception process
41 (#)Enable MAC and DMA transmission and reception:
44 (#)Prepare ETH DMA TX Descriptors and give the hand to ETH DMA to transfer
45 the frame to MAC TX FIFO:
46 (##) HAL_ETH_TransmitFrame();
48 (#)Poll for a received frame in ETH RX DMA Descriptors and get received
50 (##) HAL_ETH_GetReceivedFrame(); (should be called into an infinite loop)
52 (#) Get a received frame when an ETH RX interrupt occurs:
53 (##) HAL_ETH_GetReceivedFrame_IT(); (called in IT mode only)
55 (#) Communicate with external PHY device:
56 (##) Read a specific register from the PHY
57 HAL_ETH_ReadPHYRegister();
58 (##) Write data to a specific RHY register:
59 HAL_ETH_WritePHYRegister();
61 (#) Configure the Ethernet MAC after ETH peripheral initialization
62 HAL_ETH_ConfigMAC(); all MAC parameters should be filled.
64 (#) Configure the Ethernet DMA after ETH peripheral initialization
65 HAL_ETH_ConfigDMA(); all DMA parameters should be filled.
67 -@- The PTP protocol and the DMA descriptors ring mode are not supported
71 ******************************************************************************
74 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
76 * Redistribution and use in source and binary forms, with or without modification,
77 * are permitted provided that the following conditions are met:
78 * 1. Redistributions of source code must retain the above copyright notice,
79 * this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright notice,
81 * this list of conditions and the following disclaimer in the documentation
82 * and/or other materials provided with the distribution.
83 * 3. Neither the name of STMicroelectronics nor the names of its contributors
84 * may be used to endorse or promote products derived from this software
85 * without specific prior written permission.
87 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
88 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
90 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
93 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
94 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
95 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
96 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98 ******************************************************************************
101 /* Includes ------------------------------------------------------------------*/
102 #include "stm32f1xx_hal.h"
104 /** @addtogroup STM32F1xx_HAL_Driver
107 #if defined (STM32F107xC)
109 /** @defgroup ETH ETH
110 * @brief ETH HAL module driver
114 #ifdef HAL_ETH_MODULE_ENABLED
116 /* Private typedef -----------------------------------------------------------*/
117 /* Private define ------------------------------------------------------------*/
118 /** @defgroup ETH_Private_Constants ETH Private Constants
121 #define LINKED_STATE_TIMEOUT_VALUE ((uint32_t)2000) /* 2000 ms */
122 #define AUTONEGO_COMPLETED_TIMEOUT_VALUE ((uint32_t)1000) /* 1000 ms */
128 /* Private macro -------------------------------------------------------------*/
129 /* Private variables ---------------------------------------------------------*/
130 /* Private function prototypes -----------------------------------------------*/
131 /** @defgroup ETH_Private_Functions ETH Private Functions
134 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err);
135 static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr);
136 static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth);
137 static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth);
138 static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth);
139 static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth);
140 static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth);
141 static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth);
142 static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth);
143 static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth);
144 static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth);
149 /* Private functions ---------------------------------------------------------*/
151 /** @defgroup ETH_Exported_Functions ETH Exported Functions
155 /** @defgroup ETH_Exported_Functions_Group1 Initialization and de-initialization functions
156 * @brief Initialization and Configuration functions
159 ===============================================================================
160 ##### Initialization and de-initialization functions #####
161 ===============================================================================
162 [..] This section provides functions allowing to:
163 (+) Initialize and configure the Ethernet peripheral
164 (+) De-initialize the Ethernet peripheral
171 * @brief Initializes the Ethernet MAC and DMA according to default
173 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
174 * the configuration information for ETHERNET module
177 HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth)
179 uint32_t tmpreg = 0, phyreg = 0;
180 uint32_t hclk = 60000000;
181 uint32_t tickstart = 0;
182 uint32_t err = ETH_SUCCESS;
184 /* Check the ETH peripheral state */
190 /* Check parameters */
191 assert_param(IS_ETH_AUTONEGOTIATION(heth->Init.AutoNegotiation));
192 assert_param(IS_ETH_RX_MODE(heth->Init.RxMode));
193 assert_param(IS_ETH_CHECKSUM_MODE(heth->Init.ChecksumMode));
194 assert_param(IS_ETH_MEDIA_INTERFACE(heth->Init.MediaInterface));
196 if(heth->State == HAL_ETH_STATE_RESET)
198 /* Allocate lock resource and initialize it */
199 heth-> Lock = HAL_UNLOCKED;
201 /* Init the low level hardware : GPIO, CLOCK, NVIC. */
202 HAL_ETH_MspInit(heth);
205 /* Select MII or RMII Mode*/
206 AFIO->MAPR &= ~(AFIO_MAPR_MII_RMII_SEL);
207 AFIO->MAPR |= (uint32_t)heth->Init.MediaInterface;
209 /* Ethernet Software reset */
210 /* Set the SWR bit: resets all MAC subsystem internal registers and logic */
211 /* After reset all the registers holds their respective reset values */
212 (heth->Instance)->DMABMR |= ETH_DMABMR_SR;
214 /* Wait for software reset */
215 while (((heth->Instance)->DMABMR & ETH_DMABMR_SR) != (uint32_t)RESET)
219 /*-------------------------------- MAC Initialization ----------------------*/
220 /* Get the ETHERNET MACMIIAR value */
221 tmpreg = (heth->Instance)->MACMIIAR;
222 /* Clear CSR Clock Range CR[2:0] bits */
223 tmpreg &= ETH_MACMIIAR_CR_MASK;
225 /* Get hclk frequency value */
226 hclk = HAL_RCC_GetHCLKFreq();
228 /* Set CR bits depending on hclk value */
229 if((hclk >= 20000000)&&(hclk < 35000000))
231 /* CSR Clock Range between 20-35 MHz */
232 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_DIV16;
234 else if((hclk >= 35000000)&&(hclk < 60000000))
236 /* CSR Clock Range between 35-60 MHz */
237 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_DIV26;
241 /* CSR Clock Range between 60-72 MHz */
242 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_DIV42;
245 /* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */
246 (heth->Instance)->MACMIIAR = (uint32_t)tmpreg;
248 /*-------------------- PHY initialization and configuration ----------------*/
249 /* Put the PHY in reset mode */
250 if((HAL_ETH_WritePHYRegister(heth, PHY_BCR, PHY_RESET)) != HAL_OK)
252 /* In case of write timeout */
255 /* Config MAC and DMA */
256 ETH_MACDMAConfig(heth, err);
258 /* Set the ETH peripheral state to READY */
259 heth->State = HAL_ETH_STATE_READY;
261 /* Return HAL_ERROR */
265 /* Delay to assure PHY reset */
266 HAL_Delay(PHY_RESET_DELAY);
268 if((heth->Init).AutoNegotiation != ETH_AUTONEGOTIATION_DISABLE)
271 tickstart = HAL_GetTick();
273 /* We wait for linked status */
276 HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg);
278 /* Check for the Timeout */
279 if((HAL_GetTick() - tickstart ) > LINKED_STATE_TIMEOUT_VALUE)
281 /* In case of write timeout */
284 /* Config MAC and DMA */
285 ETH_MACDMAConfig(heth, err);
287 heth->State= HAL_ETH_STATE_READY;
289 /* Process Unlocked */
294 } while (((phyreg & PHY_LINKED_STATUS) != PHY_LINKED_STATUS));
297 /* Enable Auto-Negotiation */
298 if((HAL_ETH_WritePHYRegister(heth, PHY_BCR, PHY_AUTONEGOTIATION)) != HAL_OK)
300 /* In case of write timeout */
303 /* Config MAC and DMA */
304 ETH_MACDMAConfig(heth, err);
306 /* Set the ETH peripheral state to READY */
307 heth->State = HAL_ETH_STATE_READY;
309 /* Return HAL_ERROR */
314 tickstart = HAL_GetTick();
316 /* Wait until the auto-negotiation will be completed */
319 HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg);
321 /* Check for the Timeout */
322 if((HAL_GetTick() - tickstart ) > AUTONEGO_COMPLETED_TIMEOUT_VALUE)
324 /* In case of write timeout */
327 /* Config MAC and DMA */
328 ETH_MACDMAConfig(heth, err);
330 heth->State= HAL_ETH_STATE_READY;
332 /* Process Unlocked */
338 } while (((phyreg & PHY_AUTONEGO_COMPLETE) != PHY_AUTONEGO_COMPLETE));
340 /* Read the result of the auto-negotiation */
341 if((HAL_ETH_ReadPHYRegister(heth, PHY_SR, &phyreg)) != HAL_OK)
343 /* In case of write timeout */
346 /* Config MAC and DMA */
347 ETH_MACDMAConfig(heth, err);
349 /* Set the ETH peripheral state to READY */
350 heth->State = HAL_ETH_STATE_READY;
352 /* Return HAL_ERROR */
356 /* Configure the MAC with the Duplex Mode fixed by the auto-negotiation process */
357 if((phyreg & PHY_DUPLEX_STATUS) != (uint32_t)RESET)
359 /* Set Ethernet duplex mode to Full-duplex following the auto-negotiation */
360 (heth->Init).DuplexMode = ETH_MODE_FULLDUPLEX;
364 /* Set Ethernet duplex mode to Half-duplex following the auto-negotiation */
365 (heth->Init).DuplexMode = ETH_MODE_HALFDUPLEX;
367 /* Configure the MAC with the speed fixed by the auto-negotiation process */
368 if((phyreg & PHY_SPEED_STATUS) == PHY_SPEED_STATUS)
370 /* Set Ethernet speed to 10M following the auto-negotiation */
371 (heth->Init).Speed = ETH_SPEED_10M;
375 /* Set Ethernet speed to 100M following the auto-negotiation */
376 (heth->Init).Speed = ETH_SPEED_100M;
379 else /* AutoNegotiation Disable */
381 /* Check parameters */
382 assert_param(IS_ETH_SPEED(heth->Init.Speed));
383 assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode));
385 /* Set MAC Speed and Duplex Mode */
386 if(HAL_ETH_WritePHYRegister(heth, PHY_BCR, ((uint16_t)((heth->Init).DuplexMode >> 3) |
387 (uint16_t)((heth->Init).Speed >> 1))) != HAL_OK)
389 /* In case of write timeout */
392 /* Config MAC and DMA */
393 ETH_MACDMAConfig(heth, err);
395 /* Set the ETH peripheral state to READY */
396 heth->State = HAL_ETH_STATE_READY;
398 /* Return HAL_ERROR */
402 /* Delay to assure PHY configuration */
403 HAL_Delay(PHY_CONFIG_DELAY);
406 /* Config MAC and DMA */
407 ETH_MACDMAConfig(heth, err);
409 /* Set ETH HAL State to Ready */
410 heth->State= HAL_ETH_STATE_READY;
412 /* Return function status */
417 * @brief De-Initializes the ETH peripheral.
418 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
419 * the configuration information for ETHERNET module
422 HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth)
424 /* Set the ETH peripheral state to BUSY */
425 heth->State = HAL_ETH_STATE_BUSY;
427 /* De-Init the low level hardware : GPIO, CLOCK, NVIC. */
428 HAL_ETH_MspDeInit(heth);
430 /* Set ETH HAL state to Disabled */
431 heth->State= HAL_ETH_STATE_RESET;
436 /* Return function status */
441 * @brief Initializes the DMA Tx descriptors in chain mode.
442 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
443 * the configuration information for ETHERNET module
444 * @param DMATxDescTab: Pointer to the first Tx desc list
445 * @param TxBuff: Pointer to the first TxBuffer list
446 * @param TxBuffCount: Number of the used Tx desc in the list
449 HAL_StatusTypeDef HAL_ETH_DMATxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMATxDescTab, uint8_t *TxBuff, uint32_t TxBuffCount)
452 ETH_DMADescTypeDef *dmatxdesc;
457 /* Set the ETH peripheral state to BUSY */
458 heth->State = HAL_ETH_STATE_BUSY;
460 /* Set the DMATxDescToSet pointer with the first one of the DMATxDescTab list */
461 heth->TxDesc = DMATxDescTab;
463 /* Fill each DMATxDesc descriptor with the right values */
464 for(i=0; i < TxBuffCount; i++)
466 /* Get the pointer on the ith member of the Tx Desc list */
467 dmatxdesc = DMATxDescTab + i;
469 /* Set Second Address Chained bit */
470 dmatxdesc->Status = ETH_DMATXDESC_TCH;
472 /* Set Buffer1 address pointer */
473 dmatxdesc->Buffer1Addr = (uint32_t)(&TxBuff[i*ETH_TX_BUF_SIZE]);
475 if ((heth->Init).ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)
477 /* Set the DMA Tx descriptors checksum insertion */
478 dmatxdesc->Status |= ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL;
481 /* Initialize the next descriptor with the Next Descriptor Polling Enable */
482 if(i < (TxBuffCount-1))
484 /* Set next descriptor address register with next descriptor base address */
485 dmatxdesc->Buffer2NextDescAddr = (uint32_t)(DMATxDescTab+i+1);
489 /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
490 dmatxdesc->Buffer2NextDescAddr = (uint32_t) DMATxDescTab;
494 /* Set Transmit Descriptor List Address Register */
495 (heth->Instance)->DMATDLAR = (uint32_t) DMATxDescTab;
497 /* Set ETH HAL State to Ready */
498 heth->State= HAL_ETH_STATE_READY;
500 /* Process Unlocked */
503 /* Return function status */
508 * @brief Initializes the DMA Rx descriptors in chain mode.
509 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
510 * the configuration information for ETHERNET module
511 * @param DMARxDescTab: Pointer to the first Rx desc list
512 * @param RxBuff: Pointer to the first RxBuffer list
513 * @param RxBuffCount: Number of the used Rx desc in the list
516 HAL_StatusTypeDef HAL_ETH_DMARxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMARxDescTab, uint8_t *RxBuff, uint32_t RxBuffCount)
519 ETH_DMADescTypeDef *DMARxDesc;
524 /* Set the ETH peripheral state to BUSY */
525 heth->State = HAL_ETH_STATE_BUSY;
527 /* Set the Ethernet RxDesc pointer with the first one of the DMARxDescTab list */
528 heth->RxDesc = DMARxDescTab;
530 /* Fill each DMARxDesc descriptor with the right values */
531 for(i=0; i < RxBuffCount; i++)
533 /* Get the pointer on the ith member of the Rx Desc list */
534 DMARxDesc = DMARxDescTab+i;
536 /* Set Own bit of the Rx descriptor Status */
537 DMARxDesc->Status = ETH_DMARXDESC_OWN;
539 /* Set Buffer1 size and Second Address Chained bit */
540 DMARxDesc->ControlBufferSize = ETH_DMARXDESC_RCH | ETH_RX_BUF_SIZE;
542 /* Set Buffer1 address pointer */
543 DMARxDesc->Buffer1Addr = (uint32_t)(&RxBuff[i*ETH_RX_BUF_SIZE]);
545 if((heth->Init).RxMode == ETH_RXINTERRUPT_MODE)
547 /* Enable Ethernet DMA Rx Descriptor interrupt */
548 DMARxDesc->ControlBufferSize &= ~ETH_DMARXDESC_DIC;
551 /* Initialize the next descriptor with the Next Descriptor Polling Enable */
552 if(i < (RxBuffCount-1))
554 /* Set next descriptor address register with next descriptor base address */
555 DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab+i+1);
559 /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
560 DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab);
564 /* Set Receive Descriptor List Address Register */
565 (heth->Instance)->DMARDLAR = (uint32_t) DMARxDescTab;
567 /* Set ETH HAL State to Ready */
568 heth->State= HAL_ETH_STATE_READY;
570 /* Process Unlocked */
573 /* Return function status */
578 * @brief Initializes the ETH MSP.
579 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
580 * the configuration information for ETHERNET module
583 __weak void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
585 /* NOTE : This function Should not be modified, when the callback is needed,
586 the HAL_ETH_MspInit could be implemented in the user file
591 * @brief DeInitializes ETH MSP.
592 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
593 * the configuration information for ETHERNET module
596 __weak void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
598 /* NOTE : This function Should not be modified, when the callback is needed,
599 the HAL_ETH_MspDeInit could be implemented in the user file
607 /** @defgroup ETH_Exported_Functions_Group2 IO operation functions
608 * @brief Data transfers functions
611 ==============================================================================
612 ##### IO operation functions #####
613 ==============================================================================
614 [..] This section provides functions allowing to:
616 HAL_ETH_TransmitFrame();
618 HAL_ETH_GetReceivedFrame();
619 HAL_ETH_GetReceivedFrame_IT();
620 (+) Read from an External PHY register
621 HAL_ETH_ReadPHYRegister();
622 (+) Write to an External PHY register
623 HAL_ETH_WritePHYRegister();
631 * @brief Sends an Ethernet frame.
632 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
633 * the configuration information for ETHERNET module
634 * @param FrameLength: Amount of data to be sent
637 HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameLength)
639 uint32_t bufcount = 0, size = 0, i = 0;
644 /* Set the ETH peripheral state to BUSY */
645 heth->State = HAL_ETH_STATE_BUSY;
647 if (FrameLength == 0)
649 /* Set ETH HAL state to READY */
650 heth->State = HAL_ETH_STATE_READY;
652 /* Process Unlocked */
658 /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
659 if(((heth->TxDesc)->Status & ETH_DMATXDESC_OWN) != (uint32_t)RESET)
662 heth->State = HAL_ETH_STATE_BUSY_TX;
664 /* Process Unlocked */
670 /* Get the number of needed Tx buffers for the current frame */
671 if (FrameLength > ETH_TX_BUF_SIZE)
673 bufcount = FrameLength/ETH_TX_BUF_SIZE;
674 if (FrameLength % ETH_TX_BUF_SIZE)
685 /* Set LAST and FIRST segment */
686 heth->TxDesc->Status |=ETH_DMATXDESC_FS|ETH_DMATXDESC_LS;
688 heth->TxDesc->ControlBufferSize = (FrameLength & ETH_DMATXDESC_TBS1);
689 /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
690 heth->TxDesc->Status |= ETH_DMATXDESC_OWN;
691 /* Point to next descriptor */
692 heth->TxDesc= (ETH_DMADescTypeDef *)(heth->TxDesc->Buffer2NextDescAddr);
696 for (i=0; i< bufcount; i++)
698 /* Clear FIRST and LAST segment bits */
699 heth->TxDesc->Status &= ~(ETH_DMATXDESC_FS | ETH_DMATXDESC_LS);
703 /* Setting the first segment bit */
704 heth->TxDesc->Status |= ETH_DMATXDESC_FS;
708 heth->TxDesc->ControlBufferSize = (ETH_TX_BUF_SIZE & ETH_DMATXDESC_TBS1);
710 if (i == (bufcount-1))
712 /* Setting the last segment bit */
713 heth->TxDesc->Status |= ETH_DMATXDESC_LS;
714 size = FrameLength - (bufcount-1)*ETH_TX_BUF_SIZE;
715 heth->TxDesc->ControlBufferSize = (size & ETH_DMATXDESC_TBS1);
718 /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
719 heth->TxDesc->Status |= ETH_DMATXDESC_OWN;
720 /* point to next descriptor */
721 heth->TxDesc = (ETH_DMADescTypeDef *)(heth->TxDesc->Buffer2NextDescAddr);
725 /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
726 if (((heth->Instance)->DMASR & ETH_DMASR_TBUS) != (uint32_t)RESET)
728 /* Clear TBUS ETHERNET DMA flag */
729 (heth->Instance)->DMASR = ETH_DMASR_TBUS;
730 /* Resume DMA transmission*/
731 (heth->Instance)->DMATPDR = 0;
734 /* Set ETH HAL State to Ready */
735 heth->State = HAL_ETH_STATE_READY;
737 /* Process Unlocked */
740 /* Return function status */
745 * @brief Checks for received frames.
746 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
747 * the configuration information for ETHERNET module
750 HAL_StatusTypeDef HAL_ETH_GetReceivedFrame(ETH_HandleTypeDef *heth)
752 uint32_t framelength = 0;
757 /* Check the ETH state to BUSY */
758 heth->State = HAL_ETH_STATE_BUSY;
760 /* Check if segment is not owned by DMA */
761 /* (((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) && ((heth->RxDesc->Status & ETH_DMARXDESC_LS) != (uint32_t)RESET)) */
762 if(((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET))
764 /* Check if last segment */
765 if(((heth->RxDesc->Status & ETH_DMARXDESC_LS) != (uint32_t)RESET))
767 /* increment segment count */
768 (heth->RxFrameInfos).SegCount++;
770 /* Check if last segment is first segment: one segment contains the frame */
771 if ((heth->RxFrameInfos).SegCount == 1)
773 (heth->RxFrameInfos).FSRxDesc =heth->RxDesc;
776 heth->RxFrameInfos.LSRxDesc = heth->RxDesc;
778 /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
779 framelength = (((heth->RxDesc)->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4;
780 heth->RxFrameInfos.length = framelength;
782 /* Get the address of the buffer start address */
783 heth->RxFrameInfos.buffer = ((heth->RxFrameInfos).FSRxDesc)->Buffer1Addr;
784 /* point to next descriptor */
785 heth->RxDesc = (ETH_DMADescTypeDef*) ((heth->RxDesc)->Buffer2NextDescAddr);
787 /* Set HAL State to Ready */
788 heth->State = HAL_ETH_STATE_READY;
790 /* Process Unlocked */
793 /* Return function status */
796 /* Check if first segment */
797 else if((heth->RxDesc->Status & ETH_DMARXDESC_FS) != (uint32_t)RESET)
799 (heth->RxFrameInfos).FSRxDesc = heth->RxDesc;
800 (heth->RxFrameInfos).LSRxDesc = NULL;
801 (heth->RxFrameInfos).SegCount = 1;
802 /* Point to next descriptor */
803 heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);
805 /* Check if intermediate segment */
808 (heth->RxFrameInfos).SegCount++;
809 /* Point to next descriptor */
810 heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);
814 /* Set ETH HAL State to Ready */
815 heth->State = HAL_ETH_STATE_READY;
817 /* Process Unlocked */
820 /* Return function status */
825 * @brief Gets the Received frame in interrupt mode.
826 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
827 * the configuration information for ETHERNET module
830 HAL_StatusTypeDef HAL_ETH_GetReceivedFrame_IT(ETH_HandleTypeDef *heth)
832 uint32_t descriptorscancounter = 0;
837 /* Set ETH HAL State to BUSY */
838 heth->State = HAL_ETH_STATE_BUSY;
840 /* Scan descriptors owned by CPU */
841 while (((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) && (descriptorscancounter < ETH_RXBUFNB))
843 /* Just for security */
844 descriptorscancounter++;
846 /* Check if first segment in frame */
847 /* ((heth->RxDesc->Status & ETH_DMARXDESC_FS) != (uint32_t)RESET) && ((heth->RxDesc->Status & ETH_DMARXDESC_LS) == (uint32_t)RESET)) */
848 if((heth->RxDesc->Status & (ETH_DMARXDESC_FS | ETH_DMARXDESC_LS)) == (uint32_t)ETH_DMARXDESC_FS)
850 heth->RxFrameInfos.FSRxDesc = heth->RxDesc;
851 heth->RxFrameInfos.SegCount = 1;
852 /* Point to next descriptor */
853 heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);
855 /* Check if intermediate segment */
856 /* ((heth->RxDesc->Status & ETH_DMARXDESC_LS) == (uint32_t)RESET)&& ((heth->RxDesc->Status & ETH_DMARXDESC_FS) == (uint32_t)RESET)) */
857 else if ((heth->RxDesc->Status & (ETH_DMARXDESC_LS | ETH_DMARXDESC_FS)) == (uint32_t)RESET)
859 /* Increment segment count */
860 (heth->RxFrameInfos.SegCount)++;
861 /* Point to next descriptor */
862 heth->RxDesc = (ETH_DMADescTypeDef*)(heth->RxDesc->Buffer2NextDescAddr);
864 /* Should be last segment */
868 heth->RxFrameInfos.LSRxDesc = heth->RxDesc;
870 /* Increment segment count */
871 (heth->RxFrameInfos.SegCount)++;
873 /* Check if last segment is first segment: one segment contains the frame */
874 if ((heth->RxFrameInfos.SegCount) == 1)
876 heth->RxFrameInfos.FSRxDesc = heth->RxDesc;
879 /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
880 heth->RxFrameInfos.length = (((heth->RxDesc)->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4;
882 /* Get the address of the buffer start address */
883 heth->RxFrameInfos.buffer =((heth->RxFrameInfos).FSRxDesc)->Buffer1Addr;
885 /* Point to next descriptor */
886 heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);
888 /* Set HAL State to Ready */
889 heth->State = HAL_ETH_STATE_READY;
891 /* Process Unlocked */
894 /* Return function status */
899 /* Set HAL State to Ready */
900 heth->State = HAL_ETH_STATE_READY;
902 /* Process Unlocked */
905 /* Return function status */
910 * @brief This function handles ETH interrupt request.
911 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
912 * the configuration information for ETHERNET module
915 void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth)
918 if (__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_R))
920 /* Receive complete callback */
921 HAL_ETH_RxCpltCallback(heth);
923 /* Clear the Eth DMA Rx IT pending bits */
924 __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_R);
926 /* Set HAL State to Ready */
927 heth->State = HAL_ETH_STATE_READY;
929 /* Process Unlocked */
933 /* Frame transmitted */
934 else if (__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_T))
936 /* Transfer complete callback */
937 HAL_ETH_TxCpltCallback(heth);
939 /* Clear the Eth DMA Tx IT pending bits */
940 __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_T);
942 /* Set HAL State to Ready */
943 heth->State = HAL_ETH_STATE_READY;
945 /* Process Unlocked */
949 /* Clear the interrupt flags */
950 __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_NIS);
953 if(__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_AIS))
955 /* Ethernet Error callback */
956 HAL_ETH_ErrorCallback(heth);
958 /* Clear the interrupt flags */
959 __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_FLAG_AIS);
961 /* Set HAL State to Ready */
962 heth->State = HAL_ETH_STATE_READY;
964 /* Process Unlocked */
970 * @brief Tx Transfer completed callbacks.
971 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
972 * the configuration information for ETHERNET module
975 __weak void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)
977 /* NOTE : This function Should not be modified, when the callback is needed,
978 the HAL_ETH_TxCpltCallback could be implemented in the user file
983 * @brief Rx Transfer completed callbacks.
984 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
985 * the configuration information for ETHERNET module
988 __weak void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
990 /* NOTE : This function Should not be modified, when the callback is needed,
991 the HAL_ETH_TxCpltCallback could be implemented in the user file
996 * @brief Ethernet transfer error callbacks
997 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
998 * the configuration information for ETHERNET module
1001 __weak void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)
1003 /* NOTE : This function Should not be modified, when the callback is needed,
1004 the HAL_ETH_TxCpltCallback could be implemented in the user file
1009 * @brief Reads a PHY register
1010 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1011 * the configuration information for ETHERNET module
1012 * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
1013 * This parameter can be one of the following values:
1014 * PHY_BCR: Transceiver Basic Control Register,
1015 * PHY_BSR: Transceiver Basic Status Register.
1016 * More PHY register could be read depending on the used PHY
1017 * @param RegValue: PHY register value
1018 * @retval HAL status
1020 HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t *RegValue)
1022 uint32_t tmpreg = 0;
1023 uint32_t tickstart = 0;
1025 /* Check parameters */
1026 assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));
1028 /* Check the ETH peripheral state */
1029 if(heth->State == HAL_ETH_STATE_BUSY_RD)
1033 /* Set ETH HAL State to BUSY_RD */
1034 heth->State = HAL_ETH_STATE_BUSY_RD;
1036 /* Get the ETHERNET MACMIIAR value */
1037 tmpreg = heth->Instance->MACMIIAR;
1039 /* Keep only the CSR Clock Range CR[2:0] bits value */
1040 tmpreg &= ~ETH_MACMIIAR_CR_MASK;
1042 /* Prepare the MII address register value */
1043 tmpreg |=(((uint32_t)heth->Init.PhyAddress << 11) & ETH_MACMIIAR_PA); /* Set the PHY device address */
1044 tmpreg |=(((uint32_t)PHYReg<<6) & ETH_MACMIIAR_MR); /* Set the PHY register address */
1045 tmpreg &= ~ETH_MACMIIAR_MW; /* Set the read mode */
1046 tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
1048 /* Write the result value into the MII Address register */
1049 heth->Instance->MACMIIAR = tmpreg;
1052 tickstart = HAL_GetTick();
1054 /* Check for the Busy flag */
1055 while((tmpreg & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB)
1057 /* Check for the Timeout */
1058 if((HAL_GetTick() - tickstart ) > PHY_READ_TO)
1060 heth->State= HAL_ETH_STATE_READY;
1062 /* Process Unlocked */
1068 tmpreg = heth->Instance->MACMIIAR;
1071 /* Get MACMIIDR value */
1072 *RegValue = (uint16_t)(heth->Instance->MACMIIDR);
1074 /* Set ETH HAL State to READY */
1075 heth->State = HAL_ETH_STATE_READY;
1077 /* Return function status */
1082 * @brief Writes to a PHY register.
1083 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1084 * the configuration information for ETHERNET module
1085 * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
1086 * This parameter can be one of the following values:
1087 * PHY_BCR: Transceiver Control Register.
1088 * More PHY register could be written depending on the used PHY
1089 * @param RegValue: the value to write
1090 * @retval HAL status
1092 HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t RegValue)
1094 uint32_t tmpreg = 0;
1095 uint32_t tickstart = 0;
1097 /* Check parameters */
1098 assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));
1100 /* Check the ETH peripheral state */
1101 if(heth->State == HAL_ETH_STATE_BUSY_WR)
1105 /* Set ETH HAL State to BUSY_WR */
1106 heth->State = HAL_ETH_STATE_BUSY_WR;
1108 /* Get the ETHERNET MACMIIAR value */
1109 tmpreg = heth->Instance->MACMIIAR;
1111 /* Keep only the CSR Clock Range CR[2:0] bits value */
1112 tmpreg &= ~ETH_MACMIIAR_CR_MASK;
1114 /* Prepare the MII register address value */
1115 tmpreg |=(((uint32_t)heth->Init.PhyAddress<<11) & ETH_MACMIIAR_PA); /* Set the PHY device address */
1116 tmpreg |=(((uint32_t)PHYReg<<6) & ETH_MACMIIAR_MR); /* Set the PHY register address */
1117 tmpreg |= ETH_MACMIIAR_MW; /* Set the write mode */
1118 tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
1120 /* Give the value to the MII data register */
1121 heth->Instance->MACMIIDR = (uint16_t)RegValue;
1123 /* Write the result value into the MII Address register */
1124 heth->Instance->MACMIIAR = tmpreg;
1127 tickstart = HAL_GetTick();
1129 /* Check for the Busy flag */
1130 while((tmpreg & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB)
1132 /* Check for the Timeout */
1133 if((HAL_GetTick() - tickstart ) > PHY_WRITE_TO)
1135 heth->State= HAL_ETH_STATE_READY;
1137 /* Process Unlocked */
1143 tmpreg = heth->Instance->MACMIIAR;
1146 /* Set ETH HAL State to READY */
1147 heth->State = HAL_ETH_STATE_READY;
1149 /* Return function status */
1157 /** @defgroup ETH_Exported_Functions_Group3 Peripheral Control functions
1158 * @brief Peripheral Control functions
1161 ===============================================================================
1162 ##### Peripheral Control functions #####
1163 ===============================================================================
1164 [..] This section provides functions allowing to:
1165 (+) Enable MAC and DMA transmission and reception.
1167 (+) Disable MAC and DMA transmission and reception.
1169 (+) Set the MAC configuration in runtime mode
1170 HAL_ETH_ConfigMAC();
1171 (+) Set the DMA configuration in runtime mode
1172 HAL_ETH_ConfigDMA();
1179 * @brief Enables Ethernet MAC and DMA reception/transmission
1180 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1181 * the configuration information for ETHERNET module
1182 * @retval HAL status
1184 HAL_StatusTypeDef HAL_ETH_Start(ETH_HandleTypeDef *heth)
1186 /* Process Locked */
1189 /* Set the ETH peripheral state to BUSY */
1190 heth->State = HAL_ETH_STATE_BUSY;
1192 /* Enable transmit state machine of the MAC for transmission on the MII */
1193 ETH_MACTransmissionEnable(heth);
1195 /* Enable receive state machine of the MAC for reception from the MII */
1196 ETH_MACReceptionEnable(heth);
1198 /* Flush Transmit FIFO */
1199 ETH_FlushTransmitFIFO(heth);
1201 /* Start DMA transmission */
1202 ETH_DMATransmissionEnable(heth);
1204 /* Start DMA reception */
1205 ETH_DMAReceptionEnable(heth);
1207 /* Set the ETH state to READY*/
1208 heth->State= HAL_ETH_STATE_READY;
1210 /* Process Unlocked */
1213 /* Return function status */
1218 * @brief Stop Ethernet MAC and DMA reception/transmission
1219 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1220 * the configuration information for ETHERNET module
1221 * @retval HAL status
1223 HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth)
1225 /* Process Locked */
1228 /* Set the ETH peripheral state to BUSY */
1229 heth->State = HAL_ETH_STATE_BUSY;
1231 /* Stop DMA transmission */
1232 ETH_DMATransmissionDisable(heth);
1234 /* Stop DMA reception */
1235 ETH_DMAReceptionDisable(heth);
1237 /* Disable receive state machine of the MAC for reception from the MII */
1238 ETH_MACReceptionDisable(heth);
1240 /* Flush Transmit FIFO */
1241 ETH_FlushTransmitFIFO(heth);
1243 /* Disable transmit state machine of the MAC for transmission on the MII */
1244 ETH_MACTransmissionDisable(heth);
1246 /* Set the ETH state*/
1247 heth->State = HAL_ETH_STATE_READY;
1249 /* Process Unlocked */
1252 /* Return function status */
1257 * @brief Set ETH MAC Configuration.
1258 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1259 * the configuration information for ETHERNET module
1260 * @param macconf: MAC Configuration structure
1261 * @retval HAL status
1263 HAL_StatusTypeDef HAL_ETH_ConfigMAC(ETH_HandleTypeDef *heth, ETH_MACInitTypeDef *macconf)
1265 uint32_t tmpreg = 0;
1267 /* Process Locked */
1270 /* Set the ETH peripheral state to BUSY */
1271 heth->State= HAL_ETH_STATE_BUSY;
1273 assert_param(IS_ETH_SPEED(heth->Init.Speed));
1274 assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode));
1276 if (macconf != NULL)
1278 /* Check the parameters */
1279 assert_param(IS_ETH_WATCHDOG(macconf->Watchdog));
1280 assert_param(IS_ETH_JABBER(macconf->Jabber));
1281 assert_param(IS_ETH_INTER_FRAME_GAP(macconf->InterFrameGap));
1282 assert_param(IS_ETH_CARRIER_SENSE(macconf->CarrierSense));
1283 assert_param(IS_ETH_RECEIVE_OWN(macconf->ReceiveOwn));
1284 assert_param(IS_ETH_LOOPBACK_MODE(macconf->LoopbackMode));
1285 assert_param(IS_ETH_CHECKSUM_OFFLOAD(macconf->ChecksumOffload));
1286 assert_param(IS_ETH_RETRY_TRANSMISSION(macconf->RetryTransmission));
1287 assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(macconf->AutomaticPadCRCStrip));
1288 assert_param(IS_ETH_BACKOFF_LIMIT(macconf->BackOffLimit));
1289 assert_param(IS_ETH_DEFERRAL_CHECK(macconf->DeferralCheck));
1290 assert_param(IS_ETH_RECEIVE_ALL(macconf->ReceiveAll));
1291 assert_param(IS_ETH_SOURCE_ADDR_FILTER(macconf->SourceAddrFilter));
1292 assert_param(IS_ETH_CONTROL_FRAMES(macconf->PassControlFrames));
1293 assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(macconf->BroadcastFramesReception));
1294 assert_param(IS_ETH_DESTINATION_ADDR_FILTER(macconf->DestinationAddrFilter));
1295 assert_param(IS_ETH_PROMISCUOUS_MODE(macconf->PromiscuousMode));
1296 assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(macconf->MulticastFramesFilter));
1297 assert_param(IS_ETH_UNICAST_FRAMES_FILTER(macconf->UnicastFramesFilter));
1298 assert_param(IS_ETH_PAUSE_TIME(macconf->PauseTime));
1299 assert_param(IS_ETH_ZEROQUANTA_PAUSE(macconf->ZeroQuantaPause));
1300 assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(macconf->PauseLowThreshold));
1301 assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(macconf->UnicastPauseFrameDetect));
1302 assert_param(IS_ETH_RECEIVE_FLOWCONTROL(macconf->ReceiveFlowControl));
1303 assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(macconf->TransmitFlowControl));
1304 assert_param(IS_ETH_VLAN_TAG_COMPARISON(macconf->VLANTagComparison));
1305 assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(macconf->VLANTagIdentifier));
1307 /*------------------------ ETHERNET MACCR Configuration --------------------*/
1308 /* Get the ETHERNET MACCR value */
1309 tmpreg = (heth->Instance)->MACCR;
1310 /* Clear WD, PCE, PS, TE and RE bits */
1311 tmpreg &= ETH_MACCR_CLEAR_MASK;
1313 tmpreg |= (uint32_t)(macconf->Watchdog |
1315 macconf->InterFrameGap |
1316 macconf->CarrierSense |
1317 (heth->Init).Speed |
1318 macconf->ReceiveOwn |
1319 macconf->LoopbackMode |
1320 (heth->Init).DuplexMode |
1321 macconf->ChecksumOffload |
1322 macconf->RetryTransmission |
1323 macconf->AutomaticPadCRCStrip |
1324 macconf->BackOffLimit |
1325 macconf->DeferralCheck);
1327 /* Write to ETHERNET MACCR */
1328 (heth->Instance)->MACCR = (uint32_t)tmpreg;
1330 /* Wait until the write operation will be taken into account :
1331 at least four TX_CLK/RX_CLK clock cycles */
1332 tmpreg = (heth->Instance)->MACCR;
1333 HAL_Delay(ETH_REG_WRITE_DELAY);
1334 (heth->Instance)->MACCR = tmpreg;
1336 /*----------------------- ETHERNET MACFFR Configuration --------------------*/
1337 /* Write to ETHERNET MACFFR */
1338 (heth->Instance)->MACFFR = (uint32_t)(macconf->ReceiveAll |
1339 macconf->SourceAddrFilter |
1340 macconf->PassControlFrames |
1341 macconf->BroadcastFramesReception |
1342 macconf->DestinationAddrFilter |
1343 macconf->PromiscuousMode |
1344 macconf->MulticastFramesFilter |
1345 macconf->UnicastFramesFilter);
1347 /* Wait until the write operation will be taken into account :
1348 at least four TX_CLK/RX_CLK clock cycles */
1349 tmpreg = (heth->Instance)->MACFFR;
1350 HAL_Delay(ETH_REG_WRITE_DELAY);
1351 (heth->Instance)->MACFFR = tmpreg;
1353 /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/
1354 /* Write to ETHERNET MACHTHR */
1355 (heth->Instance)->MACHTHR = (uint32_t)macconf->HashTableHigh;
1357 /* Write to ETHERNET MACHTLR */
1358 (heth->Instance)->MACHTLR = (uint32_t)macconf->HashTableLow;
1359 /*----------------------- ETHERNET MACFCR Configuration --------------------*/
1361 /* Get the ETHERNET MACFCR value */
1362 tmpreg = (heth->Instance)->MACFCR;
1364 tmpreg &= ETH_MACFCR_CLEAR_MASK;
1366 tmpreg |= (uint32_t)((macconf->PauseTime << 16) |
1367 macconf->ZeroQuantaPause |
1368 macconf->PauseLowThreshold |
1369 macconf->UnicastPauseFrameDetect |
1370 macconf->ReceiveFlowControl |
1371 macconf->TransmitFlowControl);
1373 /* Write to ETHERNET MACFCR */
1374 (heth->Instance)->MACFCR = (uint32_t)tmpreg;
1376 /* Wait until the write operation will be taken into account :
1377 at least four TX_CLK/RX_CLK clock cycles */
1378 tmpreg = (heth->Instance)->MACFCR;
1379 HAL_Delay(ETH_REG_WRITE_DELAY);
1380 (heth->Instance)->MACFCR = tmpreg;
1382 /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/
1383 (heth->Instance)->MACVLANTR = (uint32_t)(macconf->VLANTagComparison |
1384 macconf->VLANTagIdentifier);
1386 /* Wait until the write operation will be taken into account :
1387 at least four TX_CLK/RX_CLK clock cycles */
1388 tmpreg = (heth->Instance)->MACVLANTR;
1389 HAL_Delay(ETH_REG_WRITE_DELAY);
1390 (heth->Instance)->MACVLANTR = tmpreg;
1392 else /* macconf == NULL : here we just configure Speed and Duplex mode */
1394 /*------------------------ ETHERNET MACCR Configuration --------------------*/
1395 /* Get the ETHERNET MACCR value */
1396 tmpreg = (heth->Instance)->MACCR;
1398 /* Clear FES and DM bits */
1399 tmpreg &= ~((uint32_t)0x00004800);
1401 tmpreg |= (uint32_t)(heth->Init.Speed | heth->Init.DuplexMode);
1403 /* Write to ETHERNET MACCR */
1404 (heth->Instance)->MACCR = (uint32_t)tmpreg;
1406 /* Wait until the write operation will be taken into account:
1407 at least four TX_CLK/RX_CLK clock cycles */
1408 tmpreg = (heth->Instance)->MACCR;
1409 HAL_Delay(ETH_REG_WRITE_DELAY);
1410 (heth->Instance)->MACCR = tmpreg;
1413 /* Set the ETH state to Ready */
1414 heth->State= HAL_ETH_STATE_READY;
1416 /* Process Unlocked */
1419 /* Return function status */
1424 * @brief Sets ETH DMA Configuration.
1425 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1426 * the configuration information for ETHERNET module
1427 * @param dmaconf: DMA Configuration structure
1428 * @retval HAL status
1430 HAL_StatusTypeDef HAL_ETH_ConfigDMA(ETH_HandleTypeDef *heth, ETH_DMAInitTypeDef *dmaconf)
1432 uint32_t tmpreg = 0;
1434 /* Process Locked */
1437 /* Set the ETH peripheral state to BUSY */
1438 heth->State= HAL_ETH_STATE_BUSY;
1440 /* Check parameters */
1441 assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(dmaconf->DropTCPIPChecksumErrorFrame));
1442 assert_param(IS_ETH_RECEIVE_STORE_FORWARD(dmaconf->ReceiveStoreForward));
1443 assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(dmaconf->FlushReceivedFrame));
1444 assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(dmaconf->TransmitStoreForward));
1445 assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(dmaconf->TransmitThresholdControl));
1446 assert_param(IS_ETH_FORWARD_ERROR_FRAMES(dmaconf->ForwardErrorFrames));
1447 assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(dmaconf->ForwardUndersizedGoodFrames));
1448 assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(dmaconf->ReceiveThresholdControl));
1449 assert_param(IS_ETH_SECOND_FRAME_OPERATE(dmaconf->SecondFrameOperate));
1450 assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(dmaconf->AddressAlignedBeats));
1451 assert_param(IS_ETH_FIXED_BURST(dmaconf->FixedBurst));
1452 assert_param(IS_ETH_RXDMA_BURST_LENGTH(dmaconf->RxDMABurstLength));
1453 assert_param(IS_ETH_TXDMA_BURST_LENGTH(dmaconf->TxDMABurstLength));
1454 assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(dmaconf->DescriptorSkipLength));
1455 assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(dmaconf->DMAArbitration));
1457 /*----------------------- ETHERNET DMAOMR Configuration --------------------*/
1458 /* Get the ETHERNET DMAOMR value */
1459 tmpreg = (heth->Instance)->DMAOMR;
1461 tmpreg &= ETH_DMAOMR_CLEAR_MASK;
1463 tmpreg |= (uint32_t)(dmaconf->DropTCPIPChecksumErrorFrame |
1464 dmaconf->ReceiveStoreForward |
1465 dmaconf->FlushReceivedFrame |
1466 dmaconf->TransmitStoreForward |
1467 dmaconf->TransmitThresholdControl |
1468 dmaconf->ForwardErrorFrames |
1469 dmaconf->ForwardUndersizedGoodFrames |
1470 dmaconf->ReceiveThresholdControl |
1471 dmaconf->SecondFrameOperate);
1473 /* Write to ETHERNET DMAOMR */
1474 (heth->Instance)->DMAOMR = (uint32_t)tmpreg;
1476 /* Wait until the write operation will be taken into account:
1477 at least four TX_CLK/RX_CLK clock cycles */
1478 tmpreg = (heth->Instance)->DMAOMR;
1479 HAL_Delay(ETH_REG_WRITE_DELAY);
1480 (heth->Instance)->DMAOMR = tmpreg;
1482 /*----------------------- ETHERNET DMABMR Configuration --------------------*/
1483 (heth->Instance)->DMABMR = (uint32_t)(dmaconf->AddressAlignedBeats |
1484 dmaconf->FixedBurst |
1485 dmaconf->RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
1486 dmaconf->TxDMABurstLength |
1487 (dmaconf->DescriptorSkipLength << 2) |
1488 dmaconf->DMAArbitration |
1489 ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
1491 /* Wait until the write operation will be taken into account:
1492 at least four TX_CLK/RX_CLK clock cycles */
1493 tmpreg = (heth->Instance)->DMABMR;
1494 HAL_Delay(ETH_REG_WRITE_DELAY);
1495 (heth->Instance)->DMABMR = tmpreg;
1497 /* Set the ETH state to Ready */
1498 heth->State= HAL_ETH_STATE_READY;
1500 /* Process Unlocked */
1503 /* Return function status */
1511 /** @defgroup ETH_Exported_Functions_Group4 Peripheral State functions
1512 * @brief Peripheral State functions
1515 ===============================================================================
1516 ##### Peripheral State functions #####
1517 ===============================================================================
1519 This subsection permits to get in run-time the status of the peripheral
1521 (+) Get the ETH handle state:
1530 * @brief Return the ETH HAL state
1531 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1532 * the configuration information for ETHERNET module
1535 HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth)
1537 /* Return ETH state */
1549 /** @addtogroup ETH_Private_Functions
1554 * @brief Configures Ethernet MAC and DMA with default parameters.
1555 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1556 * the configuration information for ETHERNET module
1557 * @param err: Ethernet Init error
1558 * @retval HAL status
1560 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err)
1562 ETH_MACInitTypeDef macinit;
1563 ETH_DMAInitTypeDef dmainit;
1564 uint32_t tmpreg = 0;
1566 if (err != ETH_SUCCESS) /* Auto-negotiation failed */
1568 /* Set Ethernet duplex mode to Full-duplex */
1569 (heth->Init).DuplexMode = ETH_MODE_FULLDUPLEX;
1571 /* Set Ethernet speed to 100M */
1572 (heth->Init).Speed = ETH_SPEED_100M;
1575 /* Ethernet MAC default initialization **************************************/
1576 macinit.Watchdog = ETH_WATCHDOG_ENABLE;
1577 macinit.Jabber = ETH_JABBER_ENABLE;
1578 macinit.InterFrameGap = ETH_INTERFRAMEGAP_96BIT;
1579 macinit.CarrierSense = ETH_CARRIERSENCE_ENABLE;
1580 macinit.ReceiveOwn = ETH_RECEIVEOWN_ENABLE;
1581 macinit.LoopbackMode = ETH_LOOPBACKMODE_DISABLE;
1582 if(heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)
1584 macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;
1588 macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;
1590 macinit.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE;
1591 macinit.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE;
1592 macinit.BackOffLimit = ETH_BACKOFFLIMIT_10;
1593 macinit.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE;
1594 macinit.ReceiveAll = ETH_RECEIVEAll_DISABLE;
1595 macinit.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE;
1596 macinit.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL;
1597 macinit.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE;
1598 macinit.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL;
1599 macinit.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE;
1600 macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;
1601 macinit.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT;
1602 macinit.HashTableHigh = 0x0;
1603 macinit.HashTableLow = 0x0;
1604 macinit.PauseTime = 0x0;
1605 macinit.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE;
1606 macinit.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;
1607 macinit.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE;
1608 macinit.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE;
1609 macinit.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE;
1610 macinit.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT;
1611 macinit.VLANTagIdentifier = 0x0;
1613 /*------------------------ ETHERNET MACCR Configuration --------------------*/
1614 /* Get the ETHERNET MACCR value */
1615 tmpreg = (heth->Instance)->MACCR;
1616 /* Clear WD, PCE, PS, TE and RE bits */
1617 tmpreg &= ETH_MACCR_CLEAR_MASK;
1618 /* Set the WD bit according to ETH Watchdog value */
1619 /* Set the JD: bit according to ETH Jabber value */
1620 /* Set the IFG bit according to ETH InterFrameGap value */
1621 /* Set the DCRS bit according to ETH CarrierSense value */
1622 /* Set the FES bit according to ETH Speed value */
1623 /* Set the DO bit according to ETH ReceiveOwn value */
1624 /* Set the LM bit according to ETH LoopbackMode value */
1625 /* Set the DM bit according to ETH Mode value */
1626 /* Set the IPCO bit according to ETH ChecksumOffload value */
1627 /* Set the DR bit according to ETH RetryTransmission value */
1628 /* Set the ACS bit according to ETH AutomaticPadCRCStrip value */
1629 /* Set the BL bit according to ETH BackOffLimit value */
1630 /* Set the DC bit according to ETH DeferralCheck value */
1631 tmpreg |= (uint32_t)(macinit.Watchdog |
1633 macinit.InterFrameGap |
1634 macinit.CarrierSense |
1635 (heth->Init).Speed |
1636 macinit.ReceiveOwn |
1637 macinit.LoopbackMode |
1638 (heth->Init).DuplexMode |
1639 macinit.ChecksumOffload |
1640 macinit.RetryTransmission |
1641 macinit.AutomaticPadCRCStrip |
1642 macinit.BackOffLimit |
1643 macinit.DeferralCheck);
1645 /* Write to ETHERNET MACCR */
1646 (heth->Instance)->MACCR = (uint32_t)tmpreg;
1648 /* Wait until the write operation will be taken into account:
1649 at least four TX_CLK/RX_CLK clock cycles */
1650 tmpreg = (heth->Instance)->MACCR;
1651 HAL_Delay(ETH_REG_WRITE_DELAY);
1652 (heth->Instance)->MACCR = tmpreg;
1654 /*----------------------- ETHERNET MACFFR Configuration --------------------*/
1655 /* Set the RA bit according to ETH ReceiveAll value */
1656 /* Set the SAF and SAIF bits according to ETH SourceAddrFilter value */
1657 /* Set the PCF bit according to ETH PassControlFrames value */
1658 /* Set the DBF bit according to ETH BroadcastFramesReception value */
1659 /* Set the DAIF bit according to ETH DestinationAddrFilter value */
1660 /* Set the PR bit according to ETH PromiscuousMode value */
1661 /* Set the PM, HMC and HPF bits according to ETH MulticastFramesFilter value */
1662 /* Set the HUC and HPF bits according to ETH UnicastFramesFilter value */
1663 /* Write to ETHERNET MACFFR */
1664 (heth->Instance)->MACFFR = (uint32_t)(macinit.ReceiveAll |
1665 macinit.SourceAddrFilter |
1666 macinit.PassControlFrames |
1667 macinit.BroadcastFramesReception |
1668 macinit.DestinationAddrFilter |
1669 macinit.PromiscuousMode |
1670 macinit.MulticastFramesFilter |
1671 macinit.UnicastFramesFilter);
1673 /* Wait until the write operation will be taken into account:
1674 at least four TX_CLK/RX_CLK clock cycles */
1675 tmpreg = (heth->Instance)->MACFFR;
1676 HAL_Delay(ETH_REG_WRITE_DELAY);
1677 (heth->Instance)->MACFFR = tmpreg;
1679 /*--------------- ETHERNET MACHTHR and MACHTLR Configuration --------------*/
1680 /* Write to ETHERNET MACHTHR */
1681 (heth->Instance)->MACHTHR = (uint32_t)macinit.HashTableHigh;
1683 /* Write to ETHERNET MACHTLR */
1684 (heth->Instance)->MACHTLR = (uint32_t)macinit.HashTableLow;
1685 /*----------------------- ETHERNET MACFCR Configuration -------------------*/
1687 /* Get the ETHERNET MACFCR value */
1688 tmpreg = (heth->Instance)->MACFCR;
1690 tmpreg &= ETH_MACFCR_CLEAR_MASK;
1692 /* Set the PT bit according to ETH PauseTime value */
1693 /* Set the DZPQ bit according to ETH ZeroQuantaPause value */
1694 /* Set the PLT bit according to ETH PauseLowThreshold value */
1695 /* Set the UP bit according to ETH UnicastPauseFrameDetect value */
1696 /* Set the RFE bit according to ETH ReceiveFlowControl value */
1697 /* Set the TFE bit according to ETH TransmitFlowControl value */
1698 tmpreg |= (uint32_t)((macinit.PauseTime << 16) |
1699 macinit.ZeroQuantaPause |
1700 macinit.PauseLowThreshold |
1701 macinit.UnicastPauseFrameDetect |
1702 macinit.ReceiveFlowControl |
1703 macinit.TransmitFlowControl);
1705 /* Write to ETHERNET MACFCR */
1706 (heth->Instance)->MACFCR = (uint32_t)tmpreg;
1708 /* Wait until the write operation will be taken into account:
1709 at least four TX_CLK/RX_CLK clock cycles */
1710 tmpreg = (heth->Instance)->MACFCR;
1711 HAL_Delay(ETH_REG_WRITE_DELAY);
1712 (heth->Instance)->MACFCR = tmpreg;
1714 /*----------------------- ETHERNET MACVLANTR Configuration ----------------*/
1715 /* Set the ETV bit according to ETH VLANTagComparison value */
1716 /* Set the VL bit according to ETH VLANTagIdentifier value */
1717 (heth->Instance)->MACVLANTR = (uint32_t)(macinit.VLANTagComparison |
1718 macinit.VLANTagIdentifier);
1720 /* Wait until the write operation will be taken into account:
1721 at least four TX_CLK/RX_CLK clock cycles */
1722 tmpreg = (heth->Instance)->MACVLANTR;
1723 HAL_Delay(ETH_REG_WRITE_DELAY);
1724 (heth->Instance)->MACVLANTR = tmpreg;
1726 /* Ethernet DMA default initialization ************************************/
1727 dmainit.DropTCPIPChecksumErrorFrame = ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE;
1728 dmainit.ReceiveStoreForward = ETH_RECEIVESTOREFORWARD_ENABLE;
1729 dmainit.FlushReceivedFrame = ETH_FLUSHRECEIVEDFRAME_ENABLE;
1730 dmainit.TransmitStoreForward = ETH_TRANSMITSTOREFORWARD_ENABLE;
1731 dmainit.TransmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;
1732 dmainit.ForwardErrorFrames = ETH_FORWARDERRORFRAMES_DISABLE;
1733 dmainit.ForwardUndersizedGoodFrames = ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE;
1734 dmainit.ReceiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;
1735 dmainit.SecondFrameOperate = ETH_SECONDFRAMEOPERARTE_ENABLE;
1736 dmainit.AddressAlignedBeats = ETH_ADDRESSALIGNEDBEATS_ENABLE;
1737 dmainit.FixedBurst = ETH_FIXEDBURST_ENABLE;
1738 dmainit.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;
1739 dmainit.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;
1740 dmainit.DescriptorSkipLength = 0x0;
1741 dmainit.DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;
1743 /* Get the ETHERNET DMAOMR value */
1744 tmpreg = (heth->Instance)->DMAOMR;
1746 tmpreg &= ETH_DMAOMR_CLEAR_MASK;
1748 /* Set the DT bit according to ETH DropTCPIPChecksumErrorFrame value */
1749 /* Set the RSF bit according to ETH ReceiveStoreForward value */
1750 /* Set the DFF bit according to ETH FlushReceivedFrame value */
1751 /* Set the TSF bit according to ETH TransmitStoreForward value */
1752 /* Set the TTC bit according to ETH TransmitThresholdControl value */
1753 /* Set the FEF bit according to ETH ForwardErrorFrames value */
1754 /* Set the FUF bit according to ETH ForwardUndersizedGoodFrames value */
1755 /* Set the RTC bit according to ETH ReceiveThresholdControl value */
1756 /* Set the OSF bit according to ETH SecondFrameOperate value */
1757 tmpreg |= (uint32_t)(dmainit.DropTCPIPChecksumErrorFrame |
1758 dmainit.ReceiveStoreForward |
1759 dmainit.FlushReceivedFrame |
1760 dmainit.TransmitStoreForward |
1761 dmainit.TransmitThresholdControl |
1762 dmainit.ForwardErrorFrames |
1763 dmainit.ForwardUndersizedGoodFrames |
1764 dmainit.ReceiveThresholdControl |
1765 dmainit.SecondFrameOperate);
1767 /* Write to ETHERNET DMAOMR */
1768 (heth->Instance)->DMAOMR = (uint32_t)tmpreg;
1770 /* Wait until the write operation will be taken into account:
1771 at least four TX_CLK/RX_CLK clock cycles */
1772 tmpreg = (heth->Instance)->DMAOMR;
1773 HAL_Delay(ETH_REG_WRITE_DELAY);
1774 (heth->Instance)->DMAOMR = tmpreg;
1776 /*----------------------- ETHERNET DMABMR Configuration ------------------*/
1777 /* Set the AAL bit according to ETH AddressAlignedBeats value */
1778 /* Set the FB bit according to ETH FixedBurst value */
1779 /* Set the RPBL and 4*PBL bits according to ETH RxDMABurstLength value */
1780 /* Set the PBL and 4*PBL bits according to ETH TxDMABurstLength value */
1781 /* Set the DSL bit according to ETH DesciptorSkipLength value */
1782 /* Set the PR and DA bits according to ETH DMAArbitration value */
1783 (heth->Instance)->DMABMR = (uint32_t)(dmainit.AddressAlignedBeats |
1784 dmainit.FixedBurst |
1785 dmainit.RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
1786 dmainit.TxDMABurstLength |
1787 (dmainit.DescriptorSkipLength << 2) |
1788 dmainit.DMAArbitration |
1789 ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
1791 /* Wait until the write operation will be taken into account:
1792 at least four TX_CLK/RX_CLK clock cycles */
1793 tmpreg = (heth->Instance)->DMABMR;
1794 HAL_Delay(ETH_REG_WRITE_DELAY);
1795 (heth->Instance)->DMABMR = tmpreg;
1797 if((heth->Init).RxMode == ETH_RXINTERRUPT_MODE)
1799 /* Enable the Ethernet Rx Interrupt */
1800 __HAL_ETH_DMA_ENABLE_IT((heth), ETH_DMA_IT_NIS | ETH_DMA_IT_R);
1803 /* Initialize MAC address in ethernet MAC */
1804 ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr);
1808 * @brief Configures the selected MAC address.
1809 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1810 * the configuration information for ETHERNET module
1811 * @param MacAddr: The MAC address to configure
1812 * This parameter can be one of the following values:
1813 * @arg ETH_MAC_Address0: MAC Address0
1814 * @arg ETH_MAC_Address1: MAC Address1
1815 * @arg ETH_MAC_Address2: MAC Address2
1816 * @arg ETH_MAC_Address3: MAC Address3
1817 * @param Addr: Pointer to MAC address buffer data (6 bytes)
1818 * @retval HAL status
1820 static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr)
1824 /* Check the parameters */
1825 assert_param(IS_ETH_MAC_ADDRESS0123(MacAddr));
1827 /* Calculate the selected MAC address high register */
1828 tmpreg = ((uint32_t)Addr[5] << 8) | (uint32_t)Addr[4];
1829 /* Load the selected MAC address high register */
1830 (*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_HBASE + MacAddr))) = tmpreg;
1831 /* Calculate the selected MAC address low register */
1832 tmpreg = ((uint32_t)Addr[3] << 24) | ((uint32_t)Addr[2] << 16) | ((uint32_t)Addr[1] << 8) | Addr[0];
1834 /* Load the selected MAC address low register */
1835 (*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_LBASE + MacAddr))) = tmpreg;
1839 * @brief Enables the MAC transmission.
1840 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1841 * the configuration information for ETHERNET module
1844 static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth)
1846 __IO uint32_t tmpreg = 0;
1848 /* Enable the MAC transmission */
1849 (heth->Instance)->MACCR |= ETH_MACCR_TE;
1851 /* Wait until the write operation will be taken into account:
1852 at least four TX_CLK/RX_CLK clock cycles */
1853 tmpreg = (heth->Instance)->MACCR;
1854 HAL_Delay(ETH_REG_WRITE_DELAY);
1855 (heth->Instance)->MACCR = tmpreg;
1859 * @brief Disables the MAC transmission.
1860 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1861 * the configuration information for ETHERNET module
1864 static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth)
1866 __IO uint32_t tmpreg = 0;
1868 /* Disable the MAC transmission */
1869 (heth->Instance)->MACCR &= ~ETH_MACCR_TE;
1871 /* Wait until the write operation will be taken into account:
1872 at least four TX_CLK/RX_CLK clock cycles */
1873 tmpreg = (heth->Instance)->MACCR;
1874 HAL_Delay(ETH_REG_WRITE_DELAY);
1875 (heth->Instance)->MACCR = tmpreg;
1879 * @brief Enables the MAC reception.
1880 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1881 * the configuration information for ETHERNET module
1884 static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth)
1886 __IO uint32_t tmpreg = 0;
1888 /* Enable the MAC reception */
1889 (heth->Instance)->MACCR |= ETH_MACCR_RE;
1891 /* Wait until the write operation will be taken into account:
1892 at least four TX_CLK/RX_CLK clock cycles */
1893 tmpreg = (heth->Instance)->MACCR;
1894 HAL_Delay(ETH_REG_WRITE_DELAY);
1895 (heth->Instance)->MACCR = tmpreg;
1899 * @brief Disables the MAC reception.
1900 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1901 * the configuration information for ETHERNET module
1904 static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth)
1906 __IO uint32_t tmpreg = 0;
1908 /* Disable the MAC reception */
1909 (heth->Instance)->MACCR &= ~ETH_MACCR_RE;
1911 /* Wait until the write operation will be taken into account:
1912 at least four TX_CLK/RX_CLK clock cycles */
1913 tmpreg = (heth->Instance)->MACCR;
1914 HAL_Delay(ETH_REG_WRITE_DELAY);
1915 (heth->Instance)->MACCR = tmpreg;
1919 * @brief Enables the DMA transmission.
1920 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1921 * the configuration information for ETHERNET module
1924 static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth)
1926 /* Enable the DMA transmission */
1927 (heth->Instance)->DMAOMR |= ETH_DMAOMR_ST;
1931 * @brief Disables the DMA transmission.
1932 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1933 * the configuration information for ETHERNET module
1936 static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth)
1938 /* Disable the DMA transmission */
1939 (heth->Instance)->DMAOMR &= ~ETH_DMAOMR_ST;
1943 * @brief Enables the DMA reception.
1944 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1945 * the configuration information for ETHERNET module
1948 static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth)
1950 /* Enable the DMA reception */
1951 (heth->Instance)->DMAOMR |= ETH_DMAOMR_SR;
1955 * @brief Disables the DMA reception.
1956 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1957 * the configuration information for ETHERNET module
1960 static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth)
1962 /* Disable the DMA reception */
1963 (heth->Instance)->DMAOMR &= ~ETH_DMAOMR_SR;
1967 * @brief Clears the ETHERNET transmit FIFO.
1968 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
1969 * the configuration information for ETHERNET module
1972 static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth)
1974 __IO uint32_t tmpreg = 0;
1976 /* Set the Flush Transmit FIFO bit */
1977 (heth->Instance)->DMAOMR |= ETH_DMAOMR_FTF;
1979 /* Wait until the write operation will be taken into account:
1980 at least four TX_CLK/RX_CLK clock cycles */
1981 tmpreg = (heth->Instance)->DMAOMR;
1982 HAL_Delay(ETH_REG_WRITE_DELAY);
1983 (heth->Instance)->DMAOMR = tmpreg;
1990 #endif /* HAL_ETH_MODULE_ENABLED */
1995 #endif /* STM32F107xC */
2000 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/