新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32中ETH驅(qū)動配置注意事項(xiàng)

STM32中ETH驅(qū)動配置注意事項(xiàng)

作者: 時間:2016-11-19 來源:網(wǎng)絡(luò) 收藏
1.MII/RMII/SMI接口連接和配置
SMI又稱站點(diǎn)管理接口,用于cpu與外置PHY芯片通訊,配置相關(guān)參數(shù),包含MDC和MDIO兩個管腳(CPU上有對應(yīng)引腳,當(dāng)然用普通GPIO口模擬SMI管理也是可行的,不過需要自己設(shè)置時序,按照固定幀結(jié)構(gòu)寫入和讀取數(shù)據(jù),這個我就不具體說明,有空我會單獨(dú)將程序給出)。MII和RMII是兩種以太網(wǎng)數(shù)據(jù)傳輸接口,因?yàn)镽MII在使用更少接口的情況下具有RMII相同的功效,因此我建議一般采用RMII模式,如下圖連接即可: 
特別注意:RMII模式下REF_CLK要連接CPU的MCO引腳,且MCO輸出時鐘應(yīng)為50MHz. 2.PHY初始化   一般來說,stm32外部驅(qū)動PHY芯片有兩種連接方式,MII和RMII總線,這個與硬件設(shè)計(jì)有關(guān),不過stm32芯片一般都支持這兩種總線連接方式,因?yàn)镽MII總線在傳輸效果不變的情況下占用接口更少,因此一般推薦RMII方式.   以DP83848芯片為例:   從上面可以看出RMII總線對應(yīng)的輸入時鐘要設(shè)置為50MHZ, 當(dāng)然這與你原理圖的布線有,連接PHY芯片X1接口對應(yīng)GPIO接口的外設(shè)區(qū)域時鐘就要設(shè)定為該值,考慮到掛在同區(qū)域外設(shè)的時鐘要求,為了方便設(shè)計(jì),對于stm32f207vet6(我用的芯片),將系統(tǒng)時鐘從120MHz改為100MHz,該區(qū)域外設(shè)時鐘設(shè)置為1/2即可。對于stm32f107vc則需要通過PLL3將MCO端口時鐘拉高到50Mhz輸出到phy。 目前來說大部分人對于stm32驅(qū)動的移植都是直接把官方例程拿過來用,但我建議還是對照參考手冊仔細(xì)研讀每一項(xiàng),自己配置ETH參數(shù),因?yàn)閟tm32芯片集成的MAC配置對于數(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ù)是否自動配置,選擇disable需要自動配置默寫參數(shù) ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Disable;ETH_InitStructure.ETH_Watchdog = ETH_Watchdog_Disable;                            //關(guān)閉看門狗定時器,允許接收超長幀ETH_InitStructure.ETH_Jabber = ETH_Jabber_Disable;                                //關(guān)閉jabber定時器,允許發(fā)送超長幀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;                                 //全雙工模式/*自動填充/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過濾只接受通過源目的地址的數(shù)據(jù)ETH_InitStructure.ETH_SourceAddrFilter = ETH_SourceAddrFilter_Normal_Enable;                 //MAC過濾源地址錯誤幀?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;              //目的地址過濾結(jié)果正常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 *//*丟棄校驗(yàn)錯誤幀不執(zhí)行(因?yàn)槲催M(jìn)行硬件校驗(yàn))*/ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Disable;ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Disable;              //接收數(shù)據(jù)超過閾值轉(zhuǎn)發(fā)ETH_InitStructure.ETH_FlushReceivedFrame = ETH_FlushReceivedFrame_Enable;                 //描述符被占用和接收FIFO不可用時清空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丟棄所有錯誤幀/*接收FIFO上傳長度不夠的好幀*/  ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Enable;    ETH_InitStructure.ETH_ReceiveThresholdControl = ETH_ReceiveThresholdControl_64Bytes;       //接收閾值為64BytesETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable;                  //DMA直接發(fā)送第二個幀,不需要之前幀/*   DMA  ETH_DMABMR --*/      ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;                //傳輸?shù)刂穼RETH_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ù)時重要) 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);

當(dāng)然這是我根據(jù)自己需求的配置,具體項(xiàng)目因?yàn)閷?shí)際傳輸?shù)牟煌枰獋€人修改也是必要的。

本文引用地址:http://m.butianyuan.cn/article/201611/318092.htm

3.lwip中l(wèi)wipopt.h文件的修改

 參見http://www.cnblogs.com/zc110747/p/4739588.html設(shè)置



關(guān)鍵詞: STM32ETH驅(qū)動配

評論


技術(shù)專區(qū)

關(guān)閉