1.MII/RMII/SMI接口衔接和装备
SMI又称站点办理接口,用于cpu与外置PHY芯片通讯,装备相关参数,包括MDC和MDIO两个管脚(CPU上有对应引脚,当然用一般GPIO口模仿SMI办理也是可行的,不过需求自己设置时序,依照固定帧结构写入和读取数据,这个我就不详细阐明,有空我会独自将程序给出)。MII和RMII是两种以太网数据传输接口,由于RMII在运用更少接口的情况下具有RMII相同的成效,因而我主张一般选用RMII形式,如下图衔接即可:
特别注意:RMII形式下REF_CLK要衔接CPU的MCO引脚,且MCO输出时钟应为50MHz. 2.PHY初始化 一般来说,stm32外部驱动PHY芯片有两种衔接方法,MII和RMII总线,这个与硬件规划有关,不过stm32芯片一般都支撑这两种总线衔接方法,由于RMII总线在传输作用不变的情况下占用接口更少,因而一般引荐RMII方法. 以DP83848芯片为例: 从上面能够看出RMII总线对应的输入时钟要设置为50MHZ, 当然这与你原理图的布线有,衔接PHY芯片X1接口对应GPIO接口的外设区域时钟就要设定为该值,考虑到挂在同区域外设的时钟要求,为了便利规划,关于stm32f207vet6(我用的芯片),将体系时钟从120MHz改为100MHz,该区域外设时钟设置为1/2即可。关于stm32f107vc则需求经过PLL3将MCO端口时钟拉高到50Mhz输出到phy。 现在来说大部分人关于stm32驱动的移植都是直接把官方例程拿过来用,但我主张仍是对照参考手册细心研读每一项,自己装备ETH参数,由于stm32芯片集成的MAC装备关于数据的接纳和发送影响很大。
ETH_DeInit();/* Software reset */ETH_SoftwareReset();/* Wait for software reset */while (ETH_GetSoftwareResetStatus() == SET);/* ETHERNET Configuration*//* Call ETH_StructInit if you dont like to configure all ETH_InitStructure parameter */ETH_StructInit(Ð_InitStructure);/* Fill ETH_InitStructure parametrs *//* ETH_MACCR--*///参数是否主动装备,挑选disable需求主动装备默写参数 ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Disable;ETH_InitStructure.ETH_Watchdog = ETH_Watchdog_Disable; //封闭看门狗定时器,答应接纳超长帧ETH_InitStructure.ETH_Jabber = ETH_Jabber_Disable; //封闭jabber定时器,答应发送超长帧ETH_InitStructure.ETH_InterFrameGap = ETH_InterFrameGap_40Bit; //发送帧间极大ETH_InitStructure.ETH_Speed = ETH_Speed_100M; //快速以太网速度ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable; //不启用自循环形式ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex; //全双工形式/*主动填充/CRC剥离处理不碑文,转发一切帧*/ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable; #if CHECKSUM_BY_HARDWARE ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable; //IPV4头文件硬件校验#endif/* ETH_MACFFR-*/ ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable; //MAC过滤只承受经过源意图地址的数据ETH_InitStructure.ETH_SourceAddrFilter = ETH_SourceAddrFilter_Normal_Enable; //MAC过滤源地址过错帧?ETH_InitStructure.ETH_PassControlFrames = ETH_PassControlFrames_BlockAll; //MAC不转发任何操控帧ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable; //接纳播送帧ETH_InitStructure.ETH_DestinationAddrFilter = ETH_DestinationAddrFilter_Normal; //意图地址过滤成果正常ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable; //稠浊形式,启用帧过滤ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect; //过滤器正常作业,不传送操控帧ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect; //单播帧意图地址完美过滤/* DMA ETH_DMAOMR --*/ /* When we use the Checksum offload feature, we need to enable the Store and Forward mode: the store and forward guarantee that a whole frame is stored in the FIFO, so the MAC can insert/verify the checksum, if the checksum is OK the DMA can handle the frame otherwise the frame is dropped *//*丢掉校验过错帧不碑文(由于未进行硬件校验)*/ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Disable;ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Disable; //接纳数据超越阈值转发ETH_InitStructure.ETH_FlushReceivedFrame = ETH_FlushReceivedFrame_Enable; //描述符被占用和接纳FIFO不行用时清空FIFO(处理阻塞)ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Disable; //发送数据完好帧转发ETH_InitStructure.ETH_TransmitThresholdControl = ETH_TransmitThresholdControl_64Bytes; //发送阈值为64BytesETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable; //接纳FIFO丢掉一切过错帧/*接纳FIFO上传长度不行的好帧*/ ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Enable; ETH_InitStructure.ETH_ReceiveThresholdControl = ETH_ReceiveThresholdControl_64Bytes; //接纳阈值为64BytesETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable; //DMA直接发送第二个帧,不需求之前帧/* DMA ETH_DMABMR --*/ 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; //发送和接纳份额(上传数据时重要) 2:1/* Configure Ethernet */ETH_Init(Ð_InitStructure, DP83848_PHY_ADDRESS);/* Enable the Ethernet Rx Interrupt 仅舱位接纳中止*/ETH_DMAITConfig(ETH_DMA_IT_NIS ETH_DMA_IT_R, ENABLE);
当然这是我依据自己需求的装备,详细项目由于实践传输的不同需求个人修正也是必要的。
3.lwip中lwipopt.h文件的修正
拜见http://www.cnblogs.com/zc110747/p/4739588.html设置