关于移植STM32f107网口程序到GD32f107的问题
前段时间由于做项目,需要用到GD32f107的网口,还有一款国产的phy芯片YT8512H。然后调试的时候就遇到了很多问题了,例如gd的例程需要修改后才能ping通,stm32f107的例程不能直接移植等等。具体不多说,反正调了两天,头都整大了,主要问题就是可以用stm32f107的例程来移植,但是呢必须修改驱动,强制为100M,具体咋回事呢我也不清楚,10M我也试过,不过反正是不行。 有篇帖子也讲过这个问题,不过要收费,额,正好今天有空,写出来免费分享一下。
具体需要修改的代码我放下面: void ETH_StructInit(ETH_InitTypeDef* ETH_InitStruct) { /* ETH_InitStruct members default value / /------------------------ MAC -----------------------------------/ ETH_InitStruct->ETH_AutoNegotiation = ETH_AutoNegotiation_Disable; ETH_InitStruct->ETH_Watchdog = ETH_Watchdog_Enable; ETH_InitStruct->ETH_Jabber = ETH_Jabber_Enable; ETH_InitStruct->ETH_InterFrameGap = ETH_InterFrameGap_96Bit; ETH_InitStruct->ETH_CarrierSense = ETH_CarrierSense_Enable; ETH_InitStruct->ETH_Speed = ETH_Speed_100M; ETH_InitStruct->ETH_ReceiveOwn = ETH_ReceiveOwn_Enable; ETH_InitStruct->ETH_LoopbackMode = ETH_LoopbackMode_Disable; ETH_InitStruct->ETH_Mode = ETH_Mode_FullDuplex; ETH_InitStruct->ETH_ChecksumOffload = ETH_ChecksumOffload_Disable; ETH_InitStruct->ETH_RetryTransmission = ETH_RetryTransmission_Enable; ETH_InitStruct->ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable; ETH_InitStruct->ETH_BackOffLimit = ETH_BackOffLimit_10; ETH_InitStruct->ETH_DeferralCheck = ETH_DeferralCheck_Disable; ETH_InitStruct->ETH_ReceiveAll = ETH_ReceiveAll_Disable; ETH_InitStruct->ETH_SourceAddrFilter = ETH_SourceAddrFilter_Disable; ETH_InitStruct->ETH_PassControlFrames = ETH_PassControlFrames_BlockAll; ETH_InitStruct->ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Disable; ETH_InitStruct->ETH_DestinationAddrFilter = ETH_DestinationAddrFilter_Normal; ETH_InitStruct->ETH_PromiscuousMode = ETH_PromiscuousMode_Disable; ETH_InitStruct->ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect; ETH_InitStruct->ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect; ETH_InitStruct->ETH_HashTableHigh = 0x0; ETH_InitStruct->ETH_HashTableLow = 0x0; ETH_InitStruct->ETH_PauseTime = 0x0; ETH_InitStruct->ETH_ZeroQuantaPause = ETH_ZeroQuantaPause_Disable; ETH_InitStruct->ETH_PauseLowThreshold = ETH_PauseLowThreshold_Minus4; ETH_InitStruct->ETH_UnicastPauseFrameDetect = ETH_UnicastPauseFrameDetect_Disable; ETH_InitStruct->ETH_ReceiveFlowControl = ETH_ReceiveFlowControl_Disable; ETH_InitStruct->ETH_TransmitFlowControl = ETH_TransmitFlowControl_Disable; ETH_InitStruct->ETH_VLANTagComparison = ETH_VLANTagComparison_16Bit; ETH_InitStruct->ETH_VLANTagIdentifier = 0x0; /------------------------ DMA -----------------------------------*/ ETH_InitStruct->ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable; ETH_InitStruct->ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable; ETH_InitStruct->ETH_FlushReceivedFrame = ETH_FlushReceivedFrame_Disable; ETH_InitStruct->ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable; ETH_InitStruct->ETH_TransmitThresholdControl = ETH_TransmitThresholdControl_64Bytes; ETH_InitStruct->ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable; ETH_InitStruct->ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable; ETH_InitStruct->ETH_ReceiveThresholdControl = ETH_ReceiveThresholdControl_64Bytes; ETH_InitStruct->ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable; ETH_InitStruct->ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable; ETH_InitStruct->ETH_FixedBurst = ETH_FixedBurst_Enable; ETH_InitStruct->ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat; ETH_InitStruct->ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat; ETH_InitStruct->ETH_DescriptorSkipLength = 0x0; ETH_InitStruct->ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1; }
其他地方基本不用改主要是把自协商关掉,然后强制改成100M就解决。
不过当时还遇到一个网口驱动程序启动时间需要好几秒的问题,这个仿真看一下,如果没记错应该是这个,在stm32_eth.c, stm32_eth.h里面。 我把它时间改短了一些就解决了。 差不多就是这些吧,希望对大家有用。
|