STM32中ETH驅(qū)動(dòng)配置注意事項(xiàng)
SMI又稱(chēng)站點(diǎn)管理接口,用于cpu與外置PHY芯片通訊,配置相關(guān)參數(shù),包含MDC和MDIO兩個(gè)管腳(CPU上有對(duì)應(yīng)引腳,當(dāng)然用普通GPIO口模擬SMI管理也是可行的,不過(guò)需要自己設(shè)置時(shí)序,按照固定幀結(jié)構(gòu)寫(xiě)入和讀取數(shù)據(jù),這個(gè)我就不具體說(shuō)明,有空我會(huì)單獨(dú)將程序給出)。MII和RMII是兩種以太網(wǎng)數(shù)據(jù)傳輸接口,因?yàn)镽MII在使用更少接口的情況下具有RMII相同的功效,因此我建議一般采用RMII模式,如下圖連接即可:特別注意:RMII模式下REF_CLK要連接CPU的MCO引腳,且MCO輸出時(shí)鐘應(yīng)為50MHz. 2.PHY初始化 一般來(lái)說(shuō),stm32外部驅(qū)動(dòng)PHY芯片有兩種連接方式,MII和RMII總線,這個(gè)與硬件設(shè)計(jì)有關(guān),不過(guò)stm32芯片一般都支持這兩種總線連接方式,因?yàn)镽MII總線在傳輸效果不變的情況下占用接口更少,因此一般推薦RMII方式. 以DP83848芯片為例: 從上面可以看出RMII總線對(duì)應(yīng)的輸入時(shí)鐘要設(shè)置為50MHZ, 當(dāng)然這與你原理圖的布線有,連接PHY芯片X1接口對(duì)應(yīng)GPIO接口的外設(shè)區(qū)域時(shí)鐘就要設(shè)定為該值,考慮到掛在同區(qū)域外設(shè)的時(shí)鐘要求,為了方便設(shè)計(jì),對(duì)于stm32f207vet6(我用的芯片),將系統(tǒng)時(shí)鐘從120MHz改為100MHz,該區(qū)域外設(shè)時(shí)鐘設(shè)置為1/2即可。對(duì)于stm32f107vc則需要通過(guò)PLL3將MCO端口時(shí)鐘拉高到50Mhz輸出到phy。 目前來(lái)說(shuō)大部分人對(duì)于stm32驅(qū)動(dòng)的移植都是直接把官方例程拿過(guò)來(lái)用,但我建議還是對(duì)照參考手冊(cè)仔細(xì)研讀每一項(xiàng),自己配置ETH參數(shù),因?yàn)閟tm32芯片集成的MAC配置對(duì)于數(shù)據(jù)的接收和發(fā)送影響很大。
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--*///參數(shù)是否自動(dòng)配置,選擇disable需要自動(dòng)配置默寫(xiě)參數(shù) ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Disable;ETH_InitStructure.ETH_Watchdog = ETH_Watchdog_Disable; //關(guān)閉看門(mén)狗定時(shí)器,允許接收超長(zhǎng)幀ETH_InitStructure.ETH_Jabber = ETH_Jabber_Disable; //關(guān)閉jabber定時(shí)器,允許發(fā)送超長(zhǎng)幀ETH_InitStructure.ETH_InterFrameGap = ETH_InterFrameGap_40Bit; //發(fā)送幀間間隙ETH_InitStructure.ETH_Speed = ETH_Speed_100M; //快速以太網(wǎng)速度ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable; //不啟用自循環(huán)模式ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex; //全雙工模式/*自動(dòng)填充/CRC剝離處理不執(zhí)行,轉(zhuǎn)發(fā)所有幀*/ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable; #if CHECKSUM_BY_HARDWARE ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable; //IPV4頭文件硬件校驗(yàn)#endif/* ETH_MACFFR-*/ ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable; //MAC過(guò)濾只接受通過(guò)源目的地址的數(shù)據(jù)ETH_InitStructure.ETH_SourceAddrFilter = ETH_SourceAddrFilter_Normal_Enable; //MAC過(guò)濾源地址錯(cuò)誤幀?ETH_InitStructure.ETH_PassControlFrames = ETH_PassControlFrames_BlockAll; //MAC不轉(zhuǎn)發(fā)任何控制幀ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable; //接收廣播幀ETH_InitStructure.ETH_DestinationAddrFilter = ETH_DestinationAddrFilter_Normal; //目的地址過(guò)濾結(jié)果正常ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable; //混雜模式,啟用幀過(guò)濾ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect; //過(guò)濾器正常工作,不傳送控制幀ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect; //單播幀目的地址完美過(guò)濾/* 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 *//*丟棄校驗(yàn)錯(cuò)誤幀不執(zhí)行(因?yàn)槲催M(jìn)行硬件校驗(yàn))*/ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Disable;ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Disable; //接收數(shù)據(jù)超過(guò)閾值轉(zhuǎn)發(fā)ETH_InitStructure.ETH_FlushReceivedFrame = ETH_FlushReceivedFrame_Enable; //描述符被占用和接收FIFO不可用時(shí)清空FIFO(解決堵塞)ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Disable; //發(fā)送數(shù)據(jù)完整幀轉(zhuǎn)發(fā)ETH_InitStructure.ETH_TransmitThresholdControl = ETH_TransmitThresholdControl_64Bytes; //發(fā)送閾值為64BytesETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable; //接收FIFO丟棄所有錯(cuò)誤幀/*接收FIFO上傳長(zhǎng)度不夠的好幀*/ ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Enable; ETH_InitStructure.ETH_ReceiveThresholdControl = ETH_ReceiveThresholdControl_64Bytes; //接收閾值為64BytesETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable; //DMA直接發(fā)送第二個(gè)幀,不需要之前幀/* DMA ETH_DMABMR --*/ ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable; //傳輸?shù)刂穼?duì)齊ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable; //固定的突發(fā)ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat; ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat;ETH_InitStructure.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1; //發(fā)送和接收比例(上傳數(shù)據(jù)時(shí)重要) 2:1/* Configure Ethernet */ETH_Init(Ð_InitStructure, DP83848_PHY_ADDRESS);/* Enable the Ethernet Rx Interrupt 僅開(kāi)啟接收中斷*/ETH_DMAITConfig(ETH_DMA_IT_NIS ETH_DMA_IT_R, ENABLE);
當(dāng)然這是我根據(jù)自己需求的配置,具體項(xiàng)目因?yàn)閷?shí)際傳輸?shù)牟煌枰獋€(gè)人修改也是必要的。
本文引用地址:http://butianyuan.cn/article/201611/318092.htm3.lwip中l(wèi)wipopt.h文件的修改
參見(jiàn)http://www.cnblogs.com/zc110747/p/4739588.html設(shè)置
評(píng)論