stm32f7xx_hal_eth.c 71 KB

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