stm32f1xx_hal_eth.c 71 KB

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