stm32h7xx_hal_eth_ex.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_eth_ex.c
  4. * @author MCD Application Team
  5. * @brief ETH HAL Extended module driver.
  6. *
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2017 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32h7xx_hal.h"
  21. /** @addtogroup STM32H7xx_HAL_Driver
  22. * @{
  23. */
  24. #ifdef HAL_ETH_MODULE_ENABLED
  25. #if defined(ETH)
  26. /** @defgroup ETHEx ETHEx
  27. * @brief ETH HAL Extended module driver
  28. * @{
  29. */
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* Private define ------------------------------------------------------------*/
  32. /** @defgroup ETHEx_Private_Constants ETHEx Private Constants
  33. * @{
  34. */
  35. #define ETH_MACL4CR_MASK (ETH_MACL3L4CR_L4PEN | ETH_MACL3L4CR_L4SPM | \
  36. ETH_MACL3L4CR_L4SPIM | ETH_MACL3L4CR_L4DPM | \
  37. ETH_MACL3L4CR_L4DPIM)
  38. #define ETH_MACL3CR_MASK (ETH_MACL3L4CR_L3PEN | ETH_MACL3L4CR_L3SAM | \
  39. ETH_MACL3L4CR_L3SAIM | ETH_MACL3L4CR_L3DAM | \
  40. ETH_MACL3L4CR_L3DAIM | ETH_MACL3L4CR_L3HSBM | \
  41. ETH_MACL3L4CR_L3HDBM)
  42. #define ETH_MACRXVLAN_MASK (ETH_MACVTR_EIVLRXS | ETH_MACVTR_EIVLS | \
  43. ETH_MACVTR_ERIVLT | ETH_MACVTR_EDVLP | \
  44. ETH_MACVTR_VTHM | ETH_MACVTR_EVLRXS | \
  45. ETH_MACVTR_EVLS | ETH_MACVTR_DOVLTC | \
  46. ETH_MACVTR_ERSVLM | ETH_MACVTR_ESVL | \
  47. ETH_MACVTR_VTIM | ETH_MACVTR_ETV)
  48. #define ETH_MACTXVLAN_MASK (ETH_MACVIR_VLTI | ETH_MACVIR_CSVL | \
  49. ETH_MACVIR_VLP | ETH_MACVIR_VLC)
  50. /**
  51. * @}
  52. */
  53. /* Private macros ------------------------------------------------------------*/
  54. /* Private function prototypes -----------------------------------------------*/
  55. /* Exported functions ---------------------------------------------------------*/
  56. /** @defgroup ETHEx_Exported_Functions ETH Extended Exported Functions
  57. * @{
  58. */
  59. /** @defgroup ETHEx_Exported_Functions_Group1 Extended features functions
  60. * @brief Extended features functions
  61. *
  62. @verbatim
  63. ===============================================================================
  64. ##### Extended features functions #####
  65. ===============================================================================
  66. [..] This section provides functions allowing to:
  67. (+) Configure ARP offload module
  68. (+) Configure L3 and L4 filters
  69. (+) Configure Extended VLAN features
  70. (+) Configure Energy Efficient Ethernet module
  71. @endverbatim
  72. * @{
  73. */
  74. /**
  75. * @brief Enables ARP Offload.
  76. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  77. * the configuration information for ETHERNET module
  78. * @retval None
  79. */
  80. void HAL_ETHEx_EnableARPOffload(ETH_HandleTypeDef *heth)
  81. {
  82. SET_BIT(heth->Instance->MACCR, ETH_MACCR_ARP);
  83. }
  84. /**
  85. * @brief Disables ARP Offload.
  86. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  87. * the configuration information for ETHERNET module
  88. * @retval None
  89. */
  90. void HAL_ETHEx_DisableARPOffload(ETH_HandleTypeDef *heth)
  91. {
  92. CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_ARP);
  93. }
  94. /**
  95. * @brief Set the ARP Match IP address
  96. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  97. * the configuration information for ETHERNET module
  98. * @param IpAddress: IP Address to be matched for incoming ARP requests
  99. * @retval None
  100. */
  101. void HAL_ETHEx_SetARPAddressMatch(ETH_HandleTypeDef *heth, uint32_t IpAddress)
  102. {
  103. WRITE_REG(heth->Instance->MACARPAR, IpAddress);
  104. }
  105. /**
  106. * @brief Configures the L4 Filter, this function allow to:
  107. * set the layer 4 protocol to be matched (TCP or UDP)
  108. * enable/disable L4 source/destination port perfect/inverse match.
  109. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  110. * the configuration information for ETHERNET module
  111. * @param Filter: L4 filter to configured, this parameter must be one of the following
  112. * ETH_L4_FILTER_0
  113. * ETH_L4_FILTER_1
  114. * @param pL4FilterConfig: pointer to a ETH_L4FilterConfigTypeDef structure
  115. * that contains L4 filter configuration.
  116. * @retval HAL status
  117. */
  118. HAL_StatusTypeDef HAL_ETHEx_SetL4FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter,
  119. ETH_L4FilterConfigTypeDef *pL4FilterConfig)
  120. {
  121. __IO uint32_t *configreg = ((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter));
  122. if (pL4FilterConfig == NULL)
  123. {
  124. return HAL_ERROR;
  125. }
  126. /* Write configuration to (MACL3L4C0R + filter )register */
  127. MODIFY_REG(*configreg, ETH_MACL4CR_MASK, (pL4FilterConfig->Protocol |
  128. pL4FilterConfig->SrcPortFilterMatch |
  129. pL4FilterConfig->DestPortFilterMatch));
  130. configreg = ((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter));
  131. /* Write configuration to (MACL4A0R + filter )register */
  132. MODIFY_REG(*configreg, (ETH_MACL4AR_L4DP | ETH_MACL4AR_L4SP), (pL4FilterConfig->SourcePort |
  133. (pL4FilterConfig->DestinationPort << 16)));
  134. /* Enable L4 filter */
  135. SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
  136. return HAL_OK;
  137. }
  138. /**
  139. * @brief Configures the L4 Filter, this function allow to:
  140. * set the layer 4 protocol to be matched (TCP or UDP)
  141. * enable/disable L4 source/destination port perfect/inverse match.
  142. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  143. * the configuration information for ETHERNET module
  144. * @param Filter: L4 filter to configured, this parameter must be one of the following
  145. * ETH_L4_FILTER_0
  146. * ETH_L4_FILTER_1
  147. * @param pL4FilterConfig: pointer to a ETH_L4FilterConfigTypeDef structure
  148. * that contains L4 filter configuration.
  149. * @retval HAL status
  150. */
  151. HAL_StatusTypeDef HAL_ETHEx_GetL4FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter,
  152. ETH_L4FilterConfigTypeDef *pL4FilterConfig)
  153. {
  154. if (pL4FilterConfig == NULL)
  155. {
  156. return HAL_ERROR;
  157. }
  158. /* Get configuration to (MACL3L4C0R + filter )register */
  159. pL4FilterConfig->Protocol = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)),
  160. ETH_MACL3L4CR_L4PEN);
  161. pL4FilterConfig->DestPortFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)),
  162. (ETH_MACL3L4CR_L4DPM | ETH_MACL3L4CR_L4DPIM));
  163. pL4FilterConfig->SrcPortFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)),
  164. (ETH_MACL3L4CR_L4SPM | ETH_MACL3L4CR_L4SPIM));
  165. /* Get configuration to (MACL3L4C0R + filter )register */
  166. pL4FilterConfig->DestinationPort = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter)),
  167. ETH_MACL4AR_L4DP) >> 16);
  168. pL4FilterConfig->SourcePort = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL4A0R) + Filter)), ETH_MACL4AR_L4SP);
  169. return HAL_OK;
  170. }
  171. /**
  172. * @brief Configures the L3 Filter, this function allow to:
  173. * set the layer 3 protocol to be matched (IPv4 or IPv6)
  174. * enable/disable L3 source/destination port perfect/inverse match.
  175. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  176. * the configuration information for ETHERNET module
  177. * @param Filter: L3 filter to configured, this parameter must be one of the following
  178. * ETH_L3_FILTER_0
  179. * ETH_L3_FILTER_1
  180. * @param pL3FilterConfig: pointer to a ETH_L3FilterConfigTypeDef structure
  181. * that contains L3 filter configuration.
  182. * @retval HAL status
  183. */
  184. HAL_StatusTypeDef HAL_ETHEx_SetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter,
  185. ETH_L3FilterConfigTypeDef *pL3FilterConfig)
  186. {
  187. __IO uint32_t *configreg = ((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter));
  188. if (pL3FilterConfig == NULL)
  189. {
  190. return HAL_ERROR;
  191. }
  192. /* Write configuration to (MACL3L4C0R + filter )register */
  193. MODIFY_REG(*configreg, ETH_MACL3CR_MASK, (pL3FilterConfig->Protocol |
  194. pL3FilterConfig->SrcAddrFilterMatch |
  195. pL3FilterConfig->DestAddrFilterMatch |
  196. (pL3FilterConfig->SrcAddrHigherBitsMatch << 6) |
  197. (pL3FilterConfig->DestAddrHigherBitsMatch << 11)));
  198. /* Check if IPv6 protocol is selected */
  199. if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
  200. {
  201. /* Set the IPv6 address match */
  202. /* Set Bits[31:0] of 128-bit IP addr */
  203. *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter)) = pL3FilterConfig->Ip6Addr[0];
  204. /* Set Bits[63:32] of 128-bit IP addr */
  205. *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter)) = pL3FilterConfig->Ip6Addr[1];
  206. /* update Bits[95:64] of 128-bit IP addr */
  207. *((__IO uint32_t *)(&(heth->Instance->MACL3A2R0R) + Filter)) = pL3FilterConfig->Ip6Addr[2];
  208. /* update Bits[127:96] of 128-bit IP addr */
  209. *((__IO uint32_t *)(&(heth->Instance->MACL3A3R0R) + Filter)) = pL3FilterConfig->Ip6Addr[3];
  210. }
  211. else /* IPv4 protocol is selected */
  212. {
  213. /* Set the IPv4 source address match */
  214. *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter)) = pL3FilterConfig->Ip4SrcAddr;
  215. /* Set the IPv4 destination address match */
  216. *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter)) = pL3FilterConfig->Ip4DestAddr;
  217. }
  218. return HAL_OK;
  219. }
  220. /**
  221. * @brief Configures the L3 Filter, this function allow to:
  222. * set the layer 3 protocol to be matched (IPv4 or IPv6)
  223. * enable/disable L3 source/destination port perfect/inverse match.
  224. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  225. * the configuration information for ETHERNET module
  226. * @param Filter: L3 filter to configured, this parameter must be one of the following
  227. * ETH_L3_FILTER_0
  228. * ETH_L3_FILTER_1
  229. * @param pL3FilterConfig: pointer to a ETH_L3FilterConfigTypeDef structure
  230. * that will contain the L3 filter configuration.
  231. * @retval HAL status
  232. */
  233. HAL_StatusTypeDef HAL_ETHEx_GetL3FilterConfig(ETH_HandleTypeDef *heth, uint32_t Filter,
  234. ETH_L3FilterConfigTypeDef *pL3FilterConfig)
  235. {
  236. if (pL3FilterConfig == NULL)
  237. {
  238. return HAL_ERROR;
  239. }
  240. pL3FilterConfig->Protocol = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)),
  241. ETH_MACL3L4CR_L3PEN);
  242. pL3FilterConfig->SrcAddrFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)),
  243. (ETH_MACL3L4CR_L3SAM | ETH_MACL3L4CR_L3SAIM));
  244. pL3FilterConfig->DestAddrFilterMatch = READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)),
  245. (ETH_MACL3L4CR_L3DAM | ETH_MACL3L4CR_L3DAIM));
  246. pL3FilterConfig->SrcAddrHigherBitsMatch = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)),
  247. ETH_MACL3L4CR_L3HSBM) >> 6);
  248. pL3FilterConfig->DestAddrHigherBitsMatch = (READ_BIT(*((__IO uint32_t *)(&(heth->Instance->MACL3L4C0R) + Filter)),
  249. ETH_MACL3L4CR_L3HDBM) >> 11);
  250. if (pL3FilterConfig->Protocol != ETH_L3_IPV4_MATCH)
  251. {
  252. pL3FilterConfig->Ip6Addr[0] = *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter));
  253. pL3FilterConfig->Ip6Addr[1] = *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter));
  254. pL3FilterConfig->Ip6Addr[2] = *((__IO uint32_t *)(&(heth->Instance->MACL3A2R0R) + Filter));
  255. pL3FilterConfig->Ip6Addr[3] = *((__IO uint32_t *)(&(heth->Instance->MACL3A3R0R) + Filter));
  256. }
  257. else
  258. {
  259. pL3FilterConfig->Ip4SrcAddr = *((__IO uint32_t *)(&(heth->Instance->MACL3A0R0R) + Filter));
  260. pL3FilterConfig->Ip4DestAddr = *((__IO uint32_t *)(&(heth->Instance->MACL3A1R0R) + Filter));
  261. }
  262. return HAL_OK;
  263. }
  264. /**
  265. * @brief Enables L3 and L4 filtering process.
  266. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  267. * the configuration information for ETHERNET module
  268. * @retval None.
  269. */
  270. void HAL_ETHEx_EnableL3L4Filtering(ETH_HandleTypeDef *heth)
  271. {
  272. /* Enable L3/L4 filter */
  273. SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
  274. }
  275. /**
  276. * @brief Disables L3 and L4 filtering process.
  277. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  278. * the configuration information for ETHERNET module
  279. * @retval None.
  280. */
  281. void HAL_ETHEx_DisableL3L4Filtering(ETH_HandleTypeDef *heth)
  282. {
  283. /* Disable L3/L4 filter */
  284. CLEAR_BIT(heth->Instance->MACPFR, ETH_MACPFR_IPFE);
  285. }
  286. /**
  287. * @brief Get the VLAN Configuration for Receive Packets.
  288. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  289. * the configuration information for ETHERNET module
  290. * @param pVlanConfig: pointer to a ETH_RxVLANConfigTypeDef structure
  291. * that will contain the VLAN filter configuration.
  292. * @retval HAL status
  293. */
  294. HAL_StatusTypeDef HAL_ETHEx_GetRxVLANConfig(ETH_HandleTypeDef *heth, ETH_RxVLANConfigTypeDef *pVlanConfig)
  295. {
  296. if (pVlanConfig == NULL)
  297. {
  298. return HAL_ERROR;
  299. }
  300. pVlanConfig->InnerVLANTagInStatus = ((READ_BIT(heth->Instance->MACVTR,
  301. ETH_MACVTR_EIVLRXS) >> 31) == 0U) ? DISABLE : ENABLE;
  302. pVlanConfig->StripInnerVLANTag = READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EIVLS);
  303. pVlanConfig->InnerVLANTag = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_ERIVLT) >> 27) == 0U) ? DISABLE : ENABLE;
  304. pVlanConfig->DoubleVLANProcessing = ((READ_BIT(heth->Instance->MACVTR,
  305. ETH_MACVTR_EDVLP) >> 26) == 0U) ? DISABLE : ENABLE;
  306. pVlanConfig->VLANTagHashTableMatch = ((READ_BIT(heth->Instance->MACVTR,
  307. ETH_MACVTR_VTHM) >> 25) == 0U) ? DISABLE : ENABLE;
  308. pVlanConfig->VLANTagInStatus = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EVLRXS) >> 24) == 0U) ? DISABLE : ENABLE;
  309. pVlanConfig->StripVLANTag = READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_EVLS);
  310. pVlanConfig->VLANTypeCheck = READ_BIT(heth->Instance->MACVTR,
  311. (ETH_MACVTR_DOVLTC | ETH_MACVTR_ERSVLM | ETH_MACVTR_ESVL));
  312. pVlanConfig->VLANTagInverceMatch = ((READ_BIT(heth->Instance->MACVTR, ETH_MACVTR_VTIM) >> 17) == 0U)
  313. ? DISABLE : ENABLE;
  314. return HAL_OK;
  315. }
  316. /**
  317. * @brief Set the VLAN Configuration for Receive Packets.
  318. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  319. * the configuration information for ETHERNET module
  320. * @param pVlanConfig: pointer to a ETH_RxVLANConfigTypeDef structure
  321. * that contains VLAN filter configuration.
  322. * @retval HAL status
  323. */
  324. HAL_StatusTypeDef HAL_ETHEx_SetRxVLANConfig(ETH_HandleTypeDef *heth, ETH_RxVLANConfigTypeDef *pVlanConfig)
  325. {
  326. if (pVlanConfig == NULL)
  327. {
  328. return HAL_ERROR;
  329. }
  330. /* Write config to MACVTR */
  331. MODIFY_REG(heth->Instance->MACVTR, ETH_MACRXVLAN_MASK, (((uint32_t)pVlanConfig->InnerVLANTagInStatus << 31) |
  332. pVlanConfig->StripInnerVLANTag |
  333. ((uint32_t)pVlanConfig->InnerVLANTag << 27) |
  334. ((uint32_t)pVlanConfig->DoubleVLANProcessing << 26) |
  335. ((uint32_t)pVlanConfig->VLANTagHashTableMatch << 25) |
  336. ((uint32_t)pVlanConfig->VLANTagInStatus << 24) |
  337. pVlanConfig->StripVLANTag |
  338. pVlanConfig->VLANTypeCheck |
  339. ((uint32_t)pVlanConfig->VLANTagInverceMatch << 17)));
  340. return HAL_OK;
  341. }
  342. /**
  343. * @brief Set the VLAN Hash Table
  344. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  345. * the configuration information for ETHERNET module
  346. * @param VLANHashTable: VLAN hash table 16 bit value
  347. * @retval None
  348. */
  349. void HAL_ETHEx_SetVLANHashTable(ETH_HandleTypeDef *heth, uint32_t VLANHashTable)
  350. {
  351. MODIFY_REG(heth->Instance->MACVHTR, ETH_MACVHTR_VLHT, VLANHashTable);
  352. }
  353. /**
  354. * @brief Get the VLAN Configuration for Transmit Packets.
  355. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  356. * the configuration information for ETHERNET module
  357. * @param VLANTag: Selects the vlan tag, this parameter must be one of the following
  358. * ETH_OUTER_TX_VLANTAG
  359. * ETH_INNER_TX_VLANTAG
  360. * @param pVlanConfig: pointer to a ETH_TxVLANConfigTypeDef structure
  361. * that will contain the Tx VLAN filter configuration.
  362. * @retval HAL Status.
  363. */
  364. HAL_StatusTypeDef HAL_ETHEx_GetTxVLANConfig(ETH_HandleTypeDef *heth, uint32_t VLANTag,
  365. ETH_TxVLANConfigTypeDef *pVlanConfig)
  366. {
  367. if (pVlanConfig == NULL)
  368. {
  369. return HAL_ERROR;
  370. }
  371. if (VLANTag == ETH_INNER_TX_VLANTAG)
  372. {
  373. pVlanConfig->SourceTxDesc = ((READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_VLTI) >> 20) == 0U) ? DISABLE : ENABLE;
  374. pVlanConfig->SVLANType = ((READ_BIT(heth->Instance->MACIVIR, ETH_MACVIR_CSVL) >> 19) == 0U) ? DISABLE : ENABLE;
  375. pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACIVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
  376. }
  377. else
  378. {
  379. pVlanConfig->SourceTxDesc = ((READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_VLTI) >> 20) == 0U) ? DISABLE : ENABLE;
  380. pVlanConfig->SVLANType = ((READ_BIT(heth->Instance->MACVIR, ETH_MACVIR_CSVL) >> 19) == 0U) ? DISABLE : ENABLE;
  381. pVlanConfig->VLANTagControl = READ_BIT(heth->Instance->MACVIR, (ETH_MACVIR_VLP | ETH_MACVIR_VLC));
  382. }
  383. return HAL_OK;;
  384. }
  385. /**
  386. * @brief Set the VLAN Configuration for Transmit Packets.
  387. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  388. * the configuration information for ETHERNET module
  389. * @param VLANTag: Selects the vlan tag, this parameter must be one of the following
  390. * ETH_OUTER_TX_VLANTAG
  391. * ETH_INNER_TX_VLANTAG
  392. * @param pVlanConfig: pointer to a ETH_TxVLANConfigTypeDef structure
  393. * that contains Tx VLAN filter configuration.
  394. * @retval HAL Status
  395. */
  396. HAL_StatusTypeDef HAL_ETHEx_SetTxVLANConfig(ETH_HandleTypeDef *heth, uint32_t VLANTag,
  397. ETH_TxVLANConfigTypeDef *pVlanConfig)
  398. {
  399. if (VLANTag == ETH_INNER_TX_VLANTAG)
  400. {
  401. MODIFY_REG(heth->Instance->MACIVIR, ETH_MACTXVLAN_MASK, (((uint32_t)pVlanConfig->SourceTxDesc << 20) |
  402. ((uint32_t)pVlanConfig->SVLANType << 19) |
  403. pVlanConfig->VLANTagControl));
  404. /* Enable Double VLAN processing */
  405. SET_BIT(heth->Instance->MACVTR, ETH_MACVTR_EDVLP);
  406. }
  407. else
  408. {
  409. MODIFY_REG(heth->Instance->MACVIR, ETH_MACTXVLAN_MASK, (((uint32_t)pVlanConfig->SourceTxDesc << 20) |
  410. ((uint32_t)pVlanConfig->SVLANType << 19) |
  411. pVlanConfig->VLANTagControl));
  412. }
  413. return HAL_OK;
  414. }
  415. /**
  416. * @brief Set the VLAN Tag Identifier for Transmit Packets.
  417. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  418. * the configuration information for ETHERNET module
  419. * @param VLANTag: Selects the vlan tag, this parameter must be one of the following
  420. * ETH_OUTER_TX_VLANTAG
  421. * ETH_INNER_TX_VLANTAG
  422. * @param VLANIdentifier: VLAN Identifier 16 bit value
  423. * @retval None
  424. */
  425. void HAL_ETHEx_SetTxVLANIdentifier(ETH_HandleTypeDef *heth, uint32_t VLANTag, uint32_t VLANIdentifier)
  426. {
  427. if (VLANTag == ETH_INNER_TX_VLANTAG)
  428. {
  429. MODIFY_REG(heth->Instance->MACIVIR, ETH_MACVIR_VLT, VLANIdentifier);
  430. }
  431. else
  432. {
  433. MODIFY_REG(heth->Instance->MACVIR, ETH_MACVIR_VLT, VLANIdentifier);
  434. }
  435. }
  436. /**
  437. * @brief Enables the VLAN Tag Filtering process.
  438. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  439. * the configuration information for ETHERNET module
  440. * @retval None.
  441. */
  442. void HAL_ETHEx_EnableVLANProcessing(ETH_HandleTypeDef *heth)
  443. {
  444. /* Enable VLAN processing */
  445. SET_BIT(heth->Instance->MACPFR, ETH_MACPFR_VTFE);
  446. }
  447. /**
  448. * @brief Disables the VLAN Tag Filtering process.
  449. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  450. * the configuration information for ETHERNET module
  451. * @retval None.
  452. */
  453. void HAL_ETHEx_DisableVLANProcessing(ETH_HandleTypeDef *heth)
  454. {
  455. /* Disable VLAN processing */
  456. CLEAR_BIT(heth->Instance->MACPFR, ETH_MACPFR_VTFE);
  457. }
  458. /**
  459. * @brief Enters the Low Power Idle (LPI) mode
  460. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  461. * the configuration information for ETHERNET module
  462. * @param TxAutomate: Enable/Disable automate enter/exit LPI mode.
  463. * @param TxClockStop: Enable/Disable Tx clock stop in LPI mode.
  464. * @retval None
  465. */
  466. void HAL_ETHEx_EnterLPIMode(ETH_HandleTypeDef *heth, FunctionalState TxAutomate, FunctionalState TxClockStop)
  467. {
  468. /* Enable LPI Interrupts */
  469. __HAL_ETH_MAC_ENABLE_IT(heth, ETH_MACIER_LPIIE);
  470. /* Write to LPI Control register: Enter low power mode */
  471. MODIFY_REG(heth->Instance->MACLCSR, (ETH_MACLCSR_LPIEN | ETH_MACLCSR_LPITXA | ETH_MACLCSR_LPITCSE),
  472. (((uint32_t)TxAutomate << 19) |
  473. ((uint32_t)TxClockStop << 21) |
  474. ETH_MACLCSR_LPIEN));
  475. }
  476. /**
  477. * @brief Exits the Low Power Idle (LPI) mode.
  478. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  479. * the configuration information for ETHERNET module
  480. * @retval None
  481. */
  482. void HAL_ETHEx_ExitLPIMode(ETH_HandleTypeDef *heth)
  483. {
  484. /* Clear the LPI Config and exit low power mode */
  485. CLEAR_BIT(heth->Instance->MACLCSR, (ETH_MACLCSR_LPIEN | ETH_MACLCSR_LPITXA | ETH_MACLCSR_LPITCSE));
  486. /* Enable LPI Interrupts */
  487. __HAL_ETH_MAC_DISABLE_IT(heth, ETH_MACIER_LPIIE);
  488. }
  489. /**
  490. * @brief Returns the ETH MAC LPI event
  491. * @param heth: pointer to a ETH_HandleTypeDef structure that contains
  492. * the configuration information for ETHERNET module
  493. * @retval ETH MAC WakeUp event
  494. */
  495. uint32_t HAL_ETHEx_GetMACLPIEvent(ETH_HandleTypeDef *heth)
  496. {
  497. return heth->MACLPIEvent;
  498. }
  499. /**
  500. * @}
  501. */
  502. /**
  503. * @}
  504. */
  505. /**
  506. * @}
  507. */
  508. #endif /* ETH */
  509. #endif /* HAL_ETH_MODULE_ENABLED */
  510. /**
  511. * @}
  512. */