stm32f4xx_hal_eth.c 70 KB

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