123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- #include "stm32f4x7_eth.h"
- #include "stm32f4x7_eth_bsp.h"
- __IO uint32_t EthInitStatus = 0;
- static void ETH_GPIO_Config(void);
- static void ETH_MACDMA_Config(void);
- static void ETH_NVIC_Config(void);
- void ETH_BSP_Config(void)
- {
-
- ETH_GPIO_Config();
-
-
-
- ETH_MACDMA_Config();
- ETH_NVIC_Config();
- if (EthInitStatus == 0) {
-
-
-
-
- while(1);
- }
- }
- static void ETH_MACDMA_Config(void)
- {
- ETH_InitTypeDef ETH_InitStructure;
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC | RCC_AHB1Periph_ETH_MAC_Tx |
- RCC_AHB1Periph_ETH_MAC_Rx, ENABLE);
-
- ETH_DeInit();
-
- ETH_SoftwareReset();
-
- while (ETH_GetSoftwareResetStatus() == SET);
-
-
- ETH_StructInit(Ð_InitStructure);
-
-
- ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;
-
-
-
- ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable;
- ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable;
- ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
- ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable;
- ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable;
- ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
- ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
- ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
- #ifdef CHECKSUM_BY_HARDWARE
- ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable;
- #endif
-
-
-
- ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable;
- ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable;
- ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable;
-
- ETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable;
- ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable;
- ETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable;
- ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;
- ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable;
- ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat;
- ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat;
- ETH_InitStructure.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1;
-
- EthInitStatus = ETH_Init(Ð_InitStructure, LAN8720_PHY_ADDRESS);
-
- ETH_DMAITConfig(ETH_DMA_IT_NIS | ETH_DMA_IT_R, ENABLE);
- }
- void ETH_GPIO_Config(void)
- {
- volatile uint32_t i;
- GPIO_InitTypeDef GPIO_InitStructure;
-
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB
- | RCC_AHB1Periph_GPIOC, ENABLE);
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
-
-
- SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII);
-
- #ifdef HARDWARE_BT6711
- #define ETH_RST_PIN GPIO_Pin_7
- #else
- #define ETH_RST_PIN GPIO_Pin_13
- #endif
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_ETH);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_ETH);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_ETH);
-
- GPIO_InitStructure.GPIO_Pin = ETH_RST_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- GPIO_ResetBits(GPIOE, ETH_RST_PIN);
- for (i = 0; i < 20000; i++);
- GPIO_SetBits(GPIOE, ETH_RST_PIN);
- for (i = 0; i < 20000; i++);
- }
- void ETH_NVIC_Config(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
-
-
- NVIC_InitStructure.NVIC_IRQChannel = ETH_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
|