stm32f7xx_hal_eth.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044
  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****/