11/*
2- * Copyright (c) 2006-2018 , RT-Thread Development Team
2+ * Copyright (c) 2006-2021 , RT-Thread Development Team
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 *
2828//#define DRV_DEBUG
2929#define LOG_TAG "drv.emac"
3030
31- #define ETH_RXBUFNB 4
32- #define ETH_TXBUFNB 2
31+ #define ETH_RXBUFNB 4
32+ #define ETH_TXBUFNB 2
3333
3434#define LINK_THREAD_STACK_SIZE 256
3535#define LINK_THREAD_PREORITY 21
@@ -131,14 +131,14 @@ void NVIC_Configuration(void)
131131 NVIC_SetVectorTable (NVIC_VectTab_FLASH , 0x0 );
132132
133133 /* 2 bit for pre-emption priority, 2 bits for subpriority */
134- NVIC_PriorityGroupConfig (NVIC_PriorityGroup_2 );
134+ NVIC_PriorityGroupConfig (NVIC_PriorityGroup_2 );
135135
136136 /* Enable the Ethernet global Interrupt */
137137 NVIC_InitStructure .NVIC_IRQChannel = ETH_IRQn ;
138138 NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 0 ;
139139 NVIC_InitStructure .NVIC_IRQChannelSubPriority = 0 ;
140140 NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE ;
141- NVIC_Init (& NVIC_InitStructure );
141+ NVIC_Init (& NVIC_InitStructure );
142142}
143143
144144/**
@@ -173,7 +173,7 @@ void GPIO_Configuration(void)
173173 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_AF_PP ;
174174 GPIO_Init (GPIOC , & GPIO_InitStructure );
175175
176- /*MII Mode GPIO configuration*/
176+ /*MII Mode GPIO configuration*/
177177#ifdef MII_MODE
178178/**********************MII Tx Pin Define****************************/
179179 /*
@@ -193,7 +193,7 @@ void GPIO_Configuration(void)
193193 GPIO_InitStructure .GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz ;
194194 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_AF_PP ;
195195 GPIO_Init (GPIOC , & GPIO_InitStructure );
196- /**********************MII Rx Pin Define****************************/
196+ /**********************MII Rx Pin Define****************************/
197197#if MII_RX_REMAP /*IO PIN remaped*/
198198 /*
199199 ETH_MII_RX_DV-->PD8
@@ -208,7 +208,7 @@ void GPIO_Configuration(void)
208208 */
209209 GPIO_InitStructure .GPIO_Pins = GPIO_Pins_8 | GPIO_Pins_9 | GPIO_Pins_10 | GPIO_Pins_11 | GPIO_Pins_12 ;
210210 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
211- GPIO_Init (GPIOD , & GPIO_InitStructure );
211+ GPIO_Init (GPIOD , & GPIO_InitStructure );
212212
213213 GPIO_InitStructure .GPIO_Pins = GPIO_Pins_0 | GPIO_Pins_1 | GPIO_Pins_3 ;
214214 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
@@ -233,11 +233,11 @@ void GPIO_Configuration(void)
233233 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
234234 GPIO_Init (GPIOA , & GPIO_InitStructure );
235235
236- GPIO_InitStructure .GPIO_Pins = GPIO_Pins_4 | GPIO_Pins_5 ;
236+ GPIO_InitStructure .GPIO_Pins = GPIO_Pins_4 | GPIO_Pins_5 ;
237237 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
238238 GPIO_Init (GPIOC , & GPIO_InitStructure );
239239
240- GPIO_InitStructure .GPIO_Pins = GPIO_Pins_0 | GPIO_Pins_1 | GPIO_Pins_10 ;
240+ GPIO_InitStructure .GPIO_Pins = GPIO_Pins_0 | GPIO_Pins_1 | GPIO_Pins_10 ;
241241 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
242242 GPIO_Init (GPIOB , & GPIO_InitStructure );
243243
@@ -255,8 +255,8 @@ void GPIO_Configuration(void)
255255 GPIO_InitStructure .GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz ;
256256 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_AF_PP ;
257257 GPIO_Init (GPIOB , & GPIO_InitStructure );
258-
259- /**********************RMII Rx Pin Define****************************/
258+
259+ /**********************RMII Rx Pin Define****************************/
260260#if MII_RX_REMAP /*IO PIN remaped*/
261261 /*
262262 ETH_RMII_RX_DV-->PD8
@@ -266,7 +266,7 @@ void GPIO_Configuration(void)
266266 */
267267 GPIO_InitStructure .GPIO_Pins = GPIO_Pins_8 | GPIO_Pins_9 | GPIO_Pins_10 ;
268268 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
269- GPIO_Init (GPIOD , & GPIO_InitStructure );
269+ GPIO_Init (GPIOD , & GPIO_InitStructure );
270270
271271 GPIO_InitStructure .GPIO_Pins = GPIO_Pins_1 ;
272272 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
@@ -282,7 +282,7 @@ void GPIO_Configuration(void)
282282 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
283283 GPIO_Init (GPIOA , & GPIO_InitStructure );
284284
285- GPIO_InitStructure .GPIO_Pins = GPIO_Pins_4 | GPIO_Pins_5 ;
285+ GPIO_InitStructure .GPIO_Pins = GPIO_Pins_4 | GPIO_Pins_5 ;
286286 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
287287 GPIO_Init (GPIOC , & GPIO_InitStructure );
288288
@@ -314,7 +314,7 @@ static rt_err_t rt_at32_eth_init(rt_device_t dev)
314314
315315 RCC_AHBPeriphClockCmd (RCC_AHBPERIPH_ETHMAC | RCC_AHBPERIPH_ETHMACTX |
316316 RCC_AHBPERIPH_ETHMACRX , ENABLE );
317-
317+
318318 /* MII/RMII Media interface selection ------------------------------------------*/
319319#ifdef MII_MODE /* Mode MII with AT32F407-EVAL */
320320 GPIO_ETH_MediaInterfaceConfig (GPIO_ETH_MediaInterface_MII );
@@ -361,31 +361,31 @@ static rt_err_t rt_at32_eth_init(rt_device_t dev)
361361 ETH_InitStructure .ETH_ChecksumOffload = ETH_ChecksumOffload_Enable ;
362362#endif
363363
364- /*------------------------ DMA -----------------------------------*/
364+ /*------------------------ DMA -----------------------------------*/
365365
366- /* When we use the Checksum offload feature, we need to enable the Store and Forward mode:
367- the store and forward guarantee that a whole frame is stored in the FIFO, so the MAC can insert/verify the checksum,
366+ /* When we use the Checksum offload feature, we need to enable the Store and Forward mode:
367+ the store and forward guarantee that a whole frame is stored in the FIFO, so the MAC can insert/verify the checksum,
368368 if the checksum is OK the DMA can handle the frame otherwise the frame is dropped */
369- ETH_InitStructure .ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable ;//ETH_DropTCPIPChecksumErrorFrame_Enable;
370- ETH_InitStructure .ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable ;
371- ETH_InitStructure .ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable ;
372-
373- ETH_InitStructure .ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable ;
374- ETH_InitStructure .ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable ;
375- ETH_InitStructure .ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable ;
376- ETH_InitStructure .ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable ;
377- ETH_InitStructure .ETH_FixedBurst = ETH_FixedBurst_Enable ;
378- ETH_InitStructure .ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat ;
379- ETH_InitStructure .ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat ;
369+ ETH_InitStructure .ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable ;//ETH_DropTCPIPChecksumErrorFrame_Enable;
370+ ETH_InitStructure .ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable ;
371+ ETH_InitStructure .ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable ;
372+
373+ ETH_InitStructure .ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable ;
374+ ETH_InitStructure .ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable ;
375+ ETH_InitStructure .ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable ;
376+ ETH_InitStructure .ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable ;
377+ ETH_InitStructure .ETH_FixedBurst = ETH_FixedBurst_Enable ;
378+ ETH_InitStructure .ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat ;
379+ ETH_InitStructure .ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat ;
380380 ETH_InitStructure .ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1 ;
381381
382382 /* Configure Ethernet, check error */
383383 if (ETH_Init (& ETH_InitStructure , PHY_ADDRESS ) == ((uint32_t )0 )) {
384384 return RT_ERROR ;
385- }
385+ }
386386
387387 /* Enable DMA Receive interrupt (need to enable in this case Normal interrupt) */
388- ETH_DMAITConfig (ETH_DMA_INT_NIS | ETH_DMA_INT_R , ENABLE );
388+ ETH_DMAITConfig (ETH_DMA_INT_NIS | ETH_DMA_INT_R , ENABLE );
389389
390390 /* Initialize Tx Descriptors list: Chain Mode */
391391 ETH_DMATxDescChainInit (DMATxDscrTab , & Tx_Buff [0 ][0 ], ETH_TXBUFNB );
@@ -396,7 +396,7 @@ static rt_err_t rt_at32_eth_init(rt_device_t dev)
396396 ETH_MACAddressConfig (ETH_MAC_Address0 , (u8 * )& at32_eth_device .dev_addr [0 ]);
397397
398398 /* Enable ETH transmition and recetion */
399- ETH_Start ();
399+ ETH_Start ();
400400
401401 return RT_EOK ;
402402}
@@ -581,7 +581,7 @@ struct pbuf *rt_at32_eth_rx(rt_device_t dev)
581581 {
582582 rt_uint32_t i ;
583583 rt_uint8_t * ptr = (rt_uint8_t * )(DMARxDescToGet -> Buffer1Addr );
584-
584+
585585 AT32_ETH_PRINTF ("rx_dump, len:%d\r\n" , p -> tot_len );
586586 for (i = 0 ; i < p -> tot_len ; i ++ )
587587 {
0 commit comments