eth.c 68 KB

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